Files
openlayers/master/examples/test_PasswordValidator.html
Éric Lemoine 5d14b9e2d4 Updated
2013-02-20 10:38:25 +01:00

248 lines
9.7 KiB
HTML

<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.set("disabled", true);
t.t(dojo.every(
dojo.query("[widgetId]", valid1.domNode)
.map(function(i){
return dijit.byNode(i);
}),
function(i){
return i.disabled;
}
), "disabled");
valid1.set("disabled", false);
t.t(dojo.every(
dojo.query("[widgetId]", valid1.domNode)
.map(function(i){
return dijit.byNode(i);
}),
function(i){
return !i.disabled;
}
), "enabled");
},
function test_isValid(t){
t.f(form1.isValid(), "form invalid");
dijit.byId("nv1").set("value", "test");
dijit.byId("vv1").set("value", "Test");
t.f(form1.isValid(), "isValid() 1");
dijit.byId("vv1").set("value", "test");
t.t(form1.isValid(), "isValid() 2");
t.t(form6.isValid(), "isValid() 3");
t.is({password: ""}, form6.get("value"), '{password: ""}');
dijit.byId("nv6").set("value", "test");
t.f(form6.isValid(), "isValid() 4");
t.is({password: ""}, form6.get("value"), '{password: ""}');
dijit.byId("vv6").set("value", "test");
t.t(form6.isValid(), "isValid() 5");
t.is({password: "test"}, form6.get("value"), '{password: "test"}');
},
function test_getValue(t){
dijit.byId("nv1").set("value", "test");
dijit.byId("vv1").set("value", "Test");
t.is({password: ""}, form1.get("value"), '{password: ""}');
dijit.byId("vv1").set("value", "test123");
dijit.byId("nv1").set("value", "test123");
t.is({password: "test123"}, form1.get("value"), '{password: "test123"}');
},
function test_oldPW(t){
dijit.byId("nv2").set("value", "test");
dijit.byId("vv2").set("value", "test");
t.f(form2.isValid(), "isValid() 1");
dijit.byId("ov2").set("value", "oldpw4");
t.f(form2.isValid(), "isValid() 2");
dijit.byId("ov2").set("value", "oldpw2");
t.t(form2.isValid(), "isValid() 3");
},
function test_getOldValue(t){
t.is({password: "test"}, form2.get("value"), '{password: "test"}');
dijit.byId("nv3").set("value", "test");
dijit.byId("vv3").set("value", "test");
dijit.byId("ov3").set("value", "oldpw4");
t.is({password: "", oldPassword: ""}, form3.get("value"), '{password: "", oldPassword: ""}');
dijit.byId("ov3").set("value", "oldpw3");
dijit.byId("vv3").set("value", "Test");
t.is({password: "", oldPassword: ""}, form3.get("value"), '{password: "", oldPassword: ""}');
dijit.byId("vv3").set("value", "test");
t.is({password: "test", oldPassword: "oldpw3"}, form3.get("value"),
'{password: "test", oldPassword: "oldpw3"}');
},
function test_getValuesInTable(t){
dijit.byId("nv4").set("value", "test");
dijit.byId("vv4").set("value", "test");
dijit.byId("ov4").set("value", "oldpw4");
t.is({password: "test"}, form4.get("value"), '{password: "test"}');
dijit.byId("nv5").set("value", "test");
dijit.byId("vv5").set("value", "test");
dijit.byId("ov5").set("value", "oldpw5");
t.is({password: "test", oldPassword: "oldpw5"}, form5.get("value"),
'{password: "test", oldPassword: "oldpw5"}');
}
]
);
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" action="" method="GET">
<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" action="" method="GET">
<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" action="" method="GET">
<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.get("value"));
});
</script>
Get Values
</button>
<button dojoType="dijit.form.Button">
<script type="dojo/method" event="onClick">
valid5.set("disabled", !valid5.disabled);
</script>
Toggle Disabled
</button>
<button dojoType="dijit.form.Button">
<script type="dojo/method" event="onClick">
form1.submit();
</script>
Submit Form 1
</button>
<button dojoType="dijit.form.Button">
<script type="dojo/method" event="onClick">
form2.submit();
</script>
Submit Form 2
</button>
<button dojoType="dijit.form.Button">
<script type="dojo/method" event="onClick">
form3.submit();
</script>
Submit Form 3
</button>
</body>
</html>