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
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test HTTP auth prompts by loading authenticate.sjs</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">
<iframe id="iframe"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
var iframe = document.getElementById("iframe");
// Let prompt_common know what kind of modal type is used for auth prompts.
modalType = Ci.nsIPrompt.MODAL_TYPE_TAB;
const AUTHENTICATE_PATH = new URL("authenticate.sjs", window.location.href).pathname;
add_setup(async () => {
await setStoredLoginsAsync(
["http://mochi.test:8888", null, "mochitest", "mochiuser1", "mochipass1", "", ""],
["http://mochi.test:8888", null, "mochitest2", "mochiuser2", "mochipass2", "", ""],
["http://mochi.test:8888", null, "mochitest3", "mochiuser3", "mochipass3-old", "", ""],
// Logins to test scheme upgrades (allowed) and downgrades (disallowed)
["http://example.com", null, "schemeUpgrade", "httpUser", "httpPass", "", ""],
["https://example.com", null, "schemeDowngrade", "httpsUser", "httpsPass", "", ""],
// HTTP and HTTPS version of the same domain and realm but with different passwords.
["http://example.org", null, "schemeUpgradeDedupe", "dedupeUser", "httpPass", "", ""],
["https://example.org", null, "schemeUpgradeDedupe", "dedupeUser", "httpsPass", "", ""]
);
});
add_task(async function test_iframe() {
let state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "mochiuser1",
passValue: "mochipass1",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
let action = {
buttonClick: "ok",
};
promptDone = handlePrompt(state, action);
// The following tests are driven by iframe loads
var iframeLoaded = onloadPromiseFor("iframe");
iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1";
await promptDone;
await iframeLoaded;
await checkEchoedAuthInfo({user: "mochiuser1", pass: "mochipass1"},
iframe);
state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "mochiuser2",
passValue: "mochipass2",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
action = {
buttonClick: "ok",
};
promptDone = handlePrompt(state, action);
// We've already authenticated to this host:port. For this next
// request, the existing auth should be sent, we'll get a 401 reply,
// and we should prompt for new auth.
iframeLoaded = onloadPromiseFor("iframe");
iframe.src = "authenticate.sjs?user=mochiuser2&pass=mochipass2&realm=mochitest2";
await promptDone;
await iframeLoaded;
await checkEchoedAuthInfo({user: "mochiuser2", pass: "mochipass2"},
iframe);
// Now make a load that requests the realm from test 1000. It was
// already provided there, so auth will *not* be prompted for -- the
// networking layer already knows it!
iframeLoaded = onloadPromiseFor("iframe");
iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1";
await iframeLoaded;
await checkEchoedAuthInfo({user: "mochiuser1", pass: "mochipass1"},
iframe);
// Same realm we've already authenticated to, but with a different
// expected password (to trigger an auth prompt, and change-password
// popup notification).
state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "mochiuser1",
passValue: "mochipass1",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
action = {
buttonClick: "ok",
passField: "mochipass1-new",
};
promptDone = handlePrompt(state, action);
iframeLoaded = onloadPromiseFor("iframe");
let promptShownPromise = promisePromptShown("passwordmgr-prompt-change");
iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1-new";
await promptDone;
await iframeLoaded;
await checkEchoedAuthInfo({user: "mochiuser1", pass: "mochipass1-new"},
iframe);
await promptShownPromise;
// Same as last test, but for a realm we haven't already authenticated
// to (but have an existing saved login for, so that we'll trigger
// a change-password popup notification.
state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "mochiuser3",
passValue: "mochipass3-old",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
action = {
buttonClick: "ok",
passField: "mochipass3-new",
};
promptDone = handlePrompt(state, action);
iframeLoaded = onloadPromiseFor("iframe");
promptShownPromise = promisePromptShown("passwordmgr-prompt-change");
iframe.src = "authenticate.sjs?user=mochiuser3&pass=mochipass3-new&realm=mochitest3";
await promptDone;
await iframeLoaded;
await checkEchoedAuthInfo({user: "mochiuser3", pass: "mochipass3-new"},
iframe);
await promptShownPromise;
// Housekeeping: Delete login4 to test the save prompt in the next test.
runInParent(() => {
var tmpLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
createInstance(Ci.nsILoginInfo);
tmpLogin.init("http://mochi.test:8888", null, "mochitest3",
"mochiuser3", "mochipass3-old", "", "");
Services.logins.removeLogin(tmpLogin);
// Clear cached auth from this subtest, and avoid leaking due to bug 459620.
var authMgr = Cc["@mozilla.org/network/http-auth-manager;1"].
getService(Ci.nsIHttpAuthManager);
authMgr.clearAll();
});
state = {
msg: "This site is asking you to sign in.",
title: "Authentication Required",
textValue: "",
passValue: "",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
action = {
buttonClick: "ok",
textField: "mochiuser3",
passField: "mochipass3-old",
};
// Trigger a new prompt, so we can test adding a new login.
promptDone = handlePrompt(state, action);
iframeLoaded = onloadPromiseFor("iframe");
promptShownPromise = promisePromptShown("passwordmgr-prompt-save");
iframe.src = "authenticate.sjs?user=mochiuser3&pass=mochipass3-old&realm=mochitest3";
await promptDone;
await iframeLoaded;
await checkEchoedAuthInfo({user: "mochiuser3", pass: "mochipass3-old"},
iframe);
await promptShownPromise;
});
add_task(async function test_schemeUpgrade() {
let state = {
msg: "This site is asking you to sign in. Warning: Your login information " +
"will be shared with example.com, not the website you are currently visiting.",
title: "Authentication Required",
textValue: "httpUser",
passValue: "httpPass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
let action = {
buttonClick: "ok",
};
let promptDone = handlePrompt(state, action);
// The following tests are driven by iframe loads
let iframeLoaded = onloadPromiseFor("iframe");
iframe.src = "https://example.com" + AUTHENTICATE_PATH +
"?user=httpUser&pass=httpPass&realm=schemeUpgrade";
await promptDone;
await iframeLoaded;
await checkEchoedAuthInfo({user: "httpUser", pass: "httpPass"},
iframe);
});
add_task(async function test_schemeDowngrade() {
const state = {
msg: "This site is asking you to sign in. Warning: Your login information " +
"will be shared with example.com, not the website you are currently visiting.",
title: "Authentication Required",
textValue: "", // empty because we shouldn't downgrade
passValue: "",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
const action = {
buttonClick: "cancel",
};
const promptDone = handlePrompt(state, action);
// The following tests are driven by iframe loads
const iframeLoaded = onloadPromiseFor("iframe");
iframe.src = "http://example.com" + AUTHENTICATE_PATH +
"?user=unused&pass=unused&realm=schemeDowngrade";
await promptDone;
await iframeLoaded;
});
add_task(async function test_schemeUpgrade_dedupe() {
const state = {
msg: "This site is asking you to sign in. Warning: Your login information " +
"will be shared with example.org, not the website you are currently visiting.",
title: "Authentication Required",
textValue: "dedupeUser",
passValue: "httpsPass",
iconClass: "authentication-icon question-icon",
titleHidden: true,
textHidden: false,
passHidden: false,
checkHidden: true,
checkMsg: "",
checked: false,
focused: "textField",
defButton: "button0",
};
const action = {
buttonClick: "ok",
};
const promptDone = handlePrompt(state, action);
// The following tests are driven by iframe loads
const iframeLoaded = onloadPromiseFor("iframe");
iframe.src = "https://example.org" + AUTHENTICATE_PATH +
"?user=dedupeUser&pass=httpsPass&realm=schemeUpgradeDedupe";
await promptDone;
await iframeLoaded;
await checkEchoedAuthInfo({user: "dedupeUser", pass: "httpsPass"},
iframe);
});
</script>
</pre>
</body>
</html>
|