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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test promptAuth prompts</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<script type="text/javascript" src="../../../prompts/test/prompt_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
const level = Ci.nsIAuthPrompt2.LEVEL_NONE;
const authinfo = {
username: "",
password: "",
domain: "",
flags: Ci.nsIAuthInformation.AUTH_HOST,
authenticationScheme: "basic",
realm: "",
};
// Let prompt_common know what kind of modal type is used for auth prompts.
modalType = Ci.nsIPrompt.MODAL_TYPE_TAB;
const prompterParent = runInParent(() => {
const promptFac = Cc["@mozilla.org/passwordmanager/authpromptfactory;1"].
getService(Ci.nsIPromptFactory);
const chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
const prompter2 = promptFac.getPrompt(chromeWin, Ci.nsIAuthPrompt2);
prompter2.QueryInterface(Ci.nsILoginManagerAuthPrompter).browser = chromeWin.gBrowser.selectedBrowser;
const channels = {};
channels.channel1 = Services.io.newChannel("http://example.com",
null,
null,
null, // aLoadingNode
Services.
scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
Ci.nsIContentPolicy.TYPE_OTHER);
channels.channel2 = Services.io.newChannel("http://example2.com",
null,
null,
null, // aLoadingNode
Services.
scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
Ci.nsIContentPolicy.TYPE_OTHER);
addMessageListener("proxyPrompter", function onMessage(msg) {
const args = [...msg.args];
const channelName = args.shift();
// Replace the channel name string (arg. 0) with the channel by that name.
args.unshift(channels[channelName]);
const rv = prompter2[msg.methodName](...args);
return {
rv,
// Send the args back to content so out/inout args can be checked.
args: msg.args,
};
});
});
const prompter2 = new PrompterProxy(prompterParent);
add_setup(async () => {
await setStoredLoginsAsync(
["http://example.com", null, "http://example.com", "", "examplepass", "", ""],
["http://example2.com", null, "http://example2.com", "user1name", "user1pass", "", ""],
["http://example2.com", null, "http://example2.com", "user2name", "user2pass", "", ""],
["http://example2.com", null, "http://example2.com", "user3.name@host", "user3pass", "", ""],
["http://example2.com", null, "http://example2.com", "100@beef", "user3pass", "", ""],
["http://example2.com", null, "http://example2.com", "100%beef", "user3pass", "", ""]
);
});
add_task(async function test_accept() {
const state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "inuser",
passValue: "inpass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
const action = {
buttonClick: "ok",
textField: "outuser",
passField: "outpass",
};
authinfo.username = "inuser";
authinfo.password = "inpass";
authinfo.realm = "some realm";
promptDone = handlePrompt(state, action);
// Since prompter2 is actually a proxy to send a message to a chrome script and
// we can't send a channel in a message, we instead send the channel name that
// already exists in the chromeScript.
const isOk = prompter2.promptAuth("channel1", level, authinfo);
await promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(authinfo.username, "outuser", "Checking returned username");
is(authinfo.password, "outpass", "Checking returned password");
});
add_task(async function test_cancel() {
const state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "outuser",
passValue: "outpass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
const action = {
buttonClick: "cancel",
};
promptDone = handlePrompt(state, action);
const isOk = prompter2.promptAuth("channel1", level, authinfo);
await promptDone;
ok(!isOk, "Checking dialog return value (cancel)");
});
add_task(async function test_pwonly() {
// test filling in password-only login
const state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "",
passValue: "examplepass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
const action = {
buttonClick: "ok",
};
authinfo.username = "";
authinfo.password = "";
authinfo.realm = "http://example.com";
promptDone = handlePrompt(state, action);
const isOk = prompter2.promptAuth("channel1", level, authinfo);
await promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(authinfo.username, "", "Checking returned username");
is(authinfo.password, "examplepass", "Checking returned password");
});
add_task(async function test_multipleExisting() {
// test filling in existing login (undetermined from multiple selection)
// user2name/user2pass would also be valid to fill here.
const state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "user1name",
passValue: "user1pass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
const action = {
buttonClick: "ok",
};
authinfo.username = "";
authinfo.password = "";
authinfo.realm = "http://example2.com";
promptDone = handlePrompt(state, action);
const isOk = prompter2.promptAuth("channel2", level, authinfo);
await promptDone;
ok(isOk, "Checking dialog return value (accept)");
ok(authinfo.username == "user1name" || authinfo.username == "user2name", "Checking returned username");
ok(authinfo.password == "user1pass" || authinfo.password == "user2pass", "Checking returned password");
});
add_task(async function test_multipleExisting2() {
// test filling in existing login (undetermined --> user1)
// user2name/user2pass would also be valid to fill here.
const state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "user1name",
passValue: "user1pass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
// enter one of the known logins, test 504+505 exercise the two possible states.
const action = {
buttonClick: "ok",
textField: "user1name",
passField: "user1pass",
};
authinfo.username = "";
authinfo.password = "";
authinfo.realm = "http://example2.com";
promptDone = handlePrompt(state, action);
const isOk = prompter2.promptAuth("channel2", level, authinfo);
await promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(authinfo.username, "user1name", "Checking returned username");
is(authinfo.password, "user1pass", "Checking returned password");
});
add_task(async function test_multipleExisting3() {
// test filling in existing login (undetermined --> user2)
// user2name/user2pass would also be valid to fill here.
const state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "user1name",
passValue: "user1pass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
// enter one of the known logins, test 504+505 exercise the two possible states.
const action = {
buttonClick: "ok",
textField: "user2name",
passField: "user2pass",
};
authinfo.username = "";
authinfo.password = "";
authinfo.realm = "http://example2.com";
promptDone = handlePrompt(state, action);
const isOk = prompter2.promptAuth("channel2", level, authinfo);
await promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(authinfo.username, "user2name", "Checking returned username");
is(authinfo.password, "user2pass", "Checking returned password");
});
add_task(async function test_changingMultiple() {
// test changing a password (undetermined --> user2 w/ newpass)
// user2name/user2pass would also be valid to fill here.
const state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "user1name",
passValue: "user1pass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
// force to user2, and change the password
const action = {
buttonClick: "ok",
textField: "user2name",
passField: "NEWuser2pass",
};
authinfo.username = "";
authinfo.password = "";
authinfo.realm = "http://example2.com";
promptDone = handlePrompt(state, action);
const isOk = prompter2.promptAuth("channel2", level, authinfo);
await promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(authinfo.username, "user2name", "Checking returned username");
is(authinfo.password, "NEWuser2pass", "Checking returned password");
});
add_task(async function test_changingMultiple2() {
// test changing a password (undetermined --> user2 w/ origpass)
// user2name/user2pass would also be valid to fill here.
const state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "user1name",
passValue: "user1pass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
// force to user2, and change the password back
const action = {
buttonClick: "ok",
textField: "user2name",
passField: "user2pass",
};
authinfo.username = "";
authinfo.password = "";
authinfo.realm = "http://example2.com";
promptDone = handlePrompt(state, action);
const isOk = prompter2.promptAuth("channel2", level, authinfo);
await promptDone;
ok(isOk, "Checking dialog return value (accept)");
is(authinfo.username, "user2name", "Checking returned username");
is(authinfo.password, "user2pass", "Checking returned password");
});
</script>
</pre>
</body>
</html>
|