class AuthModuleTests(TestCase):
    def setUp(self):
        self.auth_module = DjangoSSOAuthBackend()
        self.user = User.objects.create(username="******")
        self.assignment1 = Assignment.objects.create(
            username="",
            username_mode=settings.ASSIGNMENT_ANY,
            domain="example.com",
            user=self.user,
            weight=100,
        )
        self.request_factory = RequestFactory()

    def tearDown(self):
        self.user.delete()
        Assignment.objects.all().delete()

    def test_empty_authenticate(self):
        request = self.request_factory.get("/")
        user = self.auth_module.authenticate(request)
        self.assertEqual(user, None)

    def test_simple_assignment(self):
        email = "*****@*****.**"
        request = self.request_factory.get("/")
        user = self.auth_module.authenticate(request, sso_email=email)
        self.assertEqual(user, self.user)

    def test_get_user(self):
        user = self.auth_module.get_user(self.user.id)
        self.assertEqual(user, self.user)

        user = self.auth_module.get_user(self.user.id + 42)
        self.assertEqual(user, None)
class AuthModuleTests(TestCase):
    def setUp(self):
        self.auth_module = DjangoSSOAuthBackend()
        self.user = User.objects.create(username='******')
        self.assignment1 = Assignment.objects.create(
            username='',
            username_mode=settings.ASSIGNMENT_ANY,
            domain='example.com',
            user=self.user,
            weight=100)

    def tearDown(self):
        self.user.delete()
        Assignment.objects.all().delete()

    def test_empty_authenticate(self):
        user = self.auth_module.authenticate()
        self.assertEqual(user, None)

    def test_simple_assignment(self):
        email = "*****@*****.**"
        user = self.auth_module.authenticate(sso_email=email)
        self.assertEqual(user, self.user)

    def test_get_user(self):
        user = self.auth_module.get_user(self.user.id)
        self.assertEqual(user, self.user)

        user = self.auth_module.get_user(self.user.id + 42)
        self.assertEqual(user, None)
class AuthModuleTests(TestCase):
    def setUp(self):
        self.auth_module = DjangoSSOAuthBackend()
        self.user = User.objects.create(username='******')
        self.assignment1 = Assignment.objects.create(username='',
                                                     username_mode=settings.ASSIGNMENT_ANY,
                                                     domain='example.com',
                                                     user=self.user,
                                                     weight=100)

    def tearDown(self):
        self.user.delete()
        Assignment.objects.all().delete()

    def test_empty_authenticate(self):
        user = self.auth_module.authenticate()
        self.assertEqual(user, None)

    def test_simple_assignment(self):
        email = "*****@*****.**"
        user = self.auth_module.authenticate(sso_email=email)
        self.assertEqual(user, self.user)

    def test_get_user(self):
        user = self.auth_module.get_user(self.user.id)
        self.assertEqual(user, self.user)

        user = self.auth_module.get_user(self.user.id + 42)
        self.assertEqual(user, None)
Exemple #4
0
class AuthModuleTests(unittest.TestCase):
    def setUp(self):
        self.auth_module = DjangoSSOAuthBackend()
        self.user = User.objects.create(username='******')
        self.assignment1 = Assignment.objects.create(
            username='',
            username_mode=settings.ASSIGNMENT_ANY,
            domain='example.com',
            user=self.user,
            weight=100)

    def tearDown(self):
        self.user.delete()
        Assignment.objects.all().delete()

    def test_empty_authenticate(self):
        user = self.auth_module.authenticate()
        self.assertEqual(user, None)

    @skipIfOpenID
    def test_simple_assignment(self):
        email = "*****@*****.**"
        user = self.auth_module.authenticate(sso_email=email)
        self.assertEqual(user, self.user)

    def create_sreg_response(self, fullname='', email='', identifier=''):
        message = Message(OPENID2_NS)
        message.setArg(SREG_NS, "fullname", fullname)
        message.setArg(SREG_NS, "email", email)
        endpoint = OpenIDServiceEndpoint()
        endpoint.display_identifier = identifier
        return SuccessResponse(endpoint,
                               message,
                               signed_fields=message.toPostArgs().keys())

    @skipIfOAuth
    def test_domain_matches(self):
        response = self.create_sreg_response(fullname="User Name",
                                             email="*****@*****.**",
                                             identifier='7324')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertEqual(user, self.user)

    def test_get_user(self):
        user = self.auth_module.get_user(self.user.id)
        self.assertEqual(user, self.user)

        user = self.auth_module.get_user(self.user.id + 42)
        self.assertEqual(user, None)
