From 612ab2bceac496254bf9327d72db968de519567e Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 2 Sep 2014 17:46:36 +0000 Subject: [PATCH] Render hidden stack parameters with a password field In the launch stack form, any heat template parameters that are of type string and marked as hidden are now rendered as a password field. Change-Id: Ie9b0a051a8815525c89de31b7ab98d8148166a55 Closes-Bug: 1362846 --- .../dashboards/project/stacks/forms.py | 4 ++ .../dashboards/project/stacks/tests.py | 54 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/openstack_dashboard/dashboards/project/stacks/forms.py b/openstack_dashboard/dashboards/project/stacks/forms.py index b14b937391..8047313384 100644 --- a/openstack_dashboard/dashboards/project/stacks/forms.py +++ b/openstack_dashboard/dashboards/project/stacks/forms.py @@ -23,6 +23,7 @@ from horizon import forms from horizon import messages from openstack_dashboard import api +from openstack_dashboard.openstack.common import strutils LOG = logging.getLogger(__name__) @@ -296,6 +297,7 @@ class CreateStackForm(forms.SelfHandlingForm): } param_type = param.get('Type', None) + hidden = strutils.bool_from_string(param.get('NoEcho', 'false')) if 'AllowedValues' in param: choices = map(lambda x: (x, x), param['AllowedValues']) @@ -308,6 +310,8 @@ class CreateStackForm(forms.SelfHandlingForm): field_args['required'] = param.get('MinLength', 0) > 0 if 'MaxLength' in param: field_args['max_length'] = int(param['MaxLength']) + if hidden: + field_args['widget'] = forms.PasswordInput() field = forms.CharField(**field_args) elif param_type == 'Number': diff --git a/openstack_dashboard/dashboards/project/stacks/tests.py b/openstack_dashboard/dashboards/project/stacks/tests.py index b36ac48fda..49f7703640 100644 --- a/openstack_dashboard/dashboards/project/stacks/tests.py +++ b/openstack_dashboard/dashboards/project/stacks/tests.py @@ -315,6 +315,60 @@ class StackTests(test.TestCase): res = self.client.post(url, form_data) self.assertRedirectsNoFollow(res, INDEX_URL) + @test.create_stubs({api.heat: ('template_validate',)}) + def test_launch_stack_with_hidden_parameters(self): + template = { + 'data': ('heat_template_version: 2013-05-23\n' + 'parameters:\n' + ' public_string:\n' + ' type: string\n' + ' secret_string:\n' + ' type: string\n' + ' hidden: true\n'), + 'validate': { + 'Description': 'No description', + 'Parameters': { + 'public_string': { + 'Label': 'public_string', + 'Description': '', + 'Type': 'String', + 'NoEcho': 'false' + }, + 'secret_string': { + 'Label': 'secret_string', + 'Description': '', + 'Type': 'String', + 'NoEcho': 'true' + } + } + } + } + api.heat.template_validate(IsA(http.HttpRequest), + template=template['data']) \ + .AndReturn(template['validate']) + + self.mox.ReplayAll() + + url = reverse('horizon:project:stacks:select_template') + res = self.client.get(url) + self.assertTemplateUsed(res, 'project/stacks/select_template.html') + + form_data = {'template_source': 'raw', + 'template_data': template['data'], + 'method': forms.TemplateForm.__name__} + res = self.client.post(url, form_data) + self.assertTemplateUsed(res, 'project/stacks/create.html') + + # ensure the fields were rendered correctly + self.assertContains(res, '', html=True) + self.assertContains(res, '', html=True) + @test.create_stubs({api.heat: ('stack_update', 'stack_get', 'template_get', 'template_validate')}) def test_edit_stack_template(self):