Add a test for re-caching a token
There was no test that showed that when a token was in the cache and a request is made to validate it again, it gets cached again. Change-Id: I1992fa6b5ddc0792dfd1ce90fb888c365ecb1612 Partial-Bug: #1289075
This commit is contained in:
parent
c9036a00ef
commit
7c954516f5
@ -1212,6 +1212,38 @@ class CommonAuthTokenMiddlewareTest(object):
|
|||||||
use_kerberos=use_kerberos,
|
use_kerberos=use_kerberos,
|
||||||
success=False)
|
success=False)
|
||||||
|
|
||||||
|
def test_caching_token_on_verify(self):
|
||||||
|
# When the token is cached, it's cached again when it's verified.
|
||||||
|
# NOTE(blk-u): This behavior is incorrect and inefficient, see
|
||||||
|
# bug 1289075.
|
||||||
|
|
||||||
|
# The token cache has to be initialized with our cache instance.
|
||||||
|
self.middleware._token_cache._env_cache_name = 'cache'
|
||||||
|
cache = memorycache.Client()
|
||||||
|
self.middleware._token_cache.initialize(env={'cache': cache})
|
||||||
|
|
||||||
|
# Mock cache.set since then the test can verify call_count.
|
||||||
|
orig_cache_set = cache.set
|
||||||
|
cache.set = mock.Mock(side_effect=orig_cache_set)
|
||||||
|
|
||||||
|
token = self.token_dict['signed_token_scoped']
|
||||||
|
|
||||||
|
req = webob.Request.blank('/')
|
||||||
|
req.headers['X-Auth-Token'] = token
|
||||||
|
self.middleware(req.environ, self.start_fake_response)
|
||||||
|
self.assertEqual(200, self.response_status)
|
||||||
|
|
||||||
|
self.assertThat(1, matchers.Equals(cache.set.call_count))
|
||||||
|
|
||||||
|
req = webob.Request.blank('/')
|
||||||
|
req.headers['X-Auth-Token'] = token
|
||||||
|
self.middleware(req.environ, self.start_fake_response)
|
||||||
|
self.assertEqual(200, self.response_status)
|
||||||
|
|
||||||
|
# FIXME(blk-u): This should be 1 since the token shouldn't be cached
|
||||||
|
# again.
|
||||||
|
self.assertThat(2, matchers.Equals(cache.set.call_count))
|
||||||
|
|
||||||
|
|
||||||
class V2CertDownloadMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
class V2CertDownloadMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
||||||
testresources.ResourcedTestCase):
|
testresources.ResourcedTestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user