summaryrefslogtreecommitdiff
path: root/service/test/unit/test_authentication.py
diff options
context:
space:
mode:
authorDenis Costa <deniscostadsc@gmail.com>2016-10-25 12:16:23 -0200
committerDenis Costa <deniscostadsc@gmail.com>2016-10-26 14:34:31 -0200
commite3006fff2f71787e9879e2f88e57dc9b935b7782 (patch)
tree1ca0033036960988167fb5111cb92303ba3dc49f /service/test/unit/test_authentication.py
parentd9c4fb3707d85aa400f7042df2fbf7088f18739e (diff)
Adds real authentication
We also did some refactoring in order to have things working. #795
Diffstat (limited to 'service/test/unit/test_authentication.py')
-rw-r--r--service/test/unit/test_authentication.py42
1 files changed, 34 insertions, 8 deletions
diff --git a/service/test/unit/test_authentication.py b/service/test/unit/test_authentication.py
index 34138b5e..f9f98af9 100644
--- a/service/test/unit/test_authentication.py
+++ b/service/test/unit/test_authentication.py
@@ -1,32 +1,58 @@
+from twisted.cred.error import UnauthorizedLogin
+from twisted.internet.defer import inlineCallbacks
from twisted.trial import unittest
+from leap.bitmask.bonafide._srp import SRPAuthError
+
+from mock import patch, Mock
+
from pixelated.authentication import Authenticator
+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 AuthenticatorTest(unittest.TestCase):
- def test_authenticates_with_username_and_password(self):
- self.fail()
+ def setUp(self):
+ with patch.object(LeapProvider, 'fetch_provider_json', return_value=PROVIDER_JSON):
+ self._leap_provider = LeapProvider('domain.org')
+
+ @inlineCallbacks
+ def test_bonafide_srp_exceptions_should_raise_unauthorized_login(self):
+ auth = Authenticator(self._leap_provider)
+ mock_bonafide_session = Mock()
+ mock_bonafide_session.authenticate = Mock(side_effect=SRPAuthError())
+ with patch('pixelated.config.leap.Session', return_value=mock_bonafide_session):
+ with self.assertRaises(UnauthorizedLogin):
+ yield auth.authenticate('username', 'password')
def test_validate_username_accepts_username(self):
- auth = Authenticator('domain.org')
+ auth = Authenticator(self._leap_provider)
self.assertTrue(auth.validate_username('username'))
def test_validate_username_accepts_email_address(self):
- auth = Authenticator('domain.org')
+ auth = Authenticator(self._leap_provider)
self.assertTrue(auth.validate_username('username@domain.org'))
def test_validate_username_denies_other_domains(self):
- auth = Authenticator('domain.org')
+ auth = Authenticator(self._leap_provider)
self.assertFalse(auth.validate_username('username@wrongdomain.org'))
def test_username_with_domain(self):
- auth = Authenticator('domain.org')
+ auth = Authenticator(self._leap_provider)
self.assertEqual('user@domain.org', auth.username_with_domain('user'))
def test_extract_username_extracts_from_plain_username(self):
- auth = Authenticator('domain.org')
+ auth = Authenticator(self._leap_provider)
self.assertEqual(auth.extract_username('user'), 'user')
def test_extract_username_extracts_from_email_address(self):
- auth = Authenticator('domain.org')
+ auth = Authenticator(self._leap_provider)
self.assertEqual(auth.extract_username('user@domain.org'), 'user')