Call an existing method in sync cache for revoke events

The cache used for synchronizing the revocation tree across
green threads had an issue where it was calling a non-existant
method ``remove`` instead of ``remove_event``. The correct method
is now being called and an expanded test to exercise the synchronize
method has been added.

Change-Id: I3fe47fa51f88aab89480831b2d95746319f82ceb
Closes-Bug: 1289935
This commit is contained in:
Morgan Fainberg 2014-03-08 21:57:51 -08:00 committed by Adam Young
parent a240705b07
commit 3035a6b394
2 changed files with 34 additions and 1 deletions

View File

@ -76,7 +76,7 @@ class _Cache(object):
with self._store.get_lock(_TREE_KEY):
for e in self._current_events:
if e.revoked_at < cutoff:
self.revoke_map.remove(e)
self.revoke_map.remove_event(e)
self._current_events.remove(e)
else:
break

View File

@ -14,9 +14,12 @@
import datetime
import uuid
import mock
from keystone.common import dependency
from keystone import config
from keystone.contrib.revoke import model
from keystone import exception
from keystone.openstack.common import timeutils
from keystone import tests
from keystone.tests import test_backend_sql
@ -137,6 +140,36 @@ class RevokeTests(object):
self.revoke_api.revoke(event)
self.assertEqual(1, len(self.revoke_api.get_events()))
@mock.patch.object(timeutils, 'utcnow')
def test_expired_events_removed_validate_token_success(self, mock_utcnow):
def _sample_token_values():
token = _sample_blank_token()
token['expires_at'] = timeutils.isotime(_future_time(),
subsecond=True)
return token
now = datetime.datetime.utcnow()
now_plus_2h = now + datetime.timedelta(hours=2)
mock_utcnow.return_value = now
# Build a token and validate it. This will seed the cache for the
# future 'synchronize' call.
token_values = _sample_token_values()
user_id = _new_id()
self.revoke_api.revoke_by_user(user_id)
token_values['user_id'] = user_id
self.assertRaises(exception.TokenNotFound,
self.revoke_api.check_token,
token_values)
# Move our clock forward by 2h, build a new token and validate it.
# 'synchronize' should now be exercised and remove old expired events
mock_utcnow.return_value = now_plus_2h
self.revoke_api.revoke_by_expiration(_new_id(), now_plus_2h)
#should no longer throw an exception
self.revoke_api.check_token(token_values)
class SqlRevokeTests(test_backend_sql.SqlTests, RevokeTests):
def setUp(self):