summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-07-03 21:01:15 +0000
committerGerrit Code Review <review@openstack.org>2017-07-03 21:01:15 +0000
commita1e421e0b782e4eaea7815033b04f8512cc44e42 (patch)
treeb67bfc34bb205988cf53f79b03f713049d9af65b
parent011c2274a00f8b0d7313aa06843753e28326d47e (diff)
parent35a2fb35a712633a88850211de11d78e7f39c343 (diff)
Merge "Add support for a domain dropdown menu at login"
-rw-r--r--openstack_auth/forms.py21
-rw-r--r--openstack_auth/tests/tests.py26
2 files changed, 42 insertions, 5 deletions
diff --git a/openstack_auth/forms.py b/openstack_auth/forms.py
index 0acb290..bacc9c0 100644
--- a/openstack_auth/forms.py
+++ b/openstack_auth/forms.py
@@ -61,11 +61,22 @@ class Login(django_auth_forms.AuthenticationForm):
61 'OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT', 61 'OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT',
62 False): 62 False):
63 last_domain = self.request.COOKIES.get('login_domain', None) 63 last_domain = self.request.COOKIES.get('login_domain', None)
64 self.fields['domain'] = forms.CharField( 64 if getattr(settings,
65 initial=last_domain, 65 'OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN',
66 label=_("Domain"), 66 False):
67 required=True, 67 self.fields['domain'] = forms.ChoiceField(
68 widget=forms.TextInput(attrs={"autofocus": "autofocus"})) 68 label=_("Domain"),
69 initial=last_domain,
70 required=True,
71 choices=getattr(settings,
72 'OPENSTACK_KEYSTONE_DOMAIN_CHOICES',
73 ()))
74 else:
75 self.fields['domain'] = forms.CharField(
76 initial=last_domain,
77 label=_("Domain"),
78 required=True,
79 widget=forms.TextInput(attrs={"autofocus": "autofocus"}))
69 self.fields['username'].widget = forms.widgets.TextInput() 80 self.fields['username'].widget = forms.widgets.TextInput()
70 fields_ordering = ['domain', 'username', 'password', 'region'] 81 fields_ordering = ['domain', 'username', 'password', 'region']
71 self.fields['region'].choices = self.get_region_choices() 82 self.fields['region'].choices = self.get_region_choices()
diff --git a/openstack_auth/tests/tests.py b/openstack_auth/tests/tests.py
index 4790f73..80e5a88 100644
--- a/openstack_auth/tests/tests.py
+++ b/openstack_auth/tests/tests.py
@@ -1091,6 +1091,32 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
1091 token=unscoped.auth_token) 1091 token=unscoped.auth_token)
1092 self.assertEqual(project_list, expected_projects) 1092 self.assertEqual(project_list, expected_projects)
1093 1093
1094 def test_login_form_multidomain(self):
1095 override = self.settings(OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT=True)
1096 override.enable()
1097 self.addCleanup(override.disable)
1098
1099 url = reverse('login')
1100 response = self.client.get(url)
1101 self.assertEqual(response.status_code, 200)
1102 self.assertContains(response, 'name="domain" type="text"')
1103
1104 def test_login_form_multidomain_dropdown(self):
1105 override = self.settings(OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT=True,
1106 OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN=True,
1107 OPENSTACK_KEYSTONE_DOMAIN_CHOICES=(
1108 ('Default', 'Default'),)
1109 )
1110 override.enable()
1111 self.addCleanup(override.disable)
1112
1113 url = reverse('login')
1114 response = self.client.get(url)
1115 self.assertEqual(response.status_code, 200)
1116 self.assertContains(response, 'select id="id_domain" name="domain"')
1117 self.assertContains(response, 'option value="Default"')
1118 settings.OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN = False
1119
1094 1120
1095class OpenStackAuthTestsWebSSO(OpenStackAuthTestsMixin, 1121class OpenStackAuthTestsWebSSO(OpenStackAuthTestsMixin,
1096 OpenStackAuthFederatedTestsMixin, 1122 OpenStackAuthFederatedTestsMixin,