예제 #1
0
    def test_decode_jwt_logs_exception_message_when_decode_throws_exception(
            self, logger_mock, decode):
        auth = 'JWT ' + make_id_token(self.user.username)
        decode.side_effect = DecodeError, BadSignatureError

        resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)

        self.assertEqual(resp.status_code, 401)
        logger_mock.exception.assert_called_once_with(
            'Invalid Authorization header. JWT Signature verification failed.')
예제 #2
0
 def test_with_multiple_audiences_and_authorized_party(self):
     auth = 'JWT ' + \
            make_id_token(self.user.username, aud=['you', 'me'], azp='you')
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)
     self.assertEqual(resp.status_code, 200)
예제 #3
0
 def test_with_invalid_signature(self):
     auth = 'JWT ' + make_id_token(self.user.username)
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth + 'x')
     self.assertEqual(resp.status_code, 401)
예제 #4
0
 def test_with_unknown_subject(self):
     auth = 'JWT ' + make_id_token(self.user.username + 'x')
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)
     self.assertEqual(resp.status_code, 401)
예제 #5
0
 def test_with_invalid_multiple_audiences(self):
     auth = 'JWT ' + make_id_token(self.user.username, aud=['we', 'me'])
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)
     self.assertEqual(resp.status_code, 401)
예제 #6
0
 def test_with_too_new_jwt(self):
     auth = 'JWT ' + make_id_token(self.user.username, nbf=999999999999)
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)
     self.assertEqual(resp.status_code, 401)
예제 #7
0
 def test_with_invalid_audience(self):
     auth = 'JWT ' + make_id_token(self.user.username, aud='somebody')
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)
     self.assertEqual(resp.status_code, 401)
예제 #8
0
 def test_with_invalid_issuer(self):
     auth = 'JWT ' + \
            make_id_token(self.user.username, iss='http://something.com')
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)
     self.assertEqual(resp.status_code, 401)
예제 #9
0
 def test_with_old_jwt(self):
     auth = 'JWT ' + make_id_token(self.user.username, iat=13151351)
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)
     self.assertEqual(resp.status_code, 401)
예제 #10
0
 def test_using_valid_jwt(self):
     auth = 'JWT ' + make_id_token(self.user.username)
     resp = self.client.get('/test/', HTTP_AUTHORIZATION=auth)
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(resp.content.decode(), 'a')