From ae0515c3a078ce27ccca1ef5a98092208c030f2f Mon Sep 17 00:00:00 2001 From: ayoung Date: Sat, 5 May 2012 14:08:18 -0400 Subject: Admin Auth URI prefix Allows the prepending of a prefix to the URI used for admin tasks. This allows URIs like https://hostname/keystone/main/v2.0 PEP8 fix Added To Unit test to ensure auth_prefix is checked Bug: 994860 Change-Id: I851e059e8b17c1bc02ab93d8b09a3fb47b9d3fee --- keystone/config.py | 1 + keystone/middleware/auth_token.py | 4 +++- tests/test_auth_token_middleware.py | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/keystone/config.py b/keystone/config.py index 86c50c82..8529eb8a 100644 --- a/keystone/config.py +++ b/keystone/config.py @@ -117,6 +117,7 @@ register_str('compute_port', default=8774) register_str('admin_port', default=35357) register_str('public_port', default=5000) register_str('onready') +register_str('auth_admin_prefix', default='') #ssl options register_bool('enable', group='ssl', default=False) diff --git a/keystone/middleware/auth_token.py b/keystone/middleware/auth_token.py index b383aaf9..d504e20c 100644 --- a/keystone/middleware/auth_token.py +++ b/keystone/middleware/auth_token.py @@ -139,6 +139,7 @@ class AuthProtocol(object): default_auth_uri = '%s://%s:%s' % (self.auth_protocol, self.auth_host, self.auth_port) + self.auth_admin_prefix = conf.get('auth_admin_prefix', '') self.auth_uri = conf.get('auth_uri', default_auth_uri) # SSL @@ -296,8 +297,9 @@ class AuthProtocol(object): if body: kwargs['body'] = jsonutils.dumps(body) + full_path = self.auth_admin_prefix + path try: - conn.request(method, path, **kwargs) + conn.request(method, full_path, **kwargs) response = conn.getresponse() body = response.read() except Exception, e: diff --git a/tests/test_auth_token_middleware.py b/tests/test_auth_token_middleware.py index 89e9a47c..01736e7c 100644 --- a/tests/test_auth_token_middleware.py +++ b/tests/test_auth_token_middleware.py @@ -20,6 +20,7 @@ import webob from keystone.middleware import auth_token from keystone.openstack.common import jsonutils +from keystone import config from keystone import test @@ -130,6 +131,8 @@ class FakeHTTPResponse(object): class FakeHTTPConnection(object): + last_requested_url = '' + def __init__(self, *args): pass @@ -144,6 +147,7 @@ class FakeHTTPConnection(object): a 404, indicating an unknown (therefore unauthorized) token. """ + FakeHTTPConnection.last_requested_url = path if method == 'POST': status = 200 body = jsonutils.dumps({ @@ -204,6 +208,7 @@ class BaseAuthTokenMiddlewareTest(test.TestCase): 'admin_token': 'admin_token1', 'auth_host': 'keystone.example.com', 'auth_port': 1234, + 'auth_admin_prefix': '/testadmin', } self.middleware = auth_token.AuthProtocol(FakeApp(expected_env), conf) @@ -243,6 +248,10 @@ class AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest): req = webob.Request.blank('/') req.headers['X-Auth-Token'] = 'valid-token' body = self.middleware(req.environ, self.start_fake_response) + self.assertEqual(self.middleware.conf['auth_admin_prefix'], + "/testadmin") + self.assertEqual("/testadmin/v2.0/tokens/valid-token", + FakeHTTPConnection.last_requested_url) self.assertEqual(self.response_status, 200) self.assertTrue(req.headers.get('X-Service-Catalog')) self.assertEqual(body, ['SUCCESS']) -- cgit