summaryrefslogtreecommitdiff
path: root/openstack_auth/tests
diff options
context:
space:
mode:
authorIvan Kolodyazhny <e0ne@e0ne.info>2019-07-31 16:13:01 +0300
committerVishal Manchanda <manchandavishal143@gmail.com>2019-09-12 17:15:07 +0000
commitf33e5fd8acf4ee840d480e8cb26e3337e1190040 (patch)
tree65b61938a6362c93a15d50060602a1a20fedcb04 /openstack_auth/tests
parent7c897b677cc4e7eb11d90fce448160c2b90d1ef4 (diff)
downloadhorizon-f33e5fd8acf4ee840d480e8cb26e3337e1190040.tar.gz
Drop deprecated Keystone V2 API support
Keystone V2 API was deprecated in Stein release in Horizon and removed from Keystone in Queens release. Change-Id: I917e273d3174adf0874e516b3d635ccb8ba58a27
Diffstat (limited to 'openstack_auth/tests')
-rw-r--r--openstack_auth/tests/data_v2.py143
-rw-r--r--openstack_auth/tests/unit/test_auth.py330
-rw-r--r--openstack_auth/tests/unit/test_utils.py36
3 files changed, 0 insertions, 509 deletions
diff --git a/openstack_auth/tests/data_v2.py b/openstack_auth/tests/data_v2.py
deleted file mode 100644
index 1f3a914a2..000000000
--- a/openstack_auth/tests/data_v2.py
+++ /dev/null
@@ -1,143 +0,0 @@
-# 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 datetime
-import uuid
-
-from django.utils import datetime_safe
-from keystoneauth1.access import access
-from keystoneauth1.access import service_catalog
-from keystoneclient.v2_0 import roles
-from keystoneclient.v2_0 import tenants
-from keystoneclient.v2_0 import users
-
-
-class TestDataContainer(object):
- """Arbitrary holder for test data in an object-oriented fashion."""
- pass
-
-
-def generate_test_data():
- '''Builds a set of test_data data as returned by Keystone V2.'''
- test_data = TestDataContainer()
-
- keystone_service = {
- 'type': 'identity',
- 'name': 'keystone',
- 'endpoints_links': [],
- 'endpoints': [
- {
- 'region': 'RegionOne',
- 'adminURL': 'http://admin.localhost:35357/v2.0',
- 'internalURL': 'http://internal.localhost:5000/v2.0',
- 'publicURL': 'http://public.localhost:5000/v2.0'
- }
- ]
- }
-
- # Users
- user_dict = {'id': uuid.uuid4().hex,
- 'name': 'gabriel',
- 'email': 'gabriel@example.com',
- 'password': 'swordfish',
- 'token': '',
- 'enabled': True}
- test_data.user = users.User(None, user_dict, loaded=True)
-
- # Tenants
- tenant_dict_1 = {'id': uuid.uuid4().hex,
- 'name': 'tenant_one',
- 'description': '',
- 'enabled': True}
- tenant_dict_2 = {'id': uuid.uuid4().hex,
- 'name': 'tenant_two',
- 'description': '',
- 'enabled': False}
- test_data.tenant_one = tenants.Tenant(None, tenant_dict_1, loaded=True)
- test_data.tenant_two = tenants.Tenant(None, tenant_dict_2, loaded=True)
-
- nova_service = {
- 'type': 'compute',
- 'name': 'nova',
- 'endpoint_links': [],
- 'endpoints': [
- {
- 'region': 'RegionOne',
- 'adminURL': ('http://nova-admin.localhost:8774/v2.0/%s'
- % (tenant_dict_1['id'])),
- 'internalURL': ('http://nova-internal.localhost:8774/v2.0/%s'
- % (tenant_dict_1['id'])),
- 'publicURL': ('http://nova-public.localhost:8774/v2.0/%s'
- % (tenant_dict_1['id']))
- },
- {
- 'region': 'RegionTwo',
- 'adminURL': ('http://nova2-admin.localhost:8774/v2.0/%s'
- % (tenant_dict_1['id'])),
- 'internalURL': ('http://nova2-internal.localhost:8774/v2.0/%s'
- % (tenant_dict_1['id'])),
- 'publicURL': ('http://nova2-public.localhost:8774/v2.0/%s'
- % (tenant_dict_1['id']))
- }
- ]
- }
-
- # Roles
- role_dict = {'id': uuid.uuid4().hex,
- 'name': 'Member'}
- test_data.role = roles.Role(roles.RoleManager, role_dict)
-
- # Tokens
- tomorrow = datetime_safe.datetime.now() + datetime.timedelta(days=1)
- expiration = datetime_safe.datetime.isoformat(tomorrow)
-
- scoped_token_dict = {
- 'access': {
- 'token': {
- 'id': uuid.uuid4().hex,
- 'expires': expiration,
- 'tenant': tenant_dict_1,
- 'tenants': [tenant_dict_1, tenant_dict_2]},
- 'user': {
- 'id': user_dict['id'],
- 'name': user_dict['name'],
- 'roles': [role_dict]},
- 'serviceCatalog': [keystone_service, nova_service]
- }
- }
-
- test_data.scoped_access_info = access.create(
- resp=None,
- body=scoped_token_dict)
-
- unscoped_token_dict = {
- 'access': {
- 'token': {
- 'id': uuid.uuid4().hex,
- 'expires': expiration},
- 'user': {
- 'id': user_dict['id'],
- 'name': user_dict['name'],
- 'roles': [role_dict]},
- 'serviceCatalog': [keystone_service]
- }
- }
- test_data.unscoped_access_info = access.create(
- resp=None,
- body=unscoped_token_dict)
-
- # Service Catalog
- test_data.service_catalog = service_catalog.ServiceCatalogV2(
- [keystone_service, nova_service])
-
- return test_data
diff --git a/openstack_auth/tests/unit/test_auth.py b/openstack_auth/tests/unit/test_auth.py
index f5d2ce03b..386f3181b 100644
--- a/openstack_auth/tests/unit/test_auth.py
+++ b/openstack_auth/tests/unit/test_auth.py
@@ -19,16 +19,13 @@ from django import test
from django.test.utils import override_settings
from django.urls import reverse
from keystoneauth1 import exceptions as keystone_exceptions
-from keystoneauth1.identity import v2 as v2_auth
from keystoneauth1.identity import v3 as v3_auth
from keystoneauth1 import session
from keystoneauth1 import token_endpoint
-from keystoneclient.v2_0 import client as client_v2
from keystoneclient.v3 import client as client_v3
from mox3 import mox
from testscenarios import load_tests_apply_scenarios
-from openstack_auth.tests import data_v2
from openstack_auth.tests import data_v3
from openstack_auth import utils
@@ -143,333 +140,6 @@ class OpenStackAuthFederatedTestsMixin(object):
self._mock_unscoped_list_domains(client, domains)
-class OpenStackAuthTestsV2(OpenStackAuthTestsMixin, test.TestCase):
-
- def setUp(self):
- super(OpenStackAuthTestsV2, self).setUp()
-
- if getattr(self, 'interface', None):
- override = self.settings(OPENSTACK_ENDPOINT_TYPE=self.interface)
- override.enable()
- self.addCleanup(override.disable)
-
- self.mox = mox.Mox()
- self.addCleanup(self.mox.VerifyAll)
- self.addCleanup(self.mox.UnsetStubs)
-
- self.data = data_v2.generate_test_data()
- self.ks_client_module = client_v2
-
- settings.OPENSTACK_API_VERSIONS['identity'] = 2.0
- settings.OPENSTACK_KEYSTONE_URL = "http://localhost:5000/v2.0"
-
- self.mox.StubOutClassWithMocks(token_endpoint, 'Token')
- self.mox.StubOutClassWithMocks(v2_auth, 'Token')
- self.mox.StubOutClassWithMocks(v2_auth, 'Password')
- self.mox.StubOutClassWithMocks(client_v2, 'Client')
-
- def _mock_unscoped_list_tenants(self, client, tenants):
- client.tenants = self.mox.CreateMockAnything()
- client.tenants.list().AndReturn(tenants)
-
- def _mock_unscoped_client_list_tenants(self, user, tenants):
- client = self._mock_unscoped_client(user)
- self._mock_unscoped_list_tenants(client, tenants)
-
- def _create_password_auth(self, username=None, password=None, url=None):
- if not username:
- username = self.data.user.name
-
- if not password:
- password = self.data.user.password
-
- if not url:
- url = settings.OPENSTACK_KEYSTONE_URL
-
- return v2_auth.Password(auth_url=url,
- password=password,
- username=username)
-
- def _create_token_auth(self, project_id, token=None, url=None):
- if not token:
- token = self.data.unscoped_access_info.auth_token
-
- if not url:
- url = settings.OPENSTACK_KEYSTONE_URL
-
- return v2_auth.Token(auth_url=url,
- token=token,
- tenant_id=project_id,
- reauthenticate=False)
-
- def _login(self):
- tenants = [self.data.tenant_one, self.data.tenant_two]
- user = self.data.user
- unscoped = self.data.unscoped_access_info
-
- form_data = self.get_form_data(user)
- self._mock_unscoped_client_list_tenants(user, tenants)
- self._mock_scoped_client_for_tenant(unscoped, self.data.tenant_one.id)
-
- self.mox.ReplayAll()
-
- url = reverse('login')
-
- # GET the page to set the test cookie.
- response = self.client.get(url, form_data)
- self.assertEqual(response.status_code, 200)
-
- # POST to the page to log in.
- response = self.client.post(url, form_data)
- self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
-
- def test_login(self):
- self._login()
-
- def test_login_with_disabled_tenant(self):
- # Test to validate that authentication will not try to get
- # scoped token for disabled project.
- tenants = [self.data.tenant_two, self.data.tenant_one]
- user = self.data.user
- unscoped = self.data.unscoped_access_info
-
- form_data = self.get_form_data(user)
- self._mock_unscoped_client_list_tenants(user, tenants)
- self._mock_scoped_client_for_tenant(unscoped, self.data.tenant_one.id)
- self.mox.ReplayAll()
-
- url = reverse('login')
-
- # GET the page to set the test cookie.
- response = self.client.get(url, form_data)
- self.assertEqual(response.status_code, 200)
-
- # POST to the page to log in.
- response = self.client.post(url, form_data)
- self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
-
- def test_login_w_bad_region_cookie(self):
- self.client.cookies['services_region'] = "bad_region"
- self._login()
- self.assertNotEqual("bad_region",
- self.client.session['services_region'])
- self.assertEqual("RegionOne",
- self.client.session['services_region'])
-
- def test_no_enabled_tenants(self):
- tenants = [self.data.tenant_two]
- user = self.data.user
-
- form_data = self.get_form_data(user)
- self._mock_unscoped_client_list_tenants(user, tenants)
- self.mox.ReplayAll()
-
- url = reverse('login')
-
- # GET the page to set the test cookie.
- response = self.client.get(url, form_data)
- self.assertEqual(response.status_code, 200)
-
- # POST to the page to log in.
- response = self.client.post(url, form_data)
- self.assertTemplateUsed(response, 'auth/login.html')
- self.assertContains(response,
- 'You are not authorized for any projects.')
-
- def test_no_tenants(self):
- user = self.data.user
-
- form_data = self.get_form_data(user)
- self._mock_unscoped_client_list_tenants(user, [])
-
- self.mox.ReplayAll()
-
- url = reverse('login')
-
- # GET the page to set the test cookie.
- response = self.client.get(url, form_data)
- self.assertEqual(response.status_code, 200)
-
- # POST to the page to log in.
- response = self.client.post(url, form_data)
- self.assertTemplateUsed(response, 'auth/login.html')
- self.assertContains(response,
- 'You are not authorized for any projects.')
-
- def test_invalid_credentials(self):
- user = self.data.user
-
- form_data = self.get_form_data(user)
- form_data['password'] = "invalid"
-
- exc = keystone_exceptions.Unauthorized(401)
- self._mock_client_password_auth_failure(user.name, "invalid", exc)
-
- self.mox.ReplayAll()
-
- url = reverse('login')
-
- # GET the page to set the test cookie.
- response = self.client.get(url, form_data)
- self.assertEqual(response.status_code, 200)
-
- # POST to the page to log in.
- response = self.client.post(url, form_data)
- self.assertTemplateUsed(response, 'auth/login.html')
- self.assertContains(response, "Invalid credentials.")
-
- def test_exception(self):
- user = self.data.user
-
- form_data = self.get_form_data(user)
- exc = keystone_exceptions.ClientException(500)
- self._mock_client_password_auth_failure(user.name, user.password, exc)
- self.mox.ReplayAll()
-
- url = reverse('login')
-
- # GET the page to set the test cookie.
- response = self.client.get(url, form_data)
- self.assertEqual(response.status_code, 200)
-
- # POST to the page to log in.
- response = self.client.post(url, form_data)
-
- self.assertTemplateUsed(response, 'auth/login.html')
- self.assertContains(response,
- ("An error occurred authenticating. Please try "
- "again later."))
-
- def test_redirect_when_already_logged_in(self):
- self._login()
-
- response = self.client.get(reverse('login'))
- self.assertEqual(response.status_code, 302)
- self.assertNotIn(reverse('login'), response['location'])
-
- def test_dont_redirect_when_already_logged_in_if_next_is_set(self):
- self._login()
-
- expected_url = "%s?%s=/%s/" % (reverse('login'),
- auth.REDIRECT_FIELD_NAME,
- 'special')
-
- response = self.client.get(expected_url)
- self.assertEqual(response.status_code, 200)
- self.assertTemplateUsed(response, 'auth/login.html')
-
- def test_switch(self, next=None):
- tenant = self.data.tenant_two
- tenants = [self.data.tenant_one, self.data.tenant_two]
- user = self.data.user
- unscoped = self.data.unscoped_access_info
- scoped = self.data.scoped_access_info
- sc = self.data.service_catalog
- et = getattr(settings, 'OPENSTACK_ENDPOINT_TYPE', 'publicURL')
- endpoint = sc.url_for(service_type='identity', interface=et)
-
- form_data = self.get_form_data(user)
-
- self._mock_unscoped_client_list_tenants(user, tenants)
- self._mock_scoped_client_for_tenant(unscoped, self.data.tenant_one.id)
- self._mock_scoped_client_for_tenant(scoped, tenant.id, url=endpoint,
- client=False)
-
- self.mox.ReplayAll()
-
- url = reverse('login')
-
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
-
- response = self.client.post(url, form_data)
- self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
-
- url = reverse('switch_tenants', args=[tenant.id])
-
- scoped._token['tenant']['id'] = self.data.tenant_two.id
-
- if next:
- form_data.update({auth.REDIRECT_FIELD_NAME: next})
-
- response = self.client.get(url, form_data)
-
- if next:
- expected_url = next
- self.assertEqual(response['location'], expected_url)
- else:
- self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
-
- self.assertEqual(self.client.session['token'].tenant['id'],
- scoped.tenant_id)
-
- def test_switch_with_next(self):
- self.test_switch(next='/next_url')
-
- def test_switch_region(self, next=None):
- tenants = [self.data.tenant_one, self.data.tenant_two]
- user = self.data.user
- scoped = self.data.scoped_access_info
- sc = self.data.service_catalog
-
- form_data = self.get_form_data(user)
-
- self._mock_unscoped_client_list_tenants(user, tenants)
- self._mock_scoped_client_for_tenant(scoped, self.data.tenant_one.id)
-
- self.mox.ReplayAll()
-
- url = reverse('login')
-
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
-
- response = self.client.post(url, form_data)
- self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
-
- old_region = sc.get_endpoints()['compute'][0]['region']
- self.assertEqual(self.client.session['services_region'], old_region)
-
- region = sc.get_endpoints()['compute'][1]['region']
- url = reverse('switch_services_region', args=[region])
-
- form_data['region_name'] = region
-
- if next:
- form_data.update({auth.REDIRECT_FIELD_NAME: next})
-
- response = self.client.get(url, form_data)
-
- if next:
- expected_url = next
- self.assertEqual(response['location'], expected_url)
- else:
- self.assertRedirects(response, settings.LOGIN_REDIRECT_URL)
-
- self.assertEqual(self.client.session['services_region'], region)
- self.assertEqual(self.client.cookies['services_region'].value, region)
-
- def test_switch_region_with_next(self, next=None):
- self.test_switch_region(next='/next_url')
-
- def test_tenant_sorting(self):
- tenants = [self.data.tenant_two, self.data.tenant_one]
- expected_tenants = [self.data.tenant_one, self.data.tenant_two]
- user = self.data.user
- unscoped = self.data.unscoped_access_info
-
- client = self._mock_unscoped_client_with_token(user, unscoped)
- self._mock_unscoped_list_tenants(client, tenants)
-
- self.mox.ReplayAll()
-
- tenant_list = utils.get_project_list(
- user_id=user.id,
- auth_url=settings.OPENSTACK_KEYSTONE_URL,
- token=unscoped.auth_token)
- self.assertEqual(tenant_list, expected_tenants)
-
-
class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
OpenStackAuthFederatedTestsMixin,
test.TestCase):
diff --git a/openstack_auth/tests/unit/test_utils.py b/openstack_auth/tests/unit/test_utils.py
index 012476344..ab91fdd01 100644
--- a/openstack_auth/tests/unit/test_utils.py
+++ b/openstack_auth/tests/unit/test_utils.py
@@ -11,7 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from django.conf import settings
from django import http
from django import test
from django.test import client
@@ -55,41 +54,6 @@ class RoleTestCaseAdmin(test.TestCase):
class UtilsTestCase(test.TestCase):
- def test_fix_auth_url_version_v20(self):
- settings.OPENSTACK_API_VERSIONS['identity'] = 2.0
- test_urls = [
- ("http://a/", ("http://a/v2.0", False)),
- ("http://a", ("http://a/v2.0", False)),
- ("http://a:8080/", ("http://a:8080/v2.0", False)),
- ("http://a/v2.0", ("http://a/v2.0", False)),
- ("http://a/v2.0/", ("http://a/v2.0/", False)),
- ("http://a/identity", ("http://a/identity/v2.0", False)),
- ("http://a/identity/", ("http://a/identity/v2.0", False)),
- ("http://a:5000/identity/v2.0",
- ("http://a:5000/identity/v2.0", False)),
- ("http://a/identity/v2.0/", ("http://a/identity/v2.0/", False))
- ]
- for src, expected in test_urls:
- self.assertEqual(expected, utils.fix_auth_url_version_prefix(src))
-
- def test_fix_auth_url_version_v3(self):
- settings.OPENSTACK_API_VERSIONS['identity'] = 3
- test_urls = [
- ("http://a/", ("http://a/v3", False)),
- ("http://a", ("http://a/v3", False)),
- ("http://a:8080/", ("http://a:8080/v3", False)),
- ("http://a/v3", ("http://a/v3", False)),
- ("http://a/v3/", ("http://a/v3/", False)),
- ("http://a/v2.0/", ("http://a/v3/", True)),
- ("http://a/v2.0", ("http://a/v3", True)),
- ("http://a/identity", ("http://a/identity/v3", False)),
- ("http://a:5000/identity/", ("http://a:5000/identity/v3", False)),
- ("http://a/identity/v3", ("http://a/identity/v3", False)),
- ("http://a/identity/v3/", ("http://a/identity/v3/", False))
- ]
- for src, expected in test_urls:
- self.assertEqual(expected, utils.fix_auth_url_version_prefix(src))
-
@override_settings(DEFAULT_SERVICE_REGIONS={
'http://example.com': 'RegionThree', '*': 'RegionFour'})
def test_default_services_region_precedence(self):