예제 #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)