test_signup: Expand tests for invalid confirmation links.

We'll need the expanded test coverage when we move
check_prereg_key_and_redirect to zerver/views/registration.py to avoid
test failures, and these are also tests we should really have anyway.
This commit is contained in:
Tim Abbott 2017-11-29 22:17:06 -08:00
parent 3675d97870
commit 6e8f4ffc77
1 changed files with 27 additions and 2 deletions

View File

@ -860,14 +860,39 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
# make sure users can't take a valid confirmation key from another # make sure users can't take a valid confirmation key from another
# pathway and use it with the invitation url route # pathway and use it with the invitation url route
# Mainly a test of get_object_from_key, rather than of the invitation pathway
def test_confirmation_key_of_wrong_type(self) -> None: def test_confirmation_key_of_wrong_type(self) -> None:
user = self.example_user('hamlet') user = self.example_user('hamlet')
registration_key = create_confirmation_link(user, 'host', Confirmation.USER_REGISTRATION).split('/')[-1] url = create_confirmation_link(user, 'host', Confirmation.USER_REGISTRATION)
registration_key = url.split('/')[-1]
# Mainly a test of get_object_from_key, rather than of the invitation pathway
with self.assertRaises(ConfirmationKeyException) as cm: with self.assertRaises(ConfirmationKeyException) as cm:
get_object_from_key(registration_key, Confirmation.INVITATION) get_object_from_key(registration_key, Confirmation.INVITATION)
self.assertEqual(cm.exception.error_type, ConfirmationKeyException.DOES_NOT_EXIST) self.assertEqual(cm.exception.error_type, ConfirmationKeyException.DOES_NOT_EXIST)
# Verify that using the wrong type doesn't work in the main confirm code path
email_change_url = create_confirmation_link(user, 'host', Confirmation.EMAIL_CHANGE)
email_change_key = email_change_url.split('/')[-1]
url = '/accounts/do_confirm/' + email_change_key
result = self.client_get(url)
self.assert_in_success_response(["Whoops. We couldn't find your "
"confirmation link in the system."], result)
def test_confirmation_expired(self) -> None:
user = self.example_user('hamlet')
url = create_confirmation_link(user, 'host', Confirmation.USER_REGISTRATION)
registration_key = url.split('/')[-1]
conf = Confirmation.objects.filter(confirmation_key=registration_key).first()
conf.date_sent -= datetime.timedelta(weeks=3)
conf.save()
target_url = '/' + url.split('/', 3)[3]
print(target_url)
result = self.client_get(target_url)
self.assert_in_success_response(["Whoops. The confirmation link has expired "
"or been deactivated."], result)
class InvitationsTestCase(InviteUserBase): class InvitationsTestCase(InviteUserBase):
def test_successful_get_open_invitations(self) -> None: def test_successful_get_open_invitations(self) -> None:
""" """