Browse Source

Merge "Render hidden stack parameters with a password field"

Jenkins 4 years ago
parent
commit
8a83578bcc

+ 4
- 0
openstack_dashboard/dashboards/project/stacks/forms.py View File

@@ -23,6 +23,7 @@ from horizon import forms
23 23
 from horizon import messages
24 24
 
25 25
 from openstack_dashboard import api
26
+from openstack_dashboard.openstack.common import strutils
26 27
 
27 28
 LOG = logging.getLogger(__name__)
28 29
 
@@ -294,6 +295,7 @@ class CreateStackForm(forms.SelfHandlingForm):
294 295
             }
295 296
 
296 297
             param_type = param.get('Type', None)
298
+            hidden = strutils.bool_from_string(param.get('NoEcho', 'false'))
297 299
 
298 300
             if 'AllowedValues' in param:
299 301
                 choices = map(lambda x: (x, x), param['AllowedValues'])
@@ -306,6 +308,8 @@ class CreateStackForm(forms.SelfHandlingForm):
306 308
                     field_args['required'] = param.get('MinLength', 0) > 0
307 309
                 if 'MaxLength' in param:
308 310
                     field_args['max_length'] = int(param['MaxLength'])
311
+                if hidden:
312
+                    field_args['widget'] = forms.PasswordInput()
309 313
                 field = forms.CharField(**field_args)
310 314
 
311 315
             elif param_type == 'Number':

+ 54
- 0
openstack_dashboard/dashboards/project/stacks/tests.py View File

@@ -315,6 +315,60 @@ class StackTests(test.TestCase):
315 315
         res = self.client.post(url, form_data)
316 316
         self.assertRedirectsNoFollow(res, INDEX_URL)
317 317
 
318
+    @test.create_stubs({api.heat: ('template_validate',)})
319
+    def test_launch_stack_with_hidden_parameters(self):
320
+        template = {
321
+            'data': ('heat_template_version: 2013-05-23\n'
322
+                     'parameters:\n'
323
+                     '  public_string:\n'
324
+                     '    type: string\n'
325
+                     '  secret_string:\n'
326
+                     '    type: string\n'
327
+                     '    hidden: true\n'),
328
+            'validate': {
329
+                'Description': 'No description',
330
+                'Parameters': {
331
+                    'public_string': {
332
+                        'Label': 'public_string',
333
+                        'Description': '',
334
+                        'Type': 'String',
335
+                        'NoEcho': 'false'
336
+                    },
337
+                    'secret_string': {
338
+                        'Label': 'secret_string',
339
+                        'Description': '',
340
+                        'Type': 'String',
341
+                        'NoEcho': 'true'
342
+                    }
343
+                }
344
+            }
345
+        }
346
+        api.heat.template_validate(IsA(http.HttpRequest),
347
+                                   template=template['data']) \
348
+           .AndReturn(template['validate'])
349
+
350
+        self.mox.ReplayAll()
351
+
352
+        url = reverse('horizon:project:stacks:select_template')
353
+        res = self.client.get(url)
354
+        self.assertTemplateUsed(res, 'project/stacks/select_template.html')
355
+
356
+        form_data = {'template_source': 'raw',
357
+                     'template_data': template['data'],
358
+                     'method': forms.TemplateForm.__name__}
359
+        res = self.client.post(url, form_data)
360
+        self.assertTemplateUsed(res, 'project/stacks/create.html')
361
+
362
+        # ensure the fields were rendered correctly
363
+        self.assertContains(res, '<input class=" form-control" '
364
+                                        'id="id___param_public_string" '
365
+                                        'name="__param_public_string" '
366
+                                        'type="text" />', html=True)
367
+        self.assertContains(res, '<input class=" form-control" '
368
+                                        'id="id___param_secret_string" '
369
+                                        'name="__param_secret_string" '
370
+                                        'type="password" />', html=True)
371
+
318 372
     @test.create_stubs({api.heat: ('stack_update', 'stack_get',
319 373
                                     'template_get', 'template_validate')})
320 374
     def test_edit_stack_template(self):

Loading…
Cancel
Save