This repository has been archived by the owner on Jan 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#935] Implements account recovery authenticator which extends Authen…
…ticator with @tayanefernandes
- Loading branch information
Sriram Viswanathan
committed
Apr 10, 2017
1 parent
5d4bb90
commit 4d7a38a
Showing
8 changed files
with
140 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Copyright (c) 2014 ThoughtWorks, Inc. | ||
# | ||
# Pixelated is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Pixelated is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from twisted.cred.error import UnauthorizedLogin | ||
|
||
from authentication import Authenticator | ||
|
||
|
||
class AccountRecoveryAuthenticator(Authenticator): | ||
def __init__(self, leap_provider): | ||
super(AccountRecoveryAuthenticator, self).__init__(leap_provider) | ||
|
||
def _auth_error(self): | ||
raise UnauthorizedLogin("User typed wrong recovery-code/username combination.") |
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
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# | ||
# Copyright (c) 2015 ThoughtWorks, Inc. | ||
# | ||
# Pixelated is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Pixelated is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from twisted.cred.error import UnauthorizedLogin | ||
from twisted.trial import unittest | ||
from twisted.internet.defer import inlineCallbacks | ||
|
||
from leap.bitmask.bonafide._srp import SRPAuthError | ||
|
||
from mock import patch, MagicMock | ||
|
||
from pixelated.account_recovery_authenticator import AccountRecoveryAuthenticator | ||
from pixelated.bitmask_libraries.provider import LeapProvider | ||
|
||
PROVIDER_JSON = { | ||
"api_uri": "https://api.domain.org:4430", | ||
"api_version": "1", | ||
"ca_cert_fingerprint": "SHA256: some_stub_sha", | ||
"ca_cert_uri": "https://domain.org/ca.crt", | ||
"domain": "domain.org", | ||
} | ||
|
||
|
||
class AccountRecoveryAuthenticatorTest(unittest.TestCase): | ||
def setUp(self): | ||
self._domain = 'domain.org' | ||
with patch.object(LeapProvider, 'fetch_provider_json', return_value=PROVIDER_JSON): | ||
self._leap_provider = LeapProvider(self._domain) | ||
|
||
@inlineCallbacks | ||
def test_bonafide_srp_exceptions_should_raise_unauthorized_login(self): | ||
account_recovery_authenticator = AccountRecoveryAuthenticator(self._leap_provider) | ||
mock_bonafide_session = MagicMock() | ||
mock_bonafide_session.authenticate = MagicMock(side_effect=SRPAuthError()) | ||
with patch('pixelated.authentication.Session', return_value=mock_bonafide_session): | ||
with self.assertRaises(UnauthorizedLogin): | ||
try: | ||
yield account_recovery_authenticator.authenticate('username', 'recovery_code') | ||
except UnauthorizedLogin as e: | ||
self.assertEqual("User typed wrong recovery-code/username combination.", e.message) | ||
raise |