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.')
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)
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)
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)
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)
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)
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)
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)
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)
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')