summaryrefslogtreecommitdiff
path: root/service/test/unit/test_authentication.py
blob: 2fb97d691746ad56a3db3ce22540eb6896783c35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from twisted.trial import unittest

from leap.bitmask.bonafide._srp import SRPAuthError
from pixelated.authentication import Authentication


class AuthenticationTest(unittest.TestCase):

    def test_authenticates_with_username_and_password(self):
        self.fail()

    def test_validate_username_accepts_username(self):
        auth = Authentication('domain.org')
        self.assertTrue(auth.validate_username('username'))

    def test_validate_username_accepts_email_address(self):
        auth = Authentication('domain.org')
        self.assertTrue(auth.validate_username('username@domain.org'))

    def test_validate_username_denies_other_domains(self):
        auth = Authentication('domain.org')
        self.assertFalse(auth.validate_username('username@wrongdomain.org'))

    def test_username_with_domain(self):
        auth = Authentication('domain.org')
        self.assertEqual('user@domain.org', auth.username_with_domain('user'))

    def test_extract_username_extracts_from_plain_username(self):
        auth = Authentication('domain.org')
        self.assertEqual(auth.extract_username('user'), 'user')

    def test_extract_username_extracts_from_email_address(self):
        auth = Authentication('domain.org')
        self.assertEqual(auth.extract_username('user@domain.org'), 'user')