Debian Codegraph @

dojox/form/tests/test_PasswordValidator.html

raw symbols SCIP
1 <html>
2 <head>
3 <script type="text/javascript"
4 src="../../../dojo/dojo.js"
5 data-dojo-config="isDebug: true, parseOnLoad: true">
6 </script>
7 <script type="text/javascript">
8 dojo.require("doh.runner");
9 dojo.require("dojo.parser");
10 dojo.require("dojox.form.PasswordValidator");
11 dojo.require("dijit.form.Button");
12 dojo.require("dijit.form.Form");
13
14 dojo.addOnLoad(function(){
15 doh.register("tests",
16 [
17 function test_setDisabled(t){
18 valid1.set("disabled", true);
19 t.t(dojo.every(
20 dojo.query("[widgetId]", valid1.domNode)
21 .map(function(i){
22 return dijit.byNode(i);
23 }),
24 function(i){
25 return i.disabled;
26 }
27 ), "disabled");
28 valid1.set("disabled", false);
29 t.t(dojo.every(
30 dojo.query("[widgetId]", valid1.domNode)
31 .map(function(i){
32 return dijit.byNode(i);
33 }),
34 function(i){
35 return !i.disabled;
36 }
37 ), "enabled");
38 },
39 function test_isValid(t){
40 t.f(form1.isValid(), "form invalid");
41 dijit.byId("nv1").set("value", "test");
42 dijit.byId("vv1").set("value", "Test");
43 t.f(form1.isValid(), "isValid() 1");
44 dijit.byId("vv1").set("value", "test");
45 t.t(form1.isValid(), "isValid() 2");
46 t.t(form6.isValid(), "isValid() 3");
47 t.is({password: ""}, form6.get("value"), '{password: ""}');
48 dijit.byId("nv6").set("value", "test");
49 t.f(form6.isValid(), "isValid() 4");
50 t.is({password: ""}, form6.get("value"), '{password: ""}');
51 dijit.byId("vv6").set("value", "test");
52 t.t(form6.isValid(), "isValid() 5");
53 t.is({password: "test"}, form6.get("value"), '{password: "test"}');
54 },
55 function test_getValue(t){
56 dijit.byId("nv1").set("value", "test");
57 dijit.byId("vv1").set("value", "Test");
58 t.is({password: ""}, form1.get("value"), '{password: ""}');
59 dijit.byId("vv1").set("value", "test123");
60 dijit.byId("nv1").set("value", "test123");
61 t.is({password: "test123"}, form1.get("value"), '{password: "test123"}');
62 },
63 function test_oldPW(t){
64 dijit.byId("nv2").set("value", "test");
65 dijit.byId("vv2").set("value", "test");
66 t.f(form2.isValid(), "isValid() 1");
67 dijit.byId("ov2").set("value", "oldpw4");
68 t.f(form2.isValid(), "isValid() 2");
69 dijit.byId("ov2").set("value", "oldpw2");
70 t.t(form2.isValid(), "isValid() 3");
71 },
72 function test_getOldValue(t){
73 t.is({password: "test"}, form2.get("value"), '{password: "test"}');
74 dijit.byId("nv3").set("value", "test");
75 dijit.byId("vv3").set("value", "test");
76 dijit.byId("ov3").set("value", "oldpw4");
77 t.is({password: "", oldPassword: ""}, form3.get("value"), '{password: "", oldPassword: ""}');
78 dijit.byId("ov3").set("value", "oldpw3");
79 dijit.byId("vv3").set("value", "Test");
80 t.is({password: "", oldPassword: ""}, form3.get("value"), '{password: "", oldPassword: ""}');
81 dijit.byId("vv3").set("value", "test");
82 t.is({password: "test", oldPassword: "oldpw3"}, form3.get("value"),
83 '{password: "test", oldPassword: "oldpw3"}');
84 },
85 function test_getValuesInTable(t){
86 dijit.byId("nv4").set("value", "test");
87 dijit.byId("vv4").set("value", "test");
88 dijit.byId("ov4").set("value", "oldpw4");
89 t.is({password: "test"}, form4.get("value"), '{password: "test"}');
90 dijit.byId("nv5").set("value", "test");
91 dijit.byId("vv5").set("value", "test");
92 dijit.byId("ov5").set("value", "oldpw5");
93 t.is({password: "test", oldPassword: "oldpw5"}, form5.get("value"),
94 '{password: "test", oldPassword: "oldpw5"}');
95 }
96 ]
97 );
98 doh.run();
99 });
100 </script>
101 <link rel="stylesheet" type="text/css" href="../../../dijit/themes/tundra/tundra.css">
102 <link rel="stylesheet" type="text/css" href="../../../dijit/tests/css/dijitTests.css">
103 </head>
104 <body class="tundra">
105 <h1 class="testTitle">Test: dojox.form.PasswordValidator</h1>
106 <h2>Automated test</h2>
107 <h4 class="testSubtitle">No old password</h4>
108 <form dojoType="dijit.form.Form" data-dojo-id="form1" action="" method="GET">
109 <div dojoType="dojox.form.PasswordValidator" data-dojo-id="valid1" name="password">
110 <label>Password: <input type="password" id="nv1" pwType="new" /></label><br>
111 <label>Validate: <input type="password" id="vv1" pwType="verify" /></label><br>
112 </div>
113 </form>
114 <hr>
115 <h4 class="testSubtitle">Old password (hard-coded to "oldpw2") - not passed to getValues</h4>
116 <form dojoType="dijit.form.Form" data-dojo-id="form2" action="" method="GET">
117 <div dojoType="dojox.form.PasswordValidator" data-dojo-id="valid2" name="password">
118 <script type="dojo/method" data-dojo-event="pwCheck" data-dojo-args="password">
119 /*
120 NOTE: Do NOT EVER EVER EVER do this sort of a check!!!
121
122 This is only as an example. You will probably want to
123 override the pwCheck function to callback to a server to
124 verify the password (the callback will need to be
125 syncronous) - and it's probably a good idea to validate
126 it again on form submission before actually doing
127 anything destructive - that's why the "oldName" value
128 is there.
129
130 And don't just fetch the password from the server
131 either :) Send the test password (probably hashed, for
132 security) and return from the server a status instead.
133
134 Again - DON'T DO THIS - it is HORRIBLY INSECURE!!!!
135
136 Security is left as an exercise to the reader :)
137 */
138 return password === "oldpw2";
139 </script>
140 <label>Old Password: <input type="password" id="ov2" pwType="old" /></label><br>
141 <label>Password: <input type="password" id="nv2" pwType="new" /></label><br>
142 <label>Validate: <input type="password" id="vv2" pwType="verify" /></label><br>
143 </div>
144 </form>
145 <hr>
146 <h4 class="testSubtitle">Old password (hard-coded to "oldpw3") - passed to getValues</h4>
147 <form dojoType="dijit.form.Form" data-dojo-id="form3" action="" method="GET">
148 <div dojoType="dojox.form.PasswordValidator" data-dojo-id="valid3" name="password" oldName="oldPassword">
149 <script type="dojo/method" data-dojo-event="pwCheck" data-dojo-args="password">
150 console.log("Checking " + password);
151 return password === "oldpw3";
152 </script>
153 <label>Old Password: <input type="password" id="ov3" pwType="old" /></label><br>
154 <label>Password: <input type="password" id="nv3" pwType="new" /></label><br>
155 <label>Validate: <input type="password" id="vv3" pwType="verify" /></label><br>
156 </div>
157 </form>
158 <hr>
159 <h4 class="testSubtitle">In Table, Old password (hard-coded to "oldpw4") - not passed to getValues</h4>
160 <form dojoType="dijit.form.Form" data-dojo-id="form4">
161 <div dojoType="dojox.form.PasswordValidator" data-dojo-id="valid4" name="password">
162 <script type="dojo/method" data-dojo-event="pwCheck" data-dojo-args="password">
163 return password === "oldpw4";
164 </script>
165 <table>
166 <tr>
167 <td><label for="ov4">Old Password:</label></td>
168 <td><input type="password" id="ov4" pwType="old" /></td>
169 </tr>
170 <tr>
171 <td><label for="nv4">Password:</label></td>
172 <td><input type="password" id="nv4" pwType="new" /></td>
173 </tr>
174 <tr>
175 <td><label for="vv4">Validate:</label></td>
176 <td><input type="password" id="vv4" pwType="verify" /></td>
177 </tr>
178 </table>
179 </div>
180 </form>
181 <hr>
182 <h4 class="testSubtitle">In Table, Old password (hard-coded to "oldpw5") - passed to getValues</h4>
183 <form dojoType="dijit.form.Form" data-dojo-id="form5">
184 <div dojoType="dojox.form.PasswordValidator" data-dojo-id="valid5" name="password" oldName="oldPassword">
185 <script type="dojo/method" data-dojo-event="pwCheck" data-dojo-args="password">
186 return password === "oldpw5";
187 </script>
188 <table>
189 <tr>
190 <td><label for="ov5">Old Password:</label></td>
191 <td><input type="password" id="ov5" pwType="old" /></td>
192 </tr>
193 <tr>
194 <td><label for="nv5">Password:</label></td>
195 <td><input type="password" id="nv5" pwType="new" /></td>
196 </tr>
197 <tr>
198 <td><label for="vv5">Validate:</label></td>
199 <td><input type="password" id="vv5" pwType="verify" /></td>
200 </tr>
201 </table>
202 </div>
203 </form>
204 <hr>
205 <h4 class="testSubtitle">No old password, not required</h4>
206 <form dojoType="dijit.form.Form" data-dojo-id="form6">
207 <div dojoType="dojox.form.PasswordValidator" required="false" data-dojo-id="valid6" name="password">
208 <label>Password: <input type="password" id="nv6" pwType="new" /></label><br>
209 <label>Validate: <input type="password" id="vv6" pwType="verify" /></label><br>
210 </div>
211 </form>
212 <hr>
213 <button dojoType="dijit.form.Button">
214 <script type="dojo/method" data-dojo-event="onClick">
215 dojo.forEach([form1, form2, form3, form4, form5, form6], function(i){
216 console.dir(i.get("value"));
217 });
218 </script>
219 Get Values
220 </button>
221 <button dojoType="dijit.form.Button">
222 <script type="dojo/method" data-dojo-event="onClick">
223 valid5.set("disabled", !valid5.disabled);
224 </script>
225 Toggle Disabled
226 </button>
227 <button dojoType="dijit.form.Button">
228 <script type="dojo/method" data-dojo-event="onClick">
229 form1.submit();
230 </script>
231 Submit Form 1
232 </button>
233 <button dojoType="dijit.form.Button">
234 <script type="dojo/method" data-dojo-event="onClick">
235 form2.submit();
236 </script>
237 Submit Form 2
238 </button>
239 <button dojoType="dijit.form.Button">
240 <script type="dojo/method" data-dojo-event="onClick">
241 form3.submit();
242 </script>
243 Submit Form 3
244 </button>
245
246 </body>
247 </html>