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
1 parent
c0c9ad5
commit a809a77
Showing
4 changed files
with
114 additions
and
45 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
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ def setUp(self): | |
def add(self, participant, address, _flush=False): | ||
participant.start_email_verification(address) | ||
nonce = participant.get_email(address).nonce | ||
r = participant.verify_email(address, nonce) | ||
r = participant.finish_email_verification(address, nonce) | ||
assert r == _email.VERIFICATION_SUCCEEDED | ||
if _flush: | ||
self.app.email_queue.flush() | ||
|
@@ -52,7 +52,7 @@ def hit_email_spt(self, action, address, user='alice', package_ids=[], should_fa | |
response.render_body({'_': lambda a: a}) | ||
return response | ||
|
||
def verify_email(self, email, nonce, username='alice', should_fail=False): | ||
def finish_email_verification(self, email, nonce, username='alice', should_fail=False): | ||
# Email address is encoded in url. | ||
url = '/~%s/emails/verify.html?email2=%s&nonce=%s' | ||
url %= (username, encode_for_querystring(email), nonce) | ||
|
@@ -62,7 +62,7 @@ def verify_email(self, email, nonce, username='alice', should_fail=False): | |
def verify_and_change_email(self, old_email, new_email, username='alice', _flush=True): | ||
self.hit_email_spt('add-email', old_email) | ||
nonce = P(username).get_email(old_email).nonce | ||
self.verify_email(old_email, nonce) | ||
self.finish_email_verification(old_email, nonce) | ||
self.hit_email_spt('add-email', new_email) | ||
if _flush: | ||
self.app.email_queue.flush() | ||
|
@@ -129,15 +129,15 @@ def test_post_too_quickly_is_400(self): | |
assert 'too quickly' in response.body | ||
|
||
def test_verify_email_without_adding_email(self): | ||
response = self.verify_email('', 'sample-nonce') | ||
response = self.finish_email_verification('', 'sample-nonce') | ||
assert 'Bad Info' in response.body | ||
|
||
def test_verify_email_wrong_nonce(self): | ||
self.hit_email_spt('add-email', '[email protected]') | ||
nonce = 'fake-nonce' | ||
r = self.alice.verify_email('[email protected]', nonce) | ||
r = self.alice.finish_email_verification('[email protected]', nonce) | ||
assert r == _email.VERIFICATION_FAILED | ||
self.verify_email('[email protected]', nonce) | ||
self.finish_email_verification('[email protected]', nonce) | ||
expected = None | ||
actual = P('alice').email_address | ||
assert expected == actual | ||
|
@@ -146,8 +146,8 @@ def test_verify_email_a_second_time_returns_redundant(self): | |
address = '[email protected]' | ||
self.hit_email_spt('add-email', address) | ||
nonce = self.alice.get_email(address).nonce | ||
r = self.alice.verify_email(address, nonce) | ||
r = self.alice.verify_email(address, nonce) | ||
r = self.alice.finish_email_verification(address, nonce) | ||
r = self.alice.finish_email_verification(address, nonce) | ||
assert r == _email.VERIFICATION_REDUNDANT | ||
|
||
def test_verify_email_expired_nonce(self): | ||
|
@@ -159,15 +159,15 @@ def test_verify_email_expired_nonce(self): | |
WHERE participant_id = %s; | ||
""", (self.alice.id,)) | ||
nonce = self.alice.get_email(address).nonce | ||
r = self.alice.verify_email(address, nonce) | ||
r = self.alice.finish_email_verification(address, nonce) | ||
assert r == _email.VERIFICATION_EXPIRED | ||
actual = P('alice').email_address | ||
assert actual == None | ||
|
||
def test_verify_email(self): | ||
def test_finish_email_verification(self): | ||
self.hit_email_spt('add-email', '[email protected]') | ||
nonce = self.alice.get_email('[email protected]').nonce | ||
self.verify_email('[email protected]', nonce) | ||
self.finish_email_verification('[email protected]', nonce) | ||
expected = '[email protected]' | ||
actual = P('alice').email_address | ||
assert expected == actual | ||
|
@@ -197,7 +197,7 @@ def test_get_emails(self): | |
def test_verify_email_after_update(self): | ||
self.verify_and_change_email('[email protected]', '[email protected]') | ||
nonce = self.alice.get_email('[email protected]').nonce | ||
self.verify_email('[email protected]', nonce) | ||
self.finish_email_verification('[email protected]', nonce) | ||
expected = '[email protected]' | ||
actual = P('alice').email_address | ||
assert expected == actual | ||
|
@@ -296,7 +296,7 @@ def test_cannot_update_email_to_already_verified(self): | |
with self.assertRaises(EmailTaken): | ||
bob.start_email_verification('[email protected]') | ||
nonce = bob.get_email('[email protected]').nonce | ||
bob.verify_email('[email protected]', nonce) | ||
bob.finish_email_verification('[email protected]', nonce) | ||
|
||
email_alice = P('alice').email_address | ||
assert email_alice == '[email protected]' | ||
|
@@ -592,7 +592,7 @@ def check(self, *package_names, **kw): | |
def preverify(self, address='[email protected]'): | ||
self.alice.start_email_verification(address) | ||
nonce = self.alice.get_email(address).nonce | ||
self.alice.verify_email(address, nonce) | ||
self.alice.finish_email_verification(address, nonce) | ||
|
||
|
||
class VerificationMessage(VerificationBase): | ||
|
@@ -677,3 +677,38 @@ def test_sends_notice_for_unverified_address_and_multiple_packages(self): | |
html, text = self.check('foo', 'bar') | ||
assert ' connecting <b>[email protected]</b> and 2 npm packages ' in html | ||
assert ' connecting [email protected] and 2 npm packages ' in text | ||
|
||
|
||
class FinishEmailVerification(VerificationBase): | ||
|
||
def start(self, address, *package_names): | ||
packages = [self.make_package(name=name, emails=[address]) for name in package_names] | ||
self.alice.start_email_verification(address, *packages) | ||
return self.alice.get_email(address).nonce | ||
|
||
def test_handles_new_address(self): | ||
address = '[email protected]' | ||
assert self.alice.email_address is None | ||
self.alice.finish_email_verification(address, self.start(address)) | ||
assert self.alice.email_address == P('alice').email_address == address | ||
|
||
def test_handles_verified_address_and_no_packages(self): | ||
raise NotImplementedError # should error | ||
|
||
def test_handles_verified_address_and_one_package(self): | ||
self.preverify() | ||
address = '[email protected]' | ||
assert self.alice.email_address == address | ||
self.alice.finish_email_verification(address, self.start(address, 'foo')) | ||
assert self.alice.email_address == P('alice').email_address == address | ||
raise NotImplementedError # assert we connect the package | ||
|
||
def test_handles_verified_address_and_multiple_packages(self): | ||
self.preverify() | ||
raise NotImplementedError | ||
|
||
def test_handles_unverified_address_and_one_package(self): | ||
raise NotImplementedError | ||
|
||
def test_handles_unverified_address_and_multiple_packages(self): | ||
raise NotImplementedError |
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