Пример #1
0
    def setUp(self):
        self.oclient = Client(name="Test Client",
                              access_host="http://localhost/")
        self.oclient.save()

        self.scope = Scope(short_name="test",
                           full_name="Test Scope",
                           description="Scope for testing")
        self.scope.save()

        self.user = User(username="******",
                         password="******",
                         email="*****@*****.**")
        self.user.save()

        self.at = AuthorizationToken(client=self.oclient, user=self.user)
        self.at.save()
        self.at.scope = [self.scope]
        self.at.save()

        self.rt = self.at.generate_refresh_token()

        self.token = self.rt.generate_access_token()

        self.handler = BearerHandler()

        self.factory = RequestFactory()
Пример #2
0
    def setUp(self):
        super(TokenTestCase, self).setUp()

        self.client_secret = self.oauth_client.secret

        self.authorization_token = AuthorizationToken(user=self.user,
                                                      client=self.oauth_client)
        self.authorization_token.save()

        self.authorization_token.scope = [self.scope]
        self.authorization_token.save()
Пример #3
0
class TokenTestCase(OAuthTestCase):
    
    def setUp(self):
        super(TokenTestCase, self).setUp()
        
        self.client_secret = self.oauth_client.secret
        
        self.authorization_token = AuthorizationToken(user=self.user, client=self.oauth_client)
        self.authorization_token.save()
        
        self.authorization_token.scope = [self.scope]
        self.authorization_token.save()
Пример #4
0
    def setUp(self):
        self.oclient = Client(name="Test Client",
                              access_host="http://localhost/")
        self.oclient.save()

        self.scope = Scope(short_name="test",
                           full_name="Test Scope",
                           description="Scope for testing")
        self.scope.save()

        self.user = User(username="******",
                         password="******",
                         email="*****@*****.**")
        self.user.save()

        self.token = AuthorizationToken(client=self.oclient, user=self.user)
        self.token.save()

        self.token.scope = [self.scope]
        self.token.save()
Пример #5
0
    def setUp(self):
        from django.http import HttpRequest
        from doac.middleware import AuthenticationMiddleware

        super(DecoratorTestCase, self).setUp()

        self.client_secret = self.oauth_client.secret

        self.authorization_token = AuthorizationToken(user=self.user,
                                                      client=self.oauth_client)
        self.authorization_token.save()

        self.authorization_token.scope = [self.scope]
        self.authorization_token.save()

        self.authorization_token.generate_refresh_token()
        self.authorization_token.refresh_token.generate_access_token()

        self.access_token = self.authorization_token.refresh_token.access_tokens.all(
        )[0]

        self.request = HttpRequest()
        self.mw = AuthenticationMiddleware()
Пример #6
0
    def setUp(self):
        self.oclient = Client(name="Test Client", access_host="http://localhost/")
        self.oclient.save()

        self.scope = Scope(short_name="test", full_name="Test Scope", description="Scope for testing")
        self.scope.save()

        self.user = User(username="******", password="******", email="*****@*****.**")
        self.user.save()

        self.token = AuthorizationToken(client=self.oclient, user=self.user)
        self.token.save()

        self.token.scope = [self.scope]
        self.token.save()
Пример #7
0
 def setUp(self):
     from django.http import HttpRequest
     from doac.middleware import AuthenticationMiddleware
     
     super(DecoratorTestCase, self).setUp()
     
     self.client_secret = self.oauth_client.secret
     
     self.authorization_token = AuthorizationToken(user=self.user, client=self.oauth_client)
     self.authorization_token.save()
     
     self.authorization_token.scope = [self.scope]
     self.authorization_token.save()
     
     self.authorization_token.generate_refresh_token()
     self.authorization_token.refresh_token.generate_access_token()
     
     self.access_token = self.authorization_token.refresh_token.access_tokens.all()[0]
     
     self.request = HttpRequest()
     self.mw = AuthenticationMiddleware()
Пример #8
0
Файл: bearer.py Проект: EE/doac
 def setUp(self):
     self.oclient = Client(name="Test Client", access_host="http://localhost/")
     self.oclient.save()
     
     self.scope = Scope(short_name="test", full_name="Test Scope", description="Scope for testing")
     self.scope.save()
     
     self.user = User(username="******", password="******", email="*****@*****.**")
     self.user.save()
     
     self.at = AuthorizationToken(client=self.oclient, user=self.user)
     self.at.save()
     self.at.scope = [self.scope]
     self.at.save()
     
     self.rt = self.at.generate_refresh_token()
     
     self.token = self.rt.generate_access_token()
     
     self.handler = BearerHandler()
     
     self.factory = RequestFactory()
Пример #9
0
class TestAuthorizationTokenModel(TestCase):
    def setUp(self):
        self.oclient = Client(name="Test Client", access_host="http://localhost/")
        self.oclient.save()

        self.scope = Scope(short_name="test", full_name="Test Scope", description="Scope for testing")
        self.scope.save()

        self.user = User(username="******", password="******", email="*****@*****.**")
        self.user.save()

        self.token = AuthorizationToken(client=self.oclient, user=self.user)
        self.token.save()

        self.token.scope = [self.scope]
        self.token.save()

    def test_unicode(self):
        self.assertEqual(unicode(self.token), self.token.token)

    def test_generate_refresh_token_creates(self):
        rt = self.token.generate_refresh_token()

        self.assertEqual(RefreshToken.objects.count(), 1)
        self.assertIsInstance(rt, RefreshToken)

    def test_generate_refresh_token_no_create_twice(self):
        self.token.generate_refresh_token()
        rt = self.token.generate_refresh_token()

        self.assertEqual(RefreshToken.objects.count(), 1)
        self.assertIsNone(rt)

    def test_generate_refresh_token_never_creates_twice(self):
        self.token.generate_refresh_token()
        self.token.is_active = True
        rt = self.token.generate_refresh_token()

        self.assertEqual(RefreshToken.objects.count(), 1)
        self.assertIsNone(rt)
