From 4b33f0dae3b372b2be0bd345ae03d30673a70274 Mon Sep 17 00:00:00 2001 From: Tim Simpson Date: Wed, 14 Mar 2012 21:18:53 -0500 Subject: [PATCH] Fixed auth to work with keystone. * Was incorrectly looking for X_TENANT instead of X-Tenant-Id. --- reddwarf/common/auth.py | 2 +- reddwarf/tests/unit/common/__init__.py | 0 reddwarf/tests/unit/common/test_auth.py | 47 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 reddwarf/tests/unit/common/__init__.py create mode 100644 reddwarf/tests/unit/common/test_auth.py diff --git a/reddwarf/common/auth.py b/reddwarf/common/auth.py index 7a8e7e9154..805060d786 100644 --- a/reddwarf/common/auth.py +++ b/reddwarf/common/auth.py @@ -36,7 +36,7 @@ class AuthorizationMiddleware(wsgi.Middleware): def process_request(self, request): roles = request.headers.get('X_ROLE', '').split(',') LOG.debug("Processing auth request with roles: %s" % roles) - tenant_id = request.headers.get('X_TENANT', None) + tenant_id = request.headers.get('X-Tenant-Id', None) LOG.debug("Processing auth request with tenant_id: %s" % tenant_id) for provider in self.auth_providers: provider.authorize(request, tenant_id, roles) diff --git a/reddwarf/tests/unit/common/__init__.py b/reddwarf/tests/unit/common/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/reddwarf/tests/unit/common/test_auth.py b/reddwarf/tests/unit/common/test_auth.py new file mode 100644 index 0000000000..a089d9a632 --- /dev/null +++ b/reddwarf/tests/unit/common/test_auth.py @@ -0,0 +1,47 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright 2012 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import unittest + +from reddwarf.common.auth import TenantBasedAuth + + +class TenantRegexTest(unittest.TestCase): + + def check(self, path, no_match=False, expected_tenant_id=None, + expected_version_id=None): + print("Path=%s" % path) + match = TenantBasedAuth.tenant_scoped_url.match(path) + if no_match: + self.assertIsNone(match, "Somehow path %s was a match!" % path) + else: + self.assertIsNotNone(match) + if expected_tenant_id: + actual = match.group('tenant_id') + self.assertEqual(expected_tenant_id, actual) + else: + self.assertRaises(IndexError, match.group('tenant_id')) + + def test_no_match(self): + self.check("blah", no_match=True) + + def test_has_tenant_id1(self): + self.check("/mgmt/instances/None", expected_tenant_id="mgmt") + + def test_has_tenant_id2(self): + self.check( + "/9bbf90bc162d4d1ea458af6214a625e6/mgmt/instances/None", + expected_tenant_id="9bbf90bc162d4d1ea458af6214a625e6")