diff options
Diffstat (limited to 'keystone-moon/keystone/tests/unit/test_versions.py')
-rw-r--r-- | keystone-moon/keystone/tests/unit/test_versions.py | 107 |
1 files changed, 73 insertions, 34 deletions
diff --git a/keystone-moon/keystone/tests/unit/test_versions.py b/keystone-moon/keystone/tests/unit/test_versions.py index 7f722f94..fc8051b2 100644 --- a/keystone-moon/keystone/tests/unit/test_versions.py +++ b/keystone-moon/keystone/tests/unit/test_versions.py @@ -20,11 +20,13 @@ import random import mock from oslo_config import cfg from oslo_serialization import jsonutils +from six.moves import http_client from testtools import matchers as tt_matchers +import webob from keystone.common import json_home from keystone import controllers -from keystone.tests import unit as tests +from keystone.tests import unit from keystone.tests.unit import utils @@ -170,6 +172,8 @@ BASE_ACCESS_TOKEN = ( # TODO(stevemar): Use BASE_IDP_PROTOCOL when bug 1420125 is resolved. FEDERATED_AUTH_URL = ('/OS-FEDERATION/identity_providers/{identity_provider}' '/protocols/{protocol}/auth') +FEDERATED_IDP_SPECIFIC_WEBSSO = ('/auth/OS-FEDERATION/identity_providers/' + '{idp_id}/protocols/{protocol_id}/websso') V3_JSON_HOME_RESOURCES_INHERIT_DISABLED = { json_home.build_v3_resource_relation('auth_tokens'): { @@ -345,13 +349,13 @@ V3_JSON_HOME_RESOURCES_INHERIT_DISABLED = { 'href-vars': {'user_id': json_home.Parameters.USER_ID, }}, json_home.build_v3_resource_relation('users'): {'href': '/users'}, _build_federation_rel(resource_name='domains'): { - 'href': '/OS-FEDERATION/domains'}, + 'href': '/auth/domains'}, _build_federation_rel(resource_name='websso'): { 'href-template': '/auth/OS-FEDERATION/websso/{protocol_id}', 'href-vars': { 'protocol_id': PROTOCOL_ID_PARAM_RELATION, }}, _build_federation_rel(resource_name='projects'): { - 'href': '/OS-FEDERATION/projects'}, + 'href': '/auth/projects'}, _build_federation_rel(resource_name='saml2'): { 'href': '/auth/OS-FEDERATION/saml2'}, _build_federation_rel(resource_name='ecp'): { @@ -368,6 +372,11 @@ V3_JSON_HOME_RESOURCES_INHERIT_DISABLED = { { 'href-template': '/OS-FEDERATION/identity_providers/{idp_id}', 'href-vars': {'idp_id': IDP_ID_PARAMETER_RELATION, }}, + _build_federation_rel(resource_name='identity_providers'): { + 'href-template': FEDERATED_IDP_SPECIFIC_WEBSSO, + 'href-vars': { + 'idp_id': IDP_ID_PARAMETER_RELATION, + 'protocol_id': PROTOCOL_ID_PARAM_RELATION, }}, _build_federation_rel(resource_name='service_provider'): { 'href-template': '/OS-FEDERATION/service_providers/{sp_id}', @@ -614,6 +623,36 @@ V3_JSON_HOME_RESOURCES_INHERIT_ENABLED.update( ) +class TestClient(object): + def __init__(self, app=None, token=None): + self.app = app + self.token = token + + def request(self, method, path, headers=None, body=None): + if headers is None: + headers = {} + + if self.token: + headers.setdefault('X-Auth-Token', self.token) + + req = webob.Request.blank(path) + req.method = method + for k, v in headers.items(): + req.headers[k] = v + if body: + req.body = body + return req.get_response(self.app) + + def get(self, path, headers=None): + return self.request('GET', path=path, headers=headers) + + def post(self, path, headers=None, body=None): + return self.request('POST', path=path, headers=headers, body=body) + + def put(self, path, headers=None, body=None): + return self.request('PUT', path=path, headers=headers, body=body) + + class _VersionsEqual(tt_matchers.MatchesListwise): def __init__(self, expected): super(_VersionsEqual, self).__init__([ @@ -632,7 +671,7 @@ class _VersionsEqual(tt_matchers.MatchesListwise): ]) -class VersionTestCase(tests.TestCase): +class VersionTestCase(unit.TestCase): def setUp(self): super(VersionTestCase, self).setUp() self.load_backends() @@ -657,7 +696,7 @@ class VersionTestCase(tests.TestCase): link['href'] = port def test_public_versions(self): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) resp = client.get('/') self.assertEqual(300, resp.status_int) data = jsonutils.loads(resp.body) @@ -674,7 +713,7 @@ class VersionTestCase(tests.TestCase): self.assertThat(data, _VersionsEqual(expected)) def test_admin_versions(self): - client = tests.TestClient(self.admin_app) + client = TestClient(self.admin_app) resp = client.get('/') self.assertEqual(300, resp.status_int) data = jsonutils.loads(resp.body) @@ -694,7 +733,7 @@ class VersionTestCase(tests.TestCase): self.config_fixture.config(public_endpoint=None, admin_endpoint=None) for app in (self.public_app, self.admin_app): - client = tests.TestClient(app) + client = TestClient(app) resp = client.get('/') self.assertEqual(300, resp.status_int) data = jsonutils.loads(resp.body) @@ -710,9 +749,9 @@ class VersionTestCase(tests.TestCase): self.assertThat(data, _VersionsEqual(expected)) def test_public_version_v2(self): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) resp = client.get('/v2.0/') - self.assertEqual(200, resp.status_int) + self.assertEqual(http_client.OK, resp.status_int) data = jsonutils.loads(resp.body) expected = v2_VERSION_RESPONSE self._paste_in_port(expected['version'], @@ -721,9 +760,9 @@ class VersionTestCase(tests.TestCase): self.assertEqual(expected, data) def test_admin_version_v2(self): - client = tests.TestClient(self.admin_app) + client = TestClient(self.admin_app) resp = client.get('/v2.0/') - self.assertEqual(200, resp.status_int) + self.assertEqual(http_client.OK, resp.status_int) data = jsonutils.loads(resp.body) expected = v2_VERSION_RESPONSE self._paste_in_port(expected['version'], @@ -734,18 +773,18 @@ class VersionTestCase(tests.TestCase): def test_use_site_url_if_endpoint_unset_v2(self): self.config_fixture.config(public_endpoint=None, admin_endpoint=None) for app in (self.public_app, self.admin_app): - client = tests.TestClient(app) + client = TestClient(app) resp = client.get('/v2.0/') - self.assertEqual(200, resp.status_int) + self.assertEqual(http_client.OK, resp.status_int) data = jsonutils.loads(resp.body) expected = v2_VERSION_RESPONSE self._paste_in_port(expected['version'], 'http://localhost/v2.0/') self.assertEqual(data, expected) def test_public_version_v3(self): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) resp = client.get('/v3/') - self.assertEqual(200, resp.status_int) + self.assertEqual(http_client.OK, resp.status_int) data = jsonutils.loads(resp.body) expected = v3_VERSION_RESPONSE self._paste_in_port(expected['version'], @@ -755,9 +794,9 @@ class VersionTestCase(tests.TestCase): @utils.wip('waiting on bug #1381961') def test_admin_version_v3(self): - client = tests.TestClient(self.admin_app) + client = TestClient(self.admin_app) resp = client.get('/v3/') - self.assertEqual(200, resp.status_int) + self.assertEqual(http_client.OK, resp.status_int) data = jsonutils.loads(resp.body) expected = v3_VERSION_RESPONSE self._paste_in_port(expected['version'], @@ -768,9 +807,9 @@ class VersionTestCase(tests.TestCase): def test_use_site_url_if_endpoint_unset_v3(self): self.config_fixture.config(public_endpoint=None, admin_endpoint=None) for app in (self.public_app, self.admin_app): - client = tests.TestClient(app) + client = TestClient(app) resp = client.get('/v3/') - self.assertEqual(200, resp.status_int) + self.assertEqual(http_client.OK, resp.status_int) data = jsonutils.loads(resp.body) expected = v3_VERSION_RESPONSE self._paste_in_port(expected['version'], 'http://localhost/v3/') @@ -778,14 +817,14 @@ class VersionTestCase(tests.TestCase): @mock.patch.object(controllers, '_VERSIONS', ['v3']) def test_v2_disabled(self): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) # request to /v2.0 should fail resp = client.get('/v2.0/') - self.assertEqual(404, resp.status_int) + self.assertEqual(http_client.NOT_FOUND, resp.status_int) # request to /v3 should pass resp = client.get('/v3/') - self.assertEqual(200, resp.status_int) + self.assertEqual(http_client.OK, resp.status_int) data = jsonutils.loads(resp.body) expected = v3_VERSION_RESPONSE self._paste_in_port(expected['version'], @@ -811,14 +850,14 @@ class VersionTestCase(tests.TestCase): @mock.patch.object(controllers, '_VERSIONS', ['v2.0']) def test_v3_disabled(self): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) # request to /v3 should fail resp = client.get('/v3/') - self.assertEqual(404, resp.status_int) + self.assertEqual(http_client.NOT_FOUND, resp.status_int) # request to /v2.0 should pass resp = client.get('/v2.0/') - self.assertEqual(200, resp.status_int) + self.assertEqual(http_client.OK, resp.status_int) data = jsonutils.loads(resp.body) expected = v2_VERSION_RESPONSE self._paste_in_port(expected['version'], @@ -843,7 +882,7 @@ class VersionTestCase(tests.TestCase): self.assertEqual(v2_only_response, data) def _test_json_home(self, path, exp_json_home_data): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) resp = client.get(path, headers={'Accept': 'application/json-home'}) self.assertThat(resp.status, tt_matchers.Equals('200 OK')) @@ -876,7 +915,7 @@ class VersionTestCase(tests.TestCase): # Accept headers with multiple types and qvalues are handled. def make_request(accept_types=None): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) headers = None if accept_types: headers = {'Accept': accept_types} @@ -926,7 +965,7 @@ class VersionTestCase(tests.TestCase): self.assertIsNone(extensions_property) -class VersionSingleAppTestCase(tests.TestCase): +class VersionSingleAppTestCase(unit.TestCase): """Tests running with a single application loaded. These are important because when Keystone is running in Apache httpd @@ -962,7 +1001,7 @@ class VersionSingleAppTestCase(tests.TestCase): else: return CONF.eventlet_server.public_port app = self.loadapp('keystone', app_name) - client = tests.TestClient(app) + client = TestClient(app) resp = client.get('/') self.assertEqual(300, resp.status_int) data = jsonutils.loads(resp.body) @@ -983,7 +1022,7 @@ class VersionSingleAppTestCase(tests.TestCase): self._test_version('admin') -class VersionInheritEnabledTestCase(tests.TestCase): +class VersionInheritEnabledTestCase(unit.TestCase): def setUp(self): super(VersionInheritEnabledTestCase, self).setUp() self.load_backends() @@ -1008,7 +1047,7 @@ class VersionInheritEnabledTestCase(tests.TestCase): # If the request is /v3 and the Accept header is application/json-home # then the server responds with a JSON Home document. - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) resp = client.get('/v3/', headers={'Accept': 'application/json-home'}) self.assertThat(resp.status, tt_matchers.Equals('200 OK')) @@ -1022,7 +1061,7 @@ class VersionInheritEnabledTestCase(tests.TestCase): tt_matchers.Equals(exp_json_home_data)) -class VersionBehindSslTestCase(tests.TestCase): +class VersionBehindSslTestCase(unit.TestCase): def setUp(self): super(VersionBehindSslTestCase, self).setUp() self.load_backends() @@ -1048,7 +1087,7 @@ class VersionBehindSslTestCase(tests.TestCase): return expected def test_versions_without_headers(self): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) host_name = 'host-%d' % random.randint(10, 30) host_port = random.randint(10000, 30000) host = 'http://%s:%s/' % (host_name, host_port) @@ -1059,7 +1098,7 @@ class VersionBehindSslTestCase(tests.TestCase): self.assertThat(data, _VersionsEqual(expected)) def test_versions_with_header(self): - client = tests.TestClient(self.public_app) + client = TestClient(self.public_app) host_name = 'host-%d' % random.randint(10, 30) host_port = random.randint(10000, 30000) resp = client.get('http://%s:%s/' % (host_name, host_port), |