-
-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue 145 alternative named static backup device use fix
- Loading branch information
Showing
3 changed files
with
64 additions
and
10 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 |
---|---|---|
|
@@ -358,6 +358,40 @@ def test_with_backup_token(self, mock_signal): | |
# Check that the signal was fired. | ||
mock_signal.assert_called_with(sender=mock.ANY, request=mock.ANY, user=user, device=device) | ||
|
||
@mock.patch('two_factor.views.core.signals.user_verified.send') | ||
def test_with_alter_backup_token(self, mock_signal): | ||
user = self.create_user() | ||
user.totpdevice_set.create(name='default', key=random_hex()) | ||
device = user.staticdevice_set.create(name='alter') | ||
device.token_set.create(token='abcdef123') | ||
|
||
# Backup phones should be listed on the login form | ||
response = self._post({'auth-username': '[email protected]', | ||
'auth-password': 'secret', | ||
'login_view-current_step': 'auth'}) | ||
self.assertContains(response, 'Backup Token') | ||
|
||
# Should be able to go to backup tokens step in wizard | ||
response = self._post({'wizard_goto_step': 'backup'}) | ||
self.assertContains(response, 'backup tokens') | ||
|
||
# Wrong codes should not be accepted | ||
response = self._post({'backup-otp_token': 'WRONG', | ||
'login_view-current_step': 'backup'}) | ||
self.assertEqual(response.context_data['wizard']['form'].errors, | ||
{'__all__': ['Invalid token. Please make sure you ' | ||
'have entered it correctly.']}) | ||
# static devices are throttled | ||
device.throttle_reset() | ||
|
||
# Valid token should be accepted. | ||
response = self._post({'backup-otp_token': 'abcdef123', | ||
'login_view-current_step': 'backup'}) | ||
self.assertRedirects(response, resolve_url(settings.LOGIN_REDIRECT_URL)) | ||
|
||
# Check that the signal was fired. | ||
mock_signal.assert_called_with(sender=mock.ANY, request=mock.ANY, user=user, device=device) | ||
|
||
@mock.patch('two_factor.views.utils.logger') | ||
def test_reset_wizard_state(self, mock_logger): | ||
self.create_user() | ||
|
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 |
---|---|---|
|
@@ -106,6 +106,29 @@ def test_show_correct_label(self): | |
self.assertNotContains(response, 'YubiKey:') | ||
self.assertContains(response, 'Token:') | ||
|
||
def test_show_correct_label_alter_backup(self): | ||
""" | ||
The token form replaces the input field when the user's device is a | ||
YubiKey. However when the user decides to enter a backup token, the | ||
normal backup token form should be shown. Refs #50. | ||
""" | ||
user = self.create_user() | ||
service = ValidationService.objects.create(name='default', param_sl='', param_timeout='') | ||
user.remoteyubikeydevice_set.create(service=service, name='default') | ||
backup = user.staticdevice_set.create(name='alter') | ||
backup.token_set.create(token='RANDOM') | ||
|
||
response = self.client.post(reverse('two_factor:login'), | ||
data={'auth-username': '[email protected]', | ||
'auth-password': 'secret', | ||
'login_view-current_step': 'auth'}) | ||
self.assertContains(response, 'YubiKey:') | ||
|
||
response = self.client.post(reverse('two_factor:login'), | ||
data={'wizard_goto_step': 'backup'}) | ||
self.assertNotContains(response, 'YubiKey:') | ||
self.assertContains(response, 'Token:') | ||
|
||
def test_missing_management_data(self): | ||
# missing management data | ||
response = self.client.post(reverse('two_factor:login'), | ||
|
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