def test_get_cache_key(self): conf = { "auth_host": "keystone.example.com", "auth_port": 1234, "auth_admin_prefix": "/testadmin", "memcache_servers": "localhost:11211", "memcache_secret_key": "mysecret", } self.set_middleware(conf=conf) self.assertEqual("tokens/mytoken", self.middleware._get_cache_key("mytoken")) conf = { "auth_host": "keystone.example.com", "auth_port": 1234, "auth_admin_prefix": "/testadmin", "memcache_servers": "localhost:11211", "memcache_security_strategy": "mac", "memcache_secret_key": "mysecret", } self.set_middleware(conf=conf) expected = "tokens/" + memcache_crypt.hash_data("mytoken" + "mysecret") self.assertEqual(self.middleware._get_cache_key("mytoken"), expected) conf = { "auth_host": "keystone.example.com", "auth_port": 1234, "auth_admin_prefix": "/testadmin", "memcache_servers": "localhost:11211", "memcache_security_strategy": "Encrypt", "memcache_secret_key": "abc!", } self.set_middleware(conf=conf) expected = "tokens/" + memcache_crypt.hash_data("mytoken" + "abc!") self.assertEqual(self.middleware._get_cache_key("mytoken"), expected)
def test_get_cache_key(self): conf = { 'admin_token': 'admin_token1', 'auth_host': 'keystone.example.com', 'auth_port': 1234, 'memcache_servers': 'localhost:11211', 'memcache_secret_key': 'mysecret', } auth = auth_token.AuthProtocol(FakeApp(), conf) self.assertEqual( 'tokens/mytoken', auth._get_cache_key('mytoken')) conf = { 'admin_token': 'admin_token1', 'auth_host': 'keystone.example.com', 'auth_port': 1234, 'memcache_servers': 'localhost:11211', 'memcache_security_strategy': 'mac', 'memcache_secret_key': 'mysecret', } auth = auth_token.AuthProtocol(FakeApp(), conf) expected = 'tokens/' + memcache_crypt.hash_data('mytoken' + 'mysecret') self.assertEqual(auth._get_cache_key('mytoken'), expected) conf = { 'admin_token': 'admin_token1', 'auth_host': 'keystone.example.com', 'auth_port': 1234, 'memcache_servers': 'localhost:11211', 'memcache_security_strategy': 'Encrypt', 'memcache_secret_key': 'abc!', } auth = auth_token.AuthProtocol(FakeApp(), conf) expected = 'tokens/' + memcache_crypt.hash_data('mytoken' + 'abc!') self.assertEqual(auth._get_cache_key('mytoken'), expected)
def _get_cache_key(self, token): """ Return the cache key. Do not use clear token as key if memcache protection is on. """ htoken = token if self._memcache_security_strategy in ('ENCRYPT', 'MAC'): derv_token = token + self._memcache_secret_key htoken = memcache_crypt.hash_data(derv_token) return 'tokens/%s' % htoken