Esempio n. 1
0
class TestJWTKeyAuthentication(JWTAuthTester):
    fixtures = ['base/addon_3615']

    def setUp(self):
        super(TestJWTKeyAuthentication, self).setUp()
        self.factory = RequestFactory()
        self.auth = JWTKeyAuthentication()
        self.user = UserProfile.objects.get(email='*****@*****.**')

    def request(self, token):
        return self.factory.get('/', HTTP_AUTHORIZATION='JWT {}'.format(token))

    def _create_token(self):
        api_key = self.create_api_key(self.user)
        return self.create_auth_token(api_key.user, api_key.key,
                                      api_key.secret)

    def test_get_user(self):
        user, _ = self.auth.authenticate(self.request(self._create_token()))
        assert user == self.user

    def test_unknown_issuer(self):
        api_key = self.create_api_key(self.user)
        payload = self.auth_token_payload(self.user, api_key.key)
        payload['iss'] = 'non-existant-issuer'
        token = self.encode_token_payload(payload, api_key.secret)

        with self.assertRaises(AuthenticationFailed):
            self.auth.authenticate(self.request(token))

    def test_deleted_user(self):
        self.user.update(deleted=True)
        with self.assertRaises(AuthenticationFailed):
            self.auth.authenticate(self.request(self._create_token()))

    def test_user_has_not_read_agreement(self):
        self.user.update(read_dev_agreement=None)
        with self.assertRaises(AuthenticationFailed):
            self.auth.authenticate(self.request(self._create_token()))
Esempio n. 2
0
class TestJWTKeyAuthentication(JWTAuthTester):
    fixtures = ["base/addon_3615"]

    def setUp(self):
        super(TestJWTKeyAuthentication, self).setUp()
        self.factory = RequestFactory()
        self.auth = JWTKeyAuthentication()
        self.user = UserProfile.objects.get(email="*****@*****.**")

    def request(self, token):
        return self.factory.get("/", HTTP_AUTHORIZATION="JWT {}".format(token))

    def _create_token(self):
        api_key = self.create_api_key(self.user)
        return self.create_auth_token(api_key.user, api_key.key, api_key.secret)

    def test_get_user(self):
        user, _ = self.auth.authenticate(self.request(self._create_token()))
        assert user == self.user

    def test_unknown_issuer(self):
        api_key = self.create_api_key(self.user)
        payload = self.auth_token_payload(self.user, api_key.key)
        payload["iss"] = "non-existant-issuer"
        token = self.encode_token_payload(payload, api_key.secret)

        with self.assertRaises(AuthenticationFailed):
            self.auth.authenticate(self.request(token))

    def test_deleted_user(self):
        self.user.update(deleted=True)
        with self.assertRaises(AuthenticationFailed):
            self.auth.authenticate(self.request(self._create_token()))

    def test_user_has_not_read_agreement(self):
        self.user.update(read_dev_agreement=None)
        with self.assertRaises(AuthenticationFailed):
            self.auth.authenticate(self.request(self._create_token()))
Esempio n. 3
0
 def setUp(self):
     super(TestJWTKeyAuthentication, self).setUp()
     self.factory = RequestFactory()
     self.auth = JWTKeyAuthentication()
     self.user = UserProfile.objects.get(email='*****@*****.**')
Esempio n. 4
0
 def setUp(self):
     super(TestJWTKeyAuthentication, self).setUp()
     self.factory = RequestFactory()
     self.auth = JWTKeyAuthentication()
     self.user = UserProfile.objects.get(email="*****@*****.**")