Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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])
Ejemplo n.º 3
0
    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'])
Ejemplo n.º 4
0
 def test_payload_decoding_error(self):
     with self.assertRaises(JSONWebTokenError):
         utils.get_payload('invalid')
Ejemplo n.º 5
0
    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)