def test_token_is_removed_from_redis_when_user_has_multiple_tokens(self): second_token, first_device = MultiToken.create_token(self.user) MultiToken.expire_token(self.token) self.assertEqual(len(TOKENS_CACHE.get(self.user.pk)), 1) _, hash = parse_full_token(self.token.key) self.assertIsNone(TOKENS_CACHE.get(hash)) self.assertEqual( TOKENS_CACHE.get(self.user.pk)[0], parse_full_token(second_token.key)[1]) self.assertIsNotNone( TOKENS_CACHE.get(parse_full_token(second_token.key)[1]))
def test_other_users_tokens_are_not_affected(self): second_user = create_test_user('tester2') second_token, _ = MultiToken.create_token(second_user) MultiToken.expire_token(self.token) self.assertIsNotNone(TOKENS_CACHE.get(second_user.pk)) self.assertIsNotNone( TOKENS_CACHE.get(parse_full_token(second_token.key)[1]))
def test_bad_full_token_returns_generic_bad_result(self): bad_full_token = ' '.join(self.full_token.split(TOKEN_HASH_SEPARATOR)) self.assertEqual(len(parse_full_token(bad_full_token)), 2) self.assertIn(WRONG_TOKEN, parse_full_token(bad_full_token)) self.assertIn(WRONG_HASH, parse_full_token(bad_full_token))
def test_correct_full_token_is_parsed_correctly(self): self.assertEqual(len(parse_full_token(self.full_token)), 2) self.assertIn(self.token, parse_full_token(self.full_token)) self.assertIn(self.hash, parse_full_token(self.full_token))
def test_token_is_removed_from_redis_when_user_has_only_one_token(self): self.assertIsNone(MultiToken.expire_token(self.token)) self.assertEqual(len(TOKENS_CACHE.get(self.user.pk)), 0) _, hash = parse_full_token(self.token.key) self.assertIsNone(TOKENS_CACHE.get(hash))