Ejemplo n.º 1
0
    def delete_user_success(self, jwt_header):
        header = {'HTTP_AUTHORIZATION': jwt_header}
        response = self.client.delete(reverse('user'), **header)
        self.assertContains(response, 'ok', status_code=200)

        with self.assertRaises(Exception):
            User.get_current_user(jwt_header)
Ejemplo n.º 2
0
 def test_get_current_user_no_redis_entity(self):
     """
     get_current_user must raise error if no redis entity for user
     """
     user = self.create_user()
     encoded_jwt, timestamp = self.make_jwt(user)
     decoded_jwt = encoded_jwt.decode('utf-8')
     with self.assertRaises(Exception):
         User.get_current_user(decoded_jwt)
Ejemplo n.º 3
0
 def test_get_current_user_with_old_timestamp(self):
     """
     get_current_user must raise error if timestamp is timed out
     """
     user = self.create_user()
     encoded_jwt, timestamp = self.make_jwt(user)
     decoded_jwt = encoded_jwt.decode('utf-8')
     User.redis_connection.database[encoded_jwt] = timestamp - User.JWT_TIMEOUT - 1
     with self.assertRaises(Exception):
         User.get_current_user(decoded_jwt)
Ejemplo n.º 4
0
 def test_get_current_user(self):
     """
     get_current_user must return authenticated user by jwt
     """
     user = self.create_user()
     encoded_jwt, timestamp = self.make_jwt(user)
     decoded_jwt = encoded_jwt.decode('utf-8')
     User.redis_connection.database[encoded_jwt] = timestamp
     authenticated_user = User.get_current_user(decoded_jwt)
     self.assertEqual(user.email, authenticated_user.email, 'Wrong user returned')