Пример #10
0
class TestBearerHandler(TestCase):
    def setUp(self):
        self.oclient = Client(name="Test Client",
                              access_host="http://localhost/")
        self.oclient.save()

        self.scope = Scope(short_name="test",
                           full_name="Test Scope",
                           description="Scope for testing")
        self.scope.save()

        self.user = User(username="******",
                         password="******",
                         email="*****@*****.**")
        self.user.save()

        self.at = AuthorizationToken(client=self.oclient, user=self.user)
        self.at.save()
        self.at.scope = [self.scope]
        self.at.save()

        self.rt = self.at.generate_refresh_token()

        self.token = self.rt.generate_access_token()

        self.handler = BearerHandler()

        self.factory = RequestFactory()

    def test_access_token(self):
        request = self.factory.get("/")

        token = self.handler.access_token(self.token.token, request)

        self.assertEqual(token, self.token)

        token = self.handler.access_token("invalid", request)

        self.assertEqual(token, None)

    def test_authenticate(self):
        request = self.factory.get("/")

        user = self.handler.authenticate(self.token.token, request)

        self.assertEqual(user, self.user)

        user = self.handler.authenticate("invalid", request)

        self.assertEqual(user, None)

    def test_validate(self):
        from doac.exceptions.base import InvalidToken
        from doac.exceptions.invalid_request import CredentialsNotProvided

        request = self.factory.get("/")

        result = self.handler.validate(self.token.token, request)

        self.assertEqual(result, None)

        response = self.handler.validate("invalid", request)

        self.assertNotEqual(response, None)
        self.assertEqual(response.status_code, 401)
        self.assertEqual(response["WWW-Authenticate"],
                         request_error_header(InvalidToken))

        response = self.handler.validate("", request)

        self.assertNotEqual(response, None)
        self.assertEqual(response.status_code, 400)
        self.assertEqual(response["WWW-Authenticate"],
                         request_error_header(CredentialsNotProvided))
Пример #11
0
Файл: bearer.py Проект: EE/doac
class TestBearerHandler(TestCase):
    
    def setUp(self):
        self.oclient = Client(name="Test Client", access_host="http://localhost/")
        self.oclient.save()
        
        self.scope = Scope(short_name="test", full_name="Test Scope", description="Scope for testing")
        self.scope.save()
        
        self.user = User(username="******", password="******", email="*****@*****.**")
        self.user.save()
        
        self.at = AuthorizationToken(client=self.oclient, user=self.user)
        self.at.save()
        self.at.scope = [self.scope]
        self.at.save()
        
        self.rt = self.at.generate_refresh_token()
        
        self.token = self.rt.generate_access_token()
        
        self.handler = BearerHandler()
        
        self.factory = RequestFactory()

    def test_access_token(self):
        request = self.factory.get("/")
        
        token = self.handler.access_token(self.token.token, request)
        
        self.assertEqual(token, self.token)
        
        token = self.handler.access_token("invalid", request)
        
        self.assertEqual(token, None)
    
    def test_authenticate(self):
        request = self.factory.get("/")
        
        user = self.handler.authenticate(self.token.token, request)
        
        self.assertEqual(user, self.user)
        
        user = self.handler.authenticate("invalid", request)
        
        self.assertEqual(user, None)
    
    def test_validate(self):
        from doac.exceptions.base import InvalidToken
        from doac.exceptions.invalid_request import CredentialsNotProvided
        
        request = self.factory.get("/")
        
        result = self.handler.validate(self.token.token, request)
        
        self.assertEqual(result, None)
        
        response = self.handler.validate("invalid", request)
        
        self.assertNotEqual(response, None)
        self.assertEqual(response.status_code, 401)
        self.assertEqual(response["WWW-Authenticate"], request_error_header(InvalidToken))
        
        response = self.handler.validate("", request)
        
        self.assertNotEqual(response, None)
        self.assertEqual(response.status_code, 400)
        self.assertEqual(response["WWW-Authenticate"], request_error_header(CredentialsNotProvided))
Пример #12
0
class TestAuthorizationTokenModel(TestCase):
    def setUp(self):
        self.oclient = Client(name="Test Client",
                              access_host="http://localhost/")
        self.oclient.save()

        self.scope = Scope(short_name="test",
                           full_name="Test Scope",
                           description="Scope for testing")
        self.scope.save()

        self.user = User(username="******",
                         password="******",
                         email="*****@*****.**")
        self.user.save()

        self.token = AuthorizationToken(client=self.oclient, user=self.user)
        self.token.save()

        self.token.scope = [self.scope]
        self.token.save()

    def test_unicode(self):
        self.assertEqual(unicode(self.token), self.token.token)

    def test_generate_refresh_token_creates(self):
        rt = self.token.generate_refresh_token()

        self.assertEqual(RefreshToken.objects.count(), 1)
        self.assertIsInstance(rt, RefreshToken)

    def test_generate_refresh_token_no_create_twice(self):
        self.token.generate_refresh_token()
        rt = self.token.generate_refresh_token()

        self.assertEqual(RefreshToken.objects.count(), 1)
        self.assertIsNone(rt)

    def test_generate_refresh_token_never_creates_twice(self):
        self.token.generate_refresh_token()
        self.token.is_active = True
        rt = self.token.generate_refresh_token()

        self.assertEqual(RefreshToken.objects.count(), 1)
        self.assertIsNone(rt)