Merge "Add a test for re-caching a token"

This commit is contained in:
Jenkins 2014-08-26 00:07:36 +00:00 committed by Gerrit Code Review
commit e3a3dff00f

View File

@ -1224,6 +1224,38 @@ class CommonAuthTokenMiddlewareTest(object):
use_kerberos=use_kerberos,
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,
testresources.ResourcedTestCase):