This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
39 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
BEGIN; | ||
ALTER TYPE email_address_with_confirmation ADD ATTRIBUTE hash text; | ||
ALTER TYPE email_address_with_confirmation ADD ATTRIBUTE ctime timestamp with time zone; | ||
ALTER TYPE email_address_with_confirmation ADD ATTRIBUTE nonce text; | ||
ALTER TYPE email_address_with_confirmation ADD ATTRIBUTE ctime timestamp with time zone; | ||
END; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
interactions: | ||
- request: | ||
body: '{"async": false, "message": {"from_name": "Gratipay", "text": "\nWelcome | ||
to Gratipay! Verify your email address:\n\nhttp:///alice/verify-email.html?hash=e6f85c8c-5ea8-4803-b620-2f6ed3e79657\n", | ||
to Gratipay! Verify your email address:\n\nhttp:///alice/verify-email.html?nonce=e6f85c8c-5ea8-4803-b620-2f6ed3e79657\n", | ||
"from_email": "[email protected]", "to": [{"email": "[email protected]", | ||
"name": "alice"}], "html": "\nWelcome to Gratipay!\n<br><br>\n<a href=\"http:///alice/verify-email.html?hash=e6f85c8c-5ea8-4803-b620-2f6ed3e79657\">Verify | ||
"name": "alice"}], "html": "\nWelcome to Gratipay!\n<br><br>\n<a href=\"http:///alice/verify-email.html?nonce=e6f85c8c-5ea8-4803-b620-2f6ed3e79657\">Verify | ||
your email address</a>.\n", "subject": "Welcome to Gratipay!"}, "send_at": null, | ||
"key": "Phh_Lm3RdPT5blqOPY4dVQ", "ip_pool": null}' | ||
headers: {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,7 +283,7 @@ def test_cpi_clears_personal_information(self): | |
, anonymous_receiving=True | ||
, number='plural' | ||
, avatar_url='img-url' | ||
, email=('[email protected]', True, 'samplehash', utcnow()) | ||
, email=('[email protected]', True, 'samplenonce', utcnow()) | ||
, claimed_time='now' | ||
, session_token='deadbeef' | ||
, session_expires='2000-01-01' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,23 +233,23 @@ def test_can_update_email(self, send_email): | |
@mock.patch.object(Participant, 'send_email') | ||
def test_can_verify_email(self, send_email): | ||
self.alice.update_email('[email protected]') | ||
hash_string = Participant.from_username('alice').email.hash | ||
r = self.alice.verify_email(hash_string) | ||
nonce = Participant.from_username('alice').email.nonce | ||
r = self.alice.verify_email(nonce) | ||
assert r == 0 | ||
actual = Participant.from_username('alice').email.confirmed | ||
assert actual == True | ||
|
||
@mock.patch.object(Participant, 'send_email') | ||
def test_cannot_verify_email_with_wrong_hash(self, send_email): | ||
def test_cannot_verify_email_with_wrong_nonce(self, send_email): | ||
self.alice.update_email('[email protected]') | ||
hash_string = "some wrong hash" | ||
r = self.alice.verify_email(hash_string) | ||
nonce = "some wrong nonce" | ||
r = self.alice.verify_email(nonce) | ||
assert r == 2 | ||
actual = Participant.from_username('alice').email.confirmed | ||
assert actual == False | ||
|
||
@mock.patch.object(Participant, 'send_email') | ||
def test_cannot_verify_email_with_expired_hash(self, send_email): | ||
def test_cannot_verify_email_with_expired_nonce(self, send_email): | ||
self.alice.update_email('[email protected]') | ||
email = self.db.one(""" | ||
UPDATE participants | ||
|
@@ -258,7 +258,7 @@ def test_cannot_verify_email_with_expired_hash(self, send_email): | |
RETURNING email | ||
""") | ||
self.alice.set_attributes(email=email) | ||
r = self.alice.verify_email(self.alice.email.hash) | ||
r = self.alice.verify_email(self.alice.email.nonce) | ||
assert r == 1 | ||
actual = Participant.from_username('alice').email.confirmed | ||
assert actual == False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ def change_email_address(self, address, username, send_email, should_fail=False) | |
) | ||
return response | ||
|
||
def verify_email(self, username, hash_string, should_fail=False): | ||
url = '/%s/verify-email.html?hash=%s' % (username , hash_string) | ||
def verify_email(self, username, nonce, should_fail=False): | ||
url = '/%s/verify-email.html?nonce=%s' % (username , nonce) | ||
if should_fail: | ||
response = self.client.GxT(url) | ||
else: | ||
|
@@ -31,31 +31,31 @@ def verify_email(self, username, hash_string, should_fail=False): | |
|
||
def test_verify_email_without_adding_email(self): | ||
participant = self.make_participant('alice') | ||
response = self.verify_email(participant.username,'sample-hash', should_fail=True) | ||
response = self.verify_email(participant.username, 'sample-nonce', should_fail=True) | ||
assert response.code == 404 | ||
|
||
def test_verify_email_wrong_hash(self): | ||
def test_verify_email_wrong_nonce(self): | ||
participant = self.make_participant('alice', claimed_time="now") | ||
self.change_email_address('[email protected]', participant.username) | ||
self.verify_email(participant.username,'sample-hash') | ||
self.verify_email(participant.username, 'sample-nonce') | ||
expected = False | ||
actual = Participant.from_username(participant.username).email.confirmed | ||
assert expected == actual | ||
|
||
def test_verify_email(self): | ||
participant = self.make_participant('alice', claimed_time="now") | ||
self.change_email_address('[email protected]', participant.username) | ||
hash_string = Participant.from_username(participant.username).email.hash | ||
self.verify_email(participant.username,hash_string) | ||
nonce = Participant.from_username(participant.username).email.nonce | ||
self.verify_email(participant.username, nonce) | ||
expected = True | ||
actual = Participant.from_username(participant.username).email.confirmed | ||
assert expected == actual | ||
|
||
def test_email_is_not_confirmed_after_update(self): | ||
participant = self.make_participant('alice', claimed_time="now") | ||
self.change_email_address('[email protected]', participant.username) | ||
hash_string = Participant.from_username(participant.username).email.hash | ||
self.verify_email(participant.username,hash_string) | ||
nonce = Participant.from_username(participant.username).email.nonce | ||
self.verify_email(participant.username, nonce) | ||
self.change_email_address('[email protected]', participant.username) | ||
expected = False | ||
actual = Participant.from_username(participant.username).email.confirmed | ||
|
@@ -64,19 +64,19 @@ def test_email_is_not_confirmed_after_update(self): | |
def test_verify_email_after_update(self): | ||
participant = self.make_participant('alice', claimed_time="now") | ||
self.change_email_address('[email protected]', participant.username) | ||
hash_string = Participant.from_username(participant.username).email.hash | ||
self.verify_email(participant.username,hash_string) | ||
nonce = Participant.from_username(participant.username).email.nonce | ||
self.verify_email(participant.username, nonce) | ||
self.change_email_address('[email protected]', participant.username) | ||
hash_string = Participant.from_username(participant.username).email.hash | ||
self.verify_email(participant.username,hash_string) | ||
nonce = Participant.from_username(participant.username).email.nonce | ||
self.verify_email(participant.username, nonce) | ||
expected = True | ||
actual = Participant.from_username(participant.username).email.confirmed | ||
assert expected == actual | ||
|
||
def test_hash_is_regenerated_on_update(self): | ||
def test_nonce_is_regenerated_on_update(self): | ||
participant = self.make_participant('alice', claimed_time="now") | ||
self.change_email_address('[email protected]', participant.username) | ||
hash_string_1 = Participant.from_username(participant.username).email.hash | ||
nonce1 = Participant.from_username(participant.username).email.nonce | ||
self.change_email_address('[email protected]', participant.username) | ||
hash_string_2 = Participant.from_username(participant.username).email.hash | ||
assert hash_string_1 != hash_string_2 | ||
nonce2 = Participant.from_username(participant.username).email.nonce | ||
assert nonce1 != nonce2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters