Merge lp:~newell-jensen/maas/fix-1676882 into lp:~maas-committers/maas/trunk

Proposed by Newell Jensen
Status: Merged
Approved by: Newell Jensen
Approved revision: no longer in the source branch.
Merged at revision: 5978
Proposed branch: lp:~newell-jensen/maas/fix-1676882
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 129 lines (+84/-6)
3 files modified
src/maasserver/static/js/angular/directives/maas_obj_form.js (+8/-2)
src/maasserver/static/js/angular/directives/pod_parameters.js (+9/-4)
src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js (+67/-0)
To merge this branch: bzr merge lp:~newell-jensen/maas/fix-1676882
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+322558@code.launchpad.net

Commit message

Changes Pod passwords from cleartext to hidden characters.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/static/js/angular/directives/maas_obj_form.js'
2--- src/maasserver/static/js/angular/directives/maas_obj_form.js 2017-04-10 22:07:32 +0000
3+++ src/maasserver/static/js/angular/directives/maas_obj_form.js 2017-04-13 21:46:31 +0000
4@@ -608,7 +608,8 @@
5 // Render the input based on the type.
6 var placeholder = attrs.placeholder || label;
7 var inputElement = null;
8- if(attrs.type === "text" || attrs.type === "textarea") {
9+ if(attrs.type === "text" || attrs.type === "textarea" ||
10+ attrs.type === "password") {
11 if(attrs.type === "text") {
12 inputElement = $compile(
13 '<input type="text" id="' + attrs.key +
14@@ -619,7 +620,12 @@
15 '<textarea id="' + attrs.key +
16 '" placeholder="' + placeholder + '"' +
17 'data-ng-disabled="ngDisabled()">' +
18- '</textarea>')(scope);
19+ '</textarea>')(scope);
20+ } else if(attrs.type === "password") {
21+ inputElement = $compile(
22+ '<input type="password" id="' + attrs.key +
23+ '" placeholder="' + placeholder + '"' +
24+ 'data-ng-disabled="ngDisabled()">')(scope);
25 }
26
27 // Allow enter on blur, by default.
28
29=== modified file 'src/maasserver/static/js/angular/directives/pod_parameters.js'
30--- src/maasserver/static/js/angular/directives/pod_parameters.js 2017-03-29 19:08:16 +0000
31+++ src/maasserver/static/js/angular/directives/pod_parameters.js 2017-04-13 21:46:31 +0000
32@@ -56,10 +56,15 @@
33 var html = '<maas-obj-field-group>';
34 angular.forEach(type.fields, function(field) {
35 if(field.scope === 'bmc') {
36- html += (
37- '<maas-obj-field type="text" key="' + field.name +
38- '" label="' + field.label + '" ' +
39- 'label-width="two" input-width="three">' +
40+ if(field.name === 'power_pass') {
41+ html += (
42+ '<maas-obj-field type="password" key="');
43+ } else {
44+ html += (
45+ '<maas-obj-field type="text" key="');
46+ }
47+ html += (field.name + '" label="' + field.label +
48+ '" ' + 'label-width="two" input-width="three">' +
49 '</maas-obj-field>');
50 }
51 });
52
53=== modified file 'src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js'
54--- src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js 2017-03-29 15:40:39 +0000
55+++ src/maasserver/static/js/angular/directives/tests/test_maas_obj_form.js 2017-04-13 21:46:31 +0000
56@@ -184,6 +184,73 @@
57 });
58 });
59
60+ describe("input type=password", function() {
61+
62+ var directive;
63+ beforeEach(function() {
64+ $scope.obj = {};
65+ $scope.manager = {
66+ updateItem: jasmine.createSpy().and.returnValue(
67+ $q.defer().promise)
68+ };
69+ var html = [
70+ '<maas-obj-form obj="obj" manager="manager">',
71+ '<maas-obj-field type="password" key="key" label="Key" ',
72+ 'placeholder="Placeholder" label-width="two" ',
73+ 'input-width="three"></maas-obj-field>',
74+ '</maas-obj-form>'
75+ ].join('');
76+ directive = compileDirective(html);
77+ });
78+
79+ it("creates input with type 'password'", function() {
80+ var inputField = angular.element(directive.find("#key"));
81+ expect(inputField.prop("nodeName")).toBe("INPUT");
82+ expect(inputField.attr("type")).toBe("password");
83+ });
84+
85+ it("sets placeholder", function() {
86+ var inputField = angular.element(directive.find("#key"));
87+ expect(inputField.attr("placeholder")).toBe("Placeholder");
88+ });
89+
90+ it("adds label with width", function() {
91+ var labelField = angular.element(directive.find("label"));
92+ expect(labelField.text()).toBe("Key");
93+ expect(labelField.hasClass("two-col")).toBe(true);
94+ });
95+
96+ it("adds inputWrapper with width", function() {
97+ var labelField = angular.element(directive.find("label "));
98+ var inputWrapper = angular.element(labelField.next("div"));
99+ expect(inputWrapper.hasClass("three-col")).toBe(true);
100+ expect(inputWrapper.hasClass("last-col")).toBe(true);
101+ });
102+
103+ it("reverts value on esc", function() {
104+ var inputField = angular.element(directive.find("#key"));
105+ inputField.triggerHandler("focus");
106+ inputField.val(makeName("newValue"));
107+
108+ // Send esc.
109+ var evt = angular.element.Event("keydown");
110+ evt.which = 27;
111+ inputField.trigger(evt);
112+
113+ expect(inputField.val()).toBe("");
114+ });
115+
116+ it("sets $maasForm on obj", function() {
117+ expect($scope.obj.$maasForm).toBeDefined();
118+ });
119+
120+ it("hasErrors returns true if has-error class exists", function() {
121+ var inputField = angular.element(directive.find("#key"));
122+ inputField.addClass('has-error');
123+ expect($scope.obj.$maasForm.hasErrors()).toBe(true);
124+ });
125+ });
126+
127 describe("select", function() {
128
129 var directive, options;