Exemple #5
0
class AuthModuleTests(unittest.TestCase):
    def setUp(self):
        self.auth_module = DjangoSSOAuthBackend()
        self.user = User.objects.create(username='******')
        self.assignment1 = Assignment.objects.create(username='',
                                                     username_mode=settings.ASSIGNMENT_ANY,
                                                     domain='example.com',
                                                     user=self.user,
                                                     weight=100)

    def tearDown(self):
        self.user.delete()
        Assignment.objects.all().delete()

    def test_empty_authenticate(self):
        user = self.auth_module.authenticate()
        self.assertEqual(user, None)

    @skipIfOpenID
    def test_simple_assignment(self):
        email = "*****@*****.**"
        user = self.auth_module.authenticate(sso_email=email)
        self.assertEqual(user, self.user)

    def create_sreg_response(self, fullname='', email='', identifier=''):
        message = Message(OPENID2_NS)
        message.setArg(SREG_NS, "fullname", fullname)
        message.setArg(SREG_NS, "email", email)
        endpoint = OpenIDServiceEndpoint()
        endpoint.display_identifier = identifier
        return SuccessResponse(endpoint, message, signed_fields=message.toPostArgs().keys())

    @skipIfOAuth
    def test_domain_matches(self):
        response = self.create_sreg_response(fullname="User Name", email="*****@*****.**", identifier='7324')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertEqual(user, self.user)

    def test_get_user(self):
        user = self.auth_module.get_user(self.user.id)
        self.assertEqual(user, self.user)

        user = self.auth_module.get_user(self.user.id + 42)
        self.assertEqual(user, None)
Exemple #6
0
class AuthModuleTests(unittest.TestCase):
    def setUp(self):
        self.auth_module = DjangoSSOAuthBackend()
        self.user1 = User.objects.create(username='******')
        self.user2 = User.objects.create(username='******')
        self.user3 = User.objects.create(username='******')
        self.assginment1 = Assignment.objects.create(username='',
                                                     username_mode=settings.ASSIGNMENT_ANY,
                                                     domain='example.com',
                                                     user=self.user1,
                                                     weight=100)
        self.assginment2 = Assignment.objects.create(username='******',
                                                     username_mode=settings.ASSIGNMENT_MATCH,
                                                     domain='example.com',
                                                     user=self.user2,
                                                     weight=200)
        self.assginment3 = Assignment.objects.create(username='******',
                                                     username_mode=settings.ASSIGNMENT_EXCEPT,
                                                     domain='example.com',
                                                     user=self.user3,
                                                     weight=300)

    def tearDown(self):
        self.user1.delete()
        self.user2.delete()
        self.user3.delete()
        Assignment.objects.all().delete()
        OpenIDUser.objects.all().delete()

    def test_domain_matches(self):
        response = self.create_sreg_response(fullname="User Name", email="*****@*****.**", identifier='7324')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertEquals(user, self.user1)

    def test_invalid_domain(self):
        response = self.create_sreg_response(email='*****@*****.**')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertIsNone(user)

    def test_domain_matches_and_username_ends_with_bar(self):
        response = self.create_sreg_response(fullname="User Name", email="*****@*****.**", identifier='5673')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertEquals(user, self.user2)

    def test_login_twice_and_reuse_stored_openid(self):
        response = self.create_sreg_response(fullname="User Name", email="*****@*****.**", identifier='1111')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertEquals(user, self.user2)
        response = self.create_sreg_response(identifier='1111')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertEquals(user, self.user2)

    def test_domain_matches_and_username_doesnt_begin_with_foo(self):
        response = self.create_sreg_response(fullname="User Name", email="*****@*****.**", identifier='3476')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertEquals(user, self.user3)

    def test_change_weight(self):
        self.assginment2.weight = 50
        self.assginment2.save()
        response = self.create_sreg_response(fullname="User Name", email="*****@*****.**", identifier='5673')
        user = self.auth_module.authenticate(openid_response=response)
        self.assertEquals(user, self.user1)

    def create_sreg_response(self, fullname='', email='', identifier=''):
        message = Message(OPENID2_NS)
        message.setArg(SREG_NS, "fullname", fullname)
        message.setArg(SREG_NS, "email", email)
        endpoint = OpenIDServiceEndpoint()
        endpoint.display_identifier = identifier
        return SuccessResponse(endpoint, message, signed_fields=message.toPostArgs().keys())