def test_payload_decode_audience_missing(self): payload = utils.jwt_payload(self.user) token = utils.jwt_encode(payload) with override_jwt_settings(JWT_AUDIENCE='test'): with self.assertRaises(JSONWebTokenError): utils.get_payload(token)
def test_token_auth(self): response = self.client.execute( self.query, { self.user.USERNAME_FIELD: self.user.get_username(), 'password': '******', }) payload = get_payload(response.data['tokenAuth']['token']) self.assertEqual(self.user.get_username(), payload[self.user.USERNAME_FIELD])
def test_refresh(self): with back_to_the_future(seconds=1): response = self.client.execute(self.query, token=self.token) data = response.data['refreshToken'] token = data['token'] payload = get_payload(token) self.assertNotEqual(self.token, token) self.assertEqual(self.user.get_username(), data['payload'][self.user.USERNAME_FIELD]) self.assertEqual(self.payload['origIat'], payload['origIat']) self.assertLess(self.payload['exp'], payload['exp'])
def test_payload_decoding_error(self): with self.assertRaises(JSONWebTokenError): utils.get_payload('invalid')
def test_payload_expired_signature(self): payload = utils.jwt_payload(self.user) token = utils.jwt_encode(payload) with self.assertRaises(JSONWebTokenError): utils.get_payload(token)