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