diff options
author | Adam Young <ayoung@redhat.com> | 2012-08-17 19:17:17 -0400 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2012-08-23 10:51:20 -0400 |
commit | 3fa4ba537e7d297aeb63554231d041da7ad2476f (patch) | |
tree | a68af65cb931573bdea07fd4d993eb641fa216cb /tests | |
parent | f20cfbf34ea0667996e7dc918f6c453ad1bd81ad (diff) | |
download | keystone-3fa4ba537e7d297aeb63554231d041da7ad2476f.tar.gz keystone-3fa4ba537e7d297aeb63554231d041da7ad2476f.tar.xz keystone-3fa4ba537e7d297aeb63554231d041da7ad2476f.zip |
Fix auth_token middleware to fetch revocation list as admin.
Make the revocation list into a JSON document and get the Vary header.
This will also allow the revocation list to carry additional
information in the future, to include sufficient information for the
calling application to figure out how to get the certificates it
requires.
Bug 1038309
Change-Id: I4a41cbd8a7352e5b5f951027d6f2063b169bce89
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_auth_token_middleware.py | 17 | ||||
-rw-r--r-- | tests/test_content_types.py | 27 | ||||
-rw-r--r-- | tests/test_overrides.conf | 5 |
3 files changed, 43 insertions, 6 deletions
diff --git a/tests/test_auth_token_middleware.py b/tests/test_auth_token_middleware.py index 07217dcf..db46a9a1 100644 --- a/tests/test_auth_token_middleware.py +++ b/tests/test_auth_token_middleware.py @@ -32,8 +32,8 @@ from keystone import config from keystone import test -#The data for these tests are signed using openssl and are stored in files -# in the signing subdirectory. IN order to keep the values consistent between +# The data for these tests are signed using openssl and are stored in files +# in the signing subdirectory. In order to keep the values consistent between # the tests and the signed documents, we read them in for use in the tests. def setUpModule(self): signing_path = os.path.join(os.path.dirname(__file__), 'signing') @@ -47,7 +47,8 @@ def setUpModule(self): with open(os.path.join(signing_path, 'revocation_list.json')) as f: self.REVOCATION_LIST = jsonutils.loads(f.read()) with open(os.path.join(signing_path, 'revocation_list.pem')) as f: - self.SIGNED_REVOCATION_LIST = f.read() + self.VALID_SIGNED_REVOCATION_LIST =\ + jsonutils.dumps({'signed': f.read()}) self.TOKEN_RESPONSES[self.SIGNED_TOKEN_SCOPED] = { 'access': { @@ -225,7 +226,7 @@ class FakeHTTPConnection(object): last_requested_url = '' def __init__(self, *args): - pass + self.send_valid_revocation_list = True def request(self, method, path, **kwargs): """Fakes out several http responses. @@ -319,6 +320,9 @@ class BaseAuthTokenMiddlewareTest(test.TestCase): self.middleware.token_revocation_list = jsonutils.dumps( {"revoked": [], "extra": "success"}) + globals()['SIGNED_REVOCATION_LIST'] =\ + globals()['VALID_SIGNED_REVOCATION_LIST'] + super(BaseAuthTokenMiddlewareTest, self).setUp() def tearDown(self): @@ -478,6 +482,11 @@ class AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest): self.middleware._token_revocation_list = None self.assertEqual(self.middleware.token_revocation_list, in_memory_list) + def test_invalid_revocation_list_raises_service_error(self): + globals()['SIGNED_REVOCATION_LIST'] = "{}" + with self.assertRaises(auth_token.ServiceError): + self.middleware.fetch_revocation_list() + def test_fetch_revocation_list(self): fetched_list = jsonutils.loads(self.middleware.fetch_revocation_list()) self.assertEqual(fetched_list, REVOCATION_LIST) diff --git a/tests/test_content_types.py b/tests/test_content_types.py index ba8d2a28..bd17f173 100644 --- a/tests/test_content_types.py +++ b/tests/test_content_types.py @@ -220,11 +220,15 @@ class RestfulTestCase(test.TestCase): def public_request(self, port=None, **kwargs): kwargs['port'] = port or self._public_port() - return self.restful_request(**kwargs) + response = self.restful_request(**kwargs) + self.assertValidResponseHeaders(response) + return response def admin_request(self, port=None, **kwargs): kwargs['port'] = port or self._admin_port() - return self.restful_request(**kwargs) + response = self.restful_request(**kwargs) + self.assertValidResponseHeaders(response) + return response def get_scoped_token(self): """Convenience method so that we can test authenticated requests.""" @@ -621,6 +625,25 @@ class JsonTestCase(RestfulTestCase, CoreApiTests): r = self.admin_request(path=path, expected_status=401) self.assertValidErrorResponse(r) + def test_fetch_revocation_list_nonadmin_fails(self): + r = self.admin_request( + method='GET', + path='/v2.0/tokens/revoked', + expected_status=401) + + def test_fetch_revocation_list_admin_200(self): + token = self.get_scoped_token() + r = self.restful_request( + method='GET', + path='/v2.0/tokens/revoked', + token=token, + expected_status=200, + port=self._admin_port()) + self.assertValidRevocationListResponse(r) + + def assertValidRevocationListResponse(self, response): + self.assertIsNotNone(response.body['signed']) + class XmlTestCase(RestfulTestCase, CoreApiTests): xmlns = 'http://docs.openstack.org/identity/api/v2.0' diff --git a/tests/test_overrides.conf b/tests/test_overrides.conf index e88a4ab9..15c18faf 100644 --- a/tests/test_overrides.conf +++ b/tests/test_overrides.conf @@ -7,3 +7,8 @@ driver = keystone.identity.backends.kvs.Identity [catalog] driver = keystone.catalog.backends.templated.TemplatedCatalog template_file = default_catalog.templates + +[signing] +certfile = signing/signing_cert.pem +keyfile = signing/private_key.pem +ca_certs = signing/cacert.pem |