2008-03-10 17:14:10 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test for Login Manager</title>
|
2009-05-06 13:46:04 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
2008-03-10 17:14:10 -07:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="text/javascript" src="pwmgr_common.js"></script>
|
2008-03-18 11:18:29 -07:00
|
|
|
<script type="text/javascript" src="prompt_common.js"></script>
|
2008-10-12 20:05:11 -07:00
|
|
|
<script type="text/javascript" src="notification_common.js"></script>
|
2008-03-10 17:14:10 -07:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Login Manager test: username/password prompts
|
|
|
|
<p id="display"></p>
|
|
|
|
|
|
|
|
<div id="content" style="display: none">
|
2008-03-16 21:54:16 -07:00
|
|
|
<iframe id="iframe"></iframe>
|
2008-03-10 17:14:10 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
/** Test for Login Manager: username / password prompts. **/
|
2008-03-18 11:18:29 -07:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
2008-03-10 17:14:10 -07:00
|
|
|
|
2010-04-06 15:28:00 -07:00
|
|
|
var pwmgr, ioService
|
|
|
|
var tmplogin, login1, login2A, login2B, login2C, login2D, login2E, login3A, login3B, login4, proxyLogin;
|
|
|
|
var mozproxy, proxiedHost = "http://mochi.test:8888";
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
function initLogins() {
|
|
|
|
pwmgr = Cc["@mozilla.org/login-manager;1"].
|
|
|
|
getService(Ci.nsILoginManager);
|
2010-04-06 15:28:00 -07:00
|
|
|
ioService = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
|
|
|
|
|
|
|
// Figure out what our proxy is set to -- can't just hardcode this, because
|
|
|
|
// mobile platforms don't use localhost.
|
|
|
|
var pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].getService();
|
|
|
|
var uri = ioService.newURI(proxiedHost, null, null);
|
|
|
|
var pi = pps.resolve(uri, 0);
|
|
|
|
mozproxy = "moz-proxy://" + pi.host + ":" + pi.port;
|
2008-03-10 17:14:10 -07:00
|
|
|
|
2008-10-12 20:05:11 -07:00
|
|
|
tmpLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
login1 = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
|
|
|
login2A = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
|
|
|
login2B = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
2009-01-15 05:16:34 -08:00
|
|
|
login2C = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
|
|
|
login2D = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
|
|
|
login2E = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
2008-03-16 21:54:16 -07:00
|
|
|
login3A = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
|
|
|
login3B = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
2008-10-12 20:05:11 -07:00
|
|
|
login4 = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
2010-04-06 15:28:00 -07:00
|
|
|
proxyLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
|
|
|
|
createInstance(Ci.nsILoginInfo);
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
login1.init("http://example.com", null, "http://example.com",
|
|
|
|
"", "examplepass", "", "");
|
|
|
|
login2A.init("http://example2.com", null, "http://example2.com",
|
|
|
|
"user1name", "user1pass", "", "");
|
|
|
|
login2B.init("http://example2.com", null, "http://example2.com",
|
|
|
|
"user2name", "user2pass", "", "");
|
2009-01-15 05:16:34 -08:00
|
|
|
login2C.init("http://example2.com", null, "http://example2.com",
|
|
|
|
"user3.name@host", "user3pass", "", "");
|
|
|
|
login2D.init("http://example2.com", null, "http://example2.com",
|
|
|
|
"100@beef", "user3pass", "", "");
|
|
|
|
login2E.init("http://example2.com", null, "http://example2.com",
|
|
|
|
"100%beef", "user3pass", "", "");
|
2010-03-12 13:53:36 -08:00
|
|
|
login3A.init("http://mochi.test:8888", null, "mochitest",
|
2008-03-16 21:54:16 -07:00
|
|
|
"mochiuser1", "mochipass1", "", "");
|
2010-03-12 13:53:36 -08:00
|
|
|
login3B.init("http://mochi.test:8888", null, "mochitest2",
|
2008-03-16 21:54:16 -07:00
|
|
|
"mochiuser2", "mochipass2", "", "");
|
2010-03-12 13:53:36 -08:00
|
|
|
login4.init("http://mochi.test:8888", null, "mochitest3",
|
2008-10-12 20:05:11 -07:00
|
|
|
"mochiuser3", "mochipass3-old", "", "");
|
2010-04-06 15:28:00 -07:00
|
|
|
proxyLogin.init(mozproxy, null, "Proxy Realm",
|
|
|
|
"proxuser", "proxpass", "", "");
|
2008-03-16 21:54:16 -07:00
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
pwmgr.addLogin(login1);
|
|
|
|
pwmgr.addLogin(login2A);
|
|
|
|
pwmgr.addLogin(login2B);
|
2009-01-15 05:16:34 -08:00
|
|
|
pwmgr.addLogin(login2C);
|
|
|
|
pwmgr.addLogin(login2D);
|
|
|
|
pwmgr.addLogin(login2E);
|
2008-03-16 21:54:16 -07:00
|
|
|
pwmgr.addLogin(login3A);
|
|
|
|
pwmgr.addLogin(login3B);
|
2008-10-12 20:05:11 -07:00
|
|
|
pwmgr.addLogin(login4);
|
2010-04-06 15:28:00 -07:00
|
|
|
pwmgr.addLogin(proxyLogin);
|
2008-03-10 17:14:10 -07:00
|
|
|
}
|
|
|
|
|
2008-03-16 21:54:16 -07:00
|
|
|
function finishTest() {
|
|
|
|
ok(true, "finishTest removing testing logins...");
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "currently have " + pwmgr.getAllLogins().length + " logins.");
|
2008-03-10 17:14:10 -07:00
|
|
|
pwmgr.removeLogin(login1);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing login 2A...");
|
2008-03-10 17:14:10 -07:00
|
|
|
pwmgr.removeLogin(login2A);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing login 2B...");
|
2008-03-10 17:14:10 -07:00
|
|
|
pwmgr.removeLogin(login2B);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing login 2C...");
|
2009-01-15 05:16:34 -08:00
|
|
|
pwmgr.removeLogin(login2C);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing login 2D...");
|
2009-01-15 05:16:34 -08:00
|
|
|
pwmgr.removeLogin(login2D);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing login 2E...");
|
2009-01-15 05:16:34 -08:00
|
|
|
pwmgr.removeLogin(login2E);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing login 3A...");
|
2008-03-16 21:54:16 -07:00
|
|
|
pwmgr.removeLogin(login3A);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing login 3B...");
|
2008-03-16 21:54:16 -07:00
|
|
|
pwmgr.removeLogin(login3B);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing login 4...");
|
2008-10-12 20:05:11 -07:00
|
|
|
pwmgr.removeLogin(login4);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "removing proxyLogin...");
|
2010-04-06 15:28:00 -07:00
|
|
|
pwmgr.removeLogin(proxyLogin);
|
2010-09-22 14:59:32 -07:00
|
|
|
ok(true, "whee, done!");
|
2008-03-16 21:54:16 -07:00
|
|
|
|
|
|
|
SimpleTest.finish();
|
2008-03-10 17:14:10 -07:00
|
|
|
}
|
|
|
|
|
2008-10-12 20:05:11 -07:00
|
|
|
/*
|
|
|
|
* handleDialog
|
|
|
|
*
|
|
|
|
* Invoked a short period of time after calling startCallbackTimer(), and
|
|
|
|
* allows testing the actual auth dialog while it's being displayed. Tests
|
|
|
|
* should call startCallbackTimer() each time the auth dialog is expected (the
|
|
|
|
* timer is a one-shot).
|
|
|
|
*/
|
2008-03-10 17:14:10 -07:00
|
|
|
function handleDialog(doc, testNum) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
ok(true, "handleDialog running for test " + testNum);
|
|
|
|
|
|
|
|
var clickOK = true;
|
2009-08-20 07:19:15 -07:00
|
|
|
var body = doc.getElementById("info.body");
|
2008-03-10 17:14:10 -07:00
|
|
|
var userfield = doc.getElementById("loginTextbox");
|
|
|
|
var passfield = doc.getElementById("password1Textbox");
|
|
|
|
var username = userfield.getAttribute("value");
|
|
|
|
var password = passfield.getAttribute("value");
|
|
|
|
var dialog = doc.getElementById("commonDialog");
|
|
|
|
|
|
|
|
switch(testNum) {
|
|
|
|
case 1:
|
|
|
|
is(username, "abc", "Checking provided username");
|
|
|
|
userfield.setAttribute("value", "xyz");
|
2009-08-20 07:19:15 -07:00
|
|
|
is(doc.activeElement, userfield.inputField, "focus correct for test" + testNum);
|
|
|
|
doc.commandDispatcher.rewindFocus();
|
|
|
|
is(doc.activeElement, body, "description focusable");
|
2008-03-10 17:14:10 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
clickOK = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
is(password, "inputpw", "Checking provided password");
|
|
|
|
passfield.setAttribute("value", "secret");
|
2009-08-20 07:19:15 -07:00
|
|
|
is(doc.activeElement, passfield.inputField, "focus correct for test" + testNum);
|
2008-03-10 17:14:10 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
is(password, "inputpw", "Checking provided password");
|
|
|
|
clickOK = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
is(password, "", "Checking provided password");
|
|
|
|
passfield.setAttribute("value", "secret");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 14:
|
|
|
|
is(password, "", "Checking provided password");
|
|
|
|
passfield.setAttribute("value", "secret");
|
|
|
|
break;
|
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
case 30:
|
|
|
|
case 31:
|
|
|
|
is(password, "", "Checking provided password");
|
|
|
|
passfield.setAttribute("value", "fill2pass");
|
|
|
|
break;
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
case 100:
|
|
|
|
is(username, "inuser", "Checking provided username");
|
|
|
|
is(password, "inpass", "Checking provided password");
|
|
|
|
userfield.setAttribute("value", "outuser");
|
|
|
|
passfield.setAttribute("value", "outpass");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 101:
|
|
|
|
clickOK = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 102:
|
|
|
|
is(username, "", "Checking provided username");
|
|
|
|
is(password, "examplepass", "Checking provided password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 103:
|
|
|
|
ok(username == "user1name" || username == "user2name", "Checking filled username");
|
|
|
|
ok(password == "user1pass" || password == "user2pass", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 104:
|
|
|
|
is(username, "user1name", "Checking filled username");
|
|
|
|
is(password, "user1pass", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 105:
|
|
|
|
is(username, "user2name", "Checking filled username");
|
|
|
|
is(password, "user2pass", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 106:
|
|
|
|
is(username, "user2name", "Checking filled username");
|
|
|
|
is(password, "user2pass", "Checking filled password");
|
|
|
|
passfield.setAttribute("value", "NEWuser2pass");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 107:
|
|
|
|
is(username, "user2name", "Checking filled username");
|
|
|
|
is(password, "NEWuser2pass", "Checking filled password");
|
|
|
|
passfield.setAttribute("value", "user2pass");
|
|
|
|
break;
|
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
case 120:
|
|
|
|
case 121:
|
|
|
|
is(username, "", "Checking filled username");
|
|
|
|
is(password, "", "Checking filled password");
|
|
|
|
userfield.setAttribute("value", "fill2user");
|
|
|
|
passfield.setAttribute("value", "fill2pass");
|
|
|
|
break;
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
case 500:
|
|
|
|
is(username, "inuser", "Checking unfilled username");
|
|
|
|
is(password, "inpass", "Checking unfilled password");
|
|
|
|
userfield.setAttribute("value", "outuser");
|
|
|
|
passfield.setAttribute("value", "outpass");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 501:
|
|
|
|
clickOK = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 502:
|
|
|
|
is(username, "", "Checking filled username");
|
|
|
|
is(password, "examplepass", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 503:
|
|
|
|
// either of the two logins might have been filled in
|
|
|
|
ok(username == "user1name" || username == "user2name", "Checking filled username");
|
|
|
|
ok(password == "user1pass" || password == "user2pass", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 504:
|
|
|
|
// either of the two logins might have been filled in
|
|
|
|
ok(username == "user1name" || username == "user2name", "Checking filled username");
|
|
|
|
ok(password == "user1pass" || password == "user2pass", "Checking filled password");
|
|
|
|
// enter one of the known logins, test 504+505 exercise the two possible states.
|
|
|
|
userfield.setAttribute("value", "user1name");
|
|
|
|
passfield.setAttribute("value", "user1pass");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 505:
|
|
|
|
// either of the two logins might have been filled in
|
|
|
|
ok(username == "user1name" || username == "user2name", "Checking filled username");
|
|
|
|
ok(password == "user1pass" || password == "user2pass", "Checking filled password");
|
|
|
|
// enter one of the known logins, test 504+505 exercise the two possible states.
|
|
|
|
userfield.setAttribute("value", "user2name");
|
|
|
|
passfield.setAttribute("value", "user2pass");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 506:
|
|
|
|
// either of the two logins might have been filled in
|
|
|
|
ok(username == "user1name" || username == "user2name", "Checking filled username");
|
|
|
|
ok(password == "user1pass" || password == "user2pass", "Checking filled password");
|
|
|
|
// force to user2, and change the password
|
|
|
|
userfield.setAttribute("value", "user2name");
|
|
|
|
passfield.setAttribute("value", "NEWuser2pass");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 507:
|
|
|
|
// either of the two logins might have been filled in
|
|
|
|
ok(username == "user1name" || username == "user2name", "Checking filled username");
|
|
|
|
ok(password == "user1pass" || password == "user2pass", "Checking filled password");
|
|
|
|
// force to user2, and change the password back
|
|
|
|
userfield.setAttribute("value", "user2name");
|
|
|
|
passfield.setAttribute("value", "user2pass");
|
|
|
|
break;
|
|
|
|
|
2010-04-06 15:28:00 -07:00
|
|
|
case 508:
|
|
|
|
is(username, "proxuser", "Checking filled username");
|
|
|
|
is(password, "proxpass", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
// No case 509, it's unprompted.
|
|
|
|
|
|
|
|
case 510:
|
|
|
|
is(username, "proxuser", "Checking filled username");
|
|
|
|
is(password, "proxpass", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 511:
|
|
|
|
is(username, "proxuser", "Checking filled username");
|
|
|
|
is(password, "proxpass", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
2008-03-16 21:54:16 -07:00
|
|
|
case 1000:
|
|
|
|
is(username, "mochiuser1", "Checking filled username");
|
|
|
|
is(password, "mochipass1", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1001:
|
|
|
|
is(username, "mochiuser2", "Checking filled username");
|
|
|
|
is(password, "mochipass2", "Checking filled password");
|
|
|
|
break;
|
|
|
|
|
2008-10-12 20:05:11 -07:00
|
|
|
// (1002 doesn't trigger a dialog)
|
|
|
|
|
|
|
|
case 1003:
|
|
|
|
is(username, "mochiuser1", "Checking filled username");
|
|
|
|
is(password, "mochipass1", "Checking filled password");
|
|
|
|
passfield.setAttribute("value", "mochipass1-new");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1004:
|
|
|
|
is(username, "mochiuser3", "Checking filled username");
|
|
|
|
is(password, "mochipass3-old", "Checking filled password");
|
|
|
|
passfield.setAttribute("value", "mochipass3-new");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1005:
|
|
|
|
is(username, "", "Checking filled username");
|
|
|
|
is(password, "", "Checking filled password");
|
|
|
|
userfield.setAttribute("value", "mochiuser3");
|
|
|
|
passfield.setAttribute("value", "mochipass3-old");
|
|
|
|
break;
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
default:
|
|
|
|
ok(false, "Uhh, unhandled switch for testNum #" + testNum);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clickOK)
|
|
|
|
dialog.acceptDialog();
|
|
|
|
else
|
|
|
|
dialog.cancelDialog();
|
|
|
|
|
|
|
|
ok(true, "handleDialog done");
|
2008-03-16 21:54:16 -07:00
|
|
|
didDialog = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-12 20:05:11 -07:00
|
|
|
/*
|
|
|
|
* handleLoad
|
|
|
|
*
|
|
|
|
* Called when a load event is fired at the subtest's iframe.
|
|
|
|
*/
|
2008-03-16 21:54:16 -07:00
|
|
|
function handleLoad() {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
ok(true, "handleLoad running for test " + testNum);
|
|
|
|
|
|
|
|
if (testNum != 1002)
|
|
|
|
ok(didDialog, "handleDialog was invoked");
|
|
|
|
|
|
|
|
// The server echos back the user/pass it received.
|
|
|
|
var username = iframe.contentDocument.getElementById("user").textContent;
|
|
|
|
var password = iframe.contentDocument.getElementById("pass").textContent;
|
|
|
|
var authok = iframe.contentDocument.getElementById("ok").textContent;
|
|
|
|
|
|
|
|
switch(testNum) {
|
|
|
|
case 1000:
|
|
|
|
testNum++;
|
|
|
|
is(authok, "PASS", "Checking for successful authentication");
|
|
|
|
is(username, "mochiuser1", "Checking for echoed username");
|
|
|
|
is(password, "mochipass1", "Checking for echoed password");
|
|
|
|
startCallbackTimer();
|
|
|
|
// 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.
|
|
|
|
iframe.src = "authenticate.sjs?user=mochiuser2&pass=mochipass2&realm=mochitest2";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1001:
|
|
|
|
testNum++;
|
|
|
|
is(authok, "PASS", "Checking for successful authentication");
|
|
|
|
is(username, "mochiuser2", "Checking for echoed username");
|
|
|
|
is(password, "mochipass2", "Checking for echoed password");
|
|
|
|
// 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!
|
|
|
|
iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1";
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 1002:
|
|
|
|
testNum++;
|
|
|
|
is(authok, "PASS", "Checking for successful authentication");
|
|
|
|
is(username, "mochiuser1", "Checking for echoed username");
|
|
|
|
is(password, "mochipass1", "Checking for echoed password");
|
|
|
|
|
2008-10-12 20:05:11 -07:00
|
|
|
// Same realm we've already authenticated to, but with a different
|
|
|
|
// expected password (to trigger an auth prompt, and change-password
|
2010-09-09 19:08:26 -07:00
|
|
|
// popup notification).
|
2008-10-12 20:05:11 -07:00
|
|
|
startCallbackTimer();
|
|
|
|
iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1-new";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1003:
|
|
|
|
testNum++;
|
|
|
|
is(authok, "PASS", "Checking for successful authentication");
|
|
|
|
is(username, "mochiuser1", "Checking for echoed username");
|
|
|
|
is(password, "mochipass1-new", "Checking for echoed password");
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// Check for the popup notification, and change the password.
|
|
|
|
popup = getPopup(popupNotifications, "password-change");
|
|
|
|
ok(popup, "got popup notification");
|
|
|
|
clickPopupButton(popup, kChangeButton);
|
|
|
|
popup.remove();
|
|
|
|
|
2008-10-12 20:05:11 -07:00
|
|
|
// Housekeeping: change it back
|
2010-03-12 13:53:36 -08:00
|
|
|
tmpLogin.init("http://mochi.test:8888", null, "mochitest",
|
2008-10-12 20:05:11 -07:00
|
|
|
"mochiuser1", "mochipass1-new", "", "");
|
|
|
|
pwmgr.modifyLogin(tmpLogin, login3A);
|
|
|
|
|
|
|
|
// 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
|
2010-09-09 19:08:26 -07:00
|
|
|
// a change-password popup notification.
|
2008-10-12 20:05:11 -07:00
|
|
|
startCallbackTimer();
|
|
|
|
iframe.src = "authenticate.sjs?user=mochiuser3&pass=mochipass3-new&realm=mochitest3";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1004:
|
|
|
|
testNum++;
|
|
|
|
is(authok, "PASS", "Checking for successful authentication");
|
|
|
|
is(username, "mochiuser3", "Checking for echoed username");
|
|
|
|
is(password, "mochipass3-new", "Checking for echoed password");
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// Check for the popup notification, and change the password.
|
|
|
|
popup = getPopup(popupNotifications, "password-change");
|
|
|
|
ok(popup, "got popup notification");
|
|
|
|
clickPopupButton(popup, kChangeButton);
|
|
|
|
popup.remove();
|
2008-10-12 20:05:11 -07:00
|
|
|
|
|
|
|
// Housekeeping: change it back to the original login4. Actually,
|
|
|
|
// just delete it and we'll re-add it as the next test.
|
2010-09-23 18:46:41 -07:00
|
|
|
function clearIt() {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
tmpLogin.init("http://mochi.test:8888", null, "mochitest3",
|
|
|
|
"mochiuser3", "mochipass3-new", "", "");
|
|
|
|
pwmgr.removeLogin(tmpLogin);
|
|
|
|
}
|
|
|
|
setTimeout(clearIt, 0);
|
|
|
|
|
2008-10-12 20:05:11 -07:00
|
|
|
// 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();
|
|
|
|
|
|
|
|
// Trigger a new prompt, so we can test adding a new login.
|
|
|
|
startCallbackTimer();
|
|
|
|
iframe.src = "authenticate.sjs?user=mochiuser3&pass=mochipass3-old&realm=mochitest3";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1005:
|
|
|
|
testNum++;
|
|
|
|
is(authok, "PASS", "Checking for successful authentication");
|
|
|
|
is(username, "mochiuser3", "Checking for echoed username");
|
|
|
|
is(password, "mochipass3-old", "Checking for echoed password");
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// Check for the popup notification, and change the password.
|
|
|
|
popup = getPopup(popupNotifications, "password-save");
|
|
|
|
ok(popup, "got popup notification");
|
|
|
|
clickPopupButton(popup, kRememberButton);
|
|
|
|
popup.remove();
|
|
|
|
|
2010-09-23 18:46:41 -07:00
|
|
|
function finishIt() {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
setTimeout(finishIt, 0);
|
2008-03-16 21:54:16 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ok(false, "Uhh, unhandled switch for testNum #" + testNum);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
initLogins();
|
|
|
|
|
|
|
|
var authinfo = {
|
|
|
|
username : "",
|
|
|
|
password : "",
|
|
|
|
domain : "",
|
|
|
|
|
|
|
|
flags : Ci.nsIAuthInformation.AUTH_HOST,
|
|
|
|
authenticationScheme : "basic",
|
|
|
|
realm : ""
|
|
|
|
};
|
|
|
|
|
2010-04-06 15:28:00 -07:00
|
|
|
var proxyAuthinfo = {
|
|
|
|
username : "",
|
|
|
|
password : "",
|
|
|
|
domain : "",
|
|
|
|
|
|
|
|
flags : Ci.nsIAuthInformation.AUTH_PROXY,
|
|
|
|
authenticationScheme : "basic",
|
|
|
|
realm : ""
|
|
|
|
};
|
|
|
|
|
|
|
|
var prefs = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
var pb;
|
|
|
|
try {
|
|
|
|
pb = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService);
|
|
|
|
} catch (e) {}
|
|
|
|
|
2008-03-18 11:18:29 -07:00
|
|
|
const Cc_promptFac= Cc["@mozilla.org/passwordmanager/authpromptfactory;1"];
|
|
|
|
ok(Cc_promptFac != null, "Access Cc[@mozilla.org/passwordmanager/authpromptfactory;1]");
|
|
|
|
|
|
|
|
const Ci_promptFac = Ci.nsIPromptFactory;
|
|
|
|
ok(Ci_promptFac != null, "Access Ci.nsIPromptFactory");
|
|
|
|
|
|
|
|
const promptFac = Cc_promptFac.getService(Ci_promptFac);
|
|
|
|
ok(promptFac != null, "promptFac getService()");
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
var prompter1 = promptFac.getPrompt(window, Ci.nsIAuthPrompt);
|
|
|
|
var prompter2 = promptFac.getPrompt(window, Ci.nsIAuthPrompt2);
|
|
|
|
|
|
|
|
function dialogTitle() { return "nsILoginManagerPrompter test #" + testNum; }
|
|
|
|
var dialogText = "This dialog should be modified and dismissed by the test.";
|
|
|
|
var uname = { value : null };
|
|
|
|
var pword = { value : null };
|
|
|
|
var result = { value : null };
|
|
|
|
var isOk;
|
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// popupNotifications (not *popup*) is a constant, per-tab container. So, we
|
2008-10-12 20:05:11 -07:00
|
|
|
// only need to fetch it once.
|
2010-09-09 19:08:26 -07:00
|
|
|
var popupNotifications = getPopupNotifications(window.top);
|
|
|
|
ok(popupNotifications, "Got popupNotifications");
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
// ===== test 1 =====
|
|
|
|
var testNum = 1;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.prompt(dialogTitle(), dialogText, "http://example.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, "abc", result);
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(result.value, "xyz", "Checking prompt() returned value");
|
|
|
|
|
|
|
|
|
|
|
|
// ===== test 2 =====
|
|
|
|
testNum++;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.prompt(dialogTitle(), dialogText, "http://example.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, "abc", result);
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
ok(!isOk, "Checking dialog return value (cancel)");
|
|
|
|
|
|
|
|
|
|
|
|
// ===== test 10 =====
|
|
|
|
// Default password provided, existing logins are ignored.
|
|
|
|
testNum = 10;
|
|
|
|
pword.value = "inputpw";
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(pword.value, "secret", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 11 =====
|
|
|
|
// Default password provided, existing logins are ignored.
|
|
|
|
testNum++;
|
|
|
|
pword.value = "inputpw";
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(!isOk, "Checking dialog return value (cancel)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
// ===== test 12 =====
|
|
|
|
// No default password provided, realm does not match existing login.
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://nonexample.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(pword.value, "secret", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 13 =====
|
|
|
|
// No default password provided, matching login is returned w/o prompting.
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
is(pword.value, "examplepass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 14 =====
|
|
|
|
// No default password provided, none of the logins from this host are
|
|
|
|
// password-only so the user is prompted.
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(pword.value, "secret", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 15 =====
|
|
|
|
// No default password provided, matching login is returned w/o prompting.
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user1name@example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
is(pword.value, "user1pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 16 =====
|
|
|
|
// No default password provided, matching login is returned w/o prompting.
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user2name@example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
is(pword.value, "user2pass", "Checking returned password");
|
|
|
|
|
2009-01-15 05:16:34 -08:00
|
|
|
// ===== test 17 =====
|
|
|
|
// No default password provided, matching login is returned w/o prompting.
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://user3%2Ename%40host@example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
is(pword.value, "user3pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 18 =====
|
|
|
|
// No default password provided, matching login is returned w/o prompting.
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://100@beef@example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
is(pword.value, "user3pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 19 =====
|
|
|
|
// No default password provided, matching login is returned w/o prompting.
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "http://100%25beef@example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
is(pword.value, "user3pass", "Checking returned password");
|
|
|
|
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
// XXX test saving a password with Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY
|
|
|
|
|
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
// ===== test 30 =====
|
|
|
|
// We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
|
|
|
|
testNum = 30;
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-18 11:08:54 -07:00
|
|
|
is(pword.value, "fill2pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 31 =====
|
|
|
|
// We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
|
|
|
|
testNum++;
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-18 11:08:54 -07:00
|
|
|
is(pword.value, "fill2pass", "Checking returned password");
|
|
|
|
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
// ===== test 100 =====
|
|
|
|
testNum = 100;
|
|
|
|
uname.value = "inuser";
|
|
|
|
pword.value = "inpass";
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://nonexample.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(uname.value, "outuser", "Checking returned username");
|
|
|
|
is(pword.value, "outpass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 101 =====
|
|
|
|
testNum++;
|
|
|
|
uname.value = "inuser";
|
|
|
|
pword.value = "inpass";
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://nonexample.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
|
|
|
|
ok(!isOk, "Checking dialog return value (cancel)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
// ===== test 102 =====
|
|
|
|
// test filling in existing password-only login
|
|
|
|
testNum++;
|
|
|
|
uname.value = null;
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(uname.value, "", "Checking returned username");
|
|
|
|
is(pword.value, "examplepass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 103 =====
|
|
|
|
// test filling in existing login (undetermined from multiple selection)
|
|
|
|
testNum++;
|
|
|
|
uname.value = null;
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
ok(uname.value == "user1name" || uname.value == "user2name", "Checking returned username");
|
|
|
|
ok(pword.value == "user1pass" || uname.value == "user2pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 104 =====
|
|
|
|
// test filling in existing login (user1 from multiple selection)
|
|
|
|
testNum++;
|
|
|
|
uname.value = "user1name";
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(uname.value, "user1name", "Checking returned username");
|
|
|
|
is(pword.value, "user1pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 105 =====
|
|
|
|
// test filling in existing login (user2 from multiple selection)
|
|
|
|
testNum++;
|
|
|
|
uname.value = "user2name";
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(uname.value, "user2name", "Checking returned username");
|
|
|
|
is(pword.value, "user2pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 106 =====
|
|
|
|
// test changing password
|
|
|
|
testNum++;
|
|
|
|
uname.value = "user2name";
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(uname.value, "user2name", "Checking returned username");
|
|
|
|
is(pword.value, "NEWuser2pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 107 =====
|
|
|
|
// test changing password (back to original value)
|
|
|
|
testNum++;
|
|
|
|
uname.value = "user2name";
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "http://example2.com",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(uname.value, "user2name", "Checking returned username");
|
|
|
|
is(pword.value, "user2pass", "Checking returned password");
|
|
|
|
|
2008-03-18 11:08:54 -07:00
|
|
|
// ===== test 120 =====
|
|
|
|
// We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
|
|
|
|
testNum = 120;
|
|
|
|
uname.value = null;
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_NEVER, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-18 11:08:54 -07:00
|
|
|
is(uname.value, "fill2user", "Checking returned username");
|
|
|
|
is(pword.value, "fill2pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 121 =====
|
|
|
|
// We don't pre-fill or save for NS_GetAuthKey-generated realms, but we should still prompt
|
|
|
|
testNum++;
|
|
|
|
uname.value = null;
|
|
|
|
pword.value = null;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter1.promptUsernameAndPassword(dialogTitle(), dialogText, "example2.com:80 (somerealm)",
|
|
|
|
Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY, uname, pword);
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-18 11:08:54 -07:00
|
|
|
is(uname.value, "fill2user", "Checking returned username");
|
|
|
|
is(pword.value, "fill2pass", "Checking returned password");
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
|
2010-04-06 15:28:00 -07:00
|
|
|
var channel1 = ioService.newChannel("http://example.com", null, null);
|
|
|
|
var channel2 = ioService.newChannel("http://example2.com", null, null);
|
|
|
|
|
|
|
|
// I'm cheating a bit here... We should probably do some magic foo to get
|
|
|
|
// something implementing nsIProxiedProtocolHandler and then call
|
|
|
|
// NewProxiedChannel(), so we have something that's definately a proxied
|
|
|
|
// channel. But Mochitests use a proxy for a number of hosts, so just
|
|
|
|
// requesting a normal channel will give us a channel that's proxied.
|
|
|
|
var proxyChannel = ioService.newChannel(proxiedHost, null, null);
|
|
|
|
|
2008-03-10 17:14:10 -07:00
|
|
|
var level = Ci.nsIAuthPrompt2.LEVEL_NONE;
|
|
|
|
|
|
|
|
|
|
|
|
// ===== test 500 =====
|
|
|
|
testNum = 500;
|
|
|
|
authinfo.username = "inuser";
|
|
|
|
authinfo.password = "inpass";
|
|
|
|
authinfo.realm = "some realm";
|
|
|
|
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(channel1, level, authinfo);
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(authinfo.username, "outuser", "Checking returned username");
|
|
|
|
is(authinfo.password, "outpass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 501 =====
|
|
|
|
testNum++;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(channel1, level, authinfo);
|
2008-03-10 19:24:08 -07:00
|
|
|
|
2008-03-14 17:13:39 -07:00
|
|
|
ok(!isOk, "Checking dialog return value (cancel)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
|
|
|
|
// ===== test 502 =====
|
|
|
|
// test filling in password-only login
|
|
|
|
testNum++;
|
|
|
|
authinfo.username = "";
|
|
|
|
authinfo.password = "";
|
|
|
|
authinfo.realm = "http://example.com";
|
|
|
|
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(channel1, level, authinfo);
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(authinfo.username, "", "Checking returned username");
|
|
|
|
is(authinfo.password, "examplepass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 503 =====
|
|
|
|
// test filling in existing login (undetermined from multiple selection)
|
|
|
|
testNum++;
|
|
|
|
authinfo.username = "";
|
|
|
|
authinfo.password = "";
|
|
|
|
authinfo.realm = "http://example2.com";
|
|
|
|
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(channel2, level, authinfo);
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
ok(authinfo.username == "user1name" || authinfo.username == "user2name", "Checking returned username");
|
|
|
|
ok(authinfo.password == "user1pass" || authinfo.password == "user2pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 504 =====
|
|
|
|
// test filling in existing login (undetermined --> user1)
|
|
|
|
testNum++;
|
|
|
|
authinfo.username = "";
|
|
|
|
authinfo.password = "";
|
|
|
|
authinfo.realm = "http://example2.com";
|
|
|
|
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(channel2, level, authinfo);
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(authinfo.username, "user1name", "Checking returned username");
|
|
|
|
is(authinfo.password, "user1pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 505 =====
|
|
|
|
// test filling in existing login (undetermined --> user2)
|
|
|
|
testNum++;
|
|
|
|
authinfo.username = "";
|
|
|
|
authinfo.password = "";
|
|
|
|
authinfo.realm = "http://example2.com";
|
|
|
|
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(channel2, level, authinfo);
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(authinfo.username, "user2name", "Checking returned username");
|
|
|
|
is(authinfo.password, "user2pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 506 =====
|
|
|
|
// test changing a password (undetermined --> user2 w/ newpass)
|
|
|
|
testNum++;
|
|
|
|
authinfo.username = "";
|
|
|
|
authinfo.password = "";
|
|
|
|
authinfo.realm = "http://example2.com";
|
|
|
|
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(channel2, level, authinfo);
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(authinfo.username, "user2name", "Checking returned username");
|
|
|
|
is(authinfo.password, "NEWuser2pass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 507 =====
|
|
|
|
// test changing a password (undetermined --> user2 w/ origpass)
|
|
|
|
testNum++;
|
|
|
|
authinfo.username = "";
|
|
|
|
authinfo.password = "";
|
|
|
|
authinfo.realm = "http://example2.com";
|
|
|
|
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(channel2, level, authinfo);
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
2010-04-06 15:28:00 -07:00
|
|
|
ok(didDialog, "handleDialog was invoked");
|
2008-03-10 17:14:10 -07:00
|
|
|
is(authinfo.username, "user2name", "Checking returned username");
|
|
|
|
is(authinfo.password, "user2pass", "Checking returned password");
|
|
|
|
|
2010-04-06 15:28:00 -07:00
|
|
|
// ===== test 508 =====
|
|
|
|
// test proxy login (default = no autologin), make sure it prompts.
|
|
|
|
testNum++;
|
|
|
|
proxyAuthinfo.username = "";
|
|
|
|
proxyAuthinfo.password = "";
|
|
|
|
proxyAuthinfo.realm = "Proxy Realm";
|
|
|
|
proxyAuthinfo.flags = Ci.nsIAuthInformation.AUTH_PROXY;
|
|
|
|
|
|
|
|
var time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo);
|
|
|
|
var time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
ok(didDialog, "handleDialog was invoked");
|
|
|
|
isnot(time1, time2, "Checking that timeLastUsed was updated");
|
|
|
|
is(proxyAuthinfo.username, "proxuser", "Checking returned username");
|
|
|
|
is(proxyAuthinfo.password, "proxpass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 509 =====
|
|
|
|
// test proxy login (with autologin)
|
|
|
|
testNum++;
|
|
|
|
|
|
|
|
// Enable the autologin pref.
|
|
|
|
prefs.setBoolPref("signon.autologin.proxy", true);
|
|
|
|
|
|
|
|
proxyAuthinfo.username = "";
|
|
|
|
proxyAuthinfo.password = "";
|
|
|
|
proxyAuthinfo.realm = "Proxy Realm";
|
|
|
|
proxyAuthinfo.flags = Ci.nsIAuthInformation.AUTH_PROXY;
|
|
|
|
|
|
|
|
time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
|
|
|
isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo);
|
|
|
|
time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
isnot(time1, time2, "Checking that timeLastUsed was updated");
|
|
|
|
is(proxyAuthinfo.username, "proxuser", "Checking returned username");
|
|
|
|
is(proxyAuthinfo.password, "proxpass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 510 =====
|
|
|
|
// test proxy login (with autologin), ensure it prompts after a failed auth.
|
|
|
|
testNum++;
|
|
|
|
|
|
|
|
proxyAuthinfo.username = "";
|
|
|
|
proxyAuthinfo.password = "";
|
|
|
|
proxyAuthinfo.realm = "Proxy Realm";
|
|
|
|
proxyAuthinfo.flags = (Ci.nsIAuthInformation.AUTH_PROXY | Ci.nsIAuthInformation.PREVIOUS_FAILED);
|
|
|
|
|
|
|
|
time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo);
|
|
|
|
time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
ok(didDialog, "handleDialog was invoked");
|
|
|
|
isnot(time1, time2, "Checking that timeLastUsed was updated");
|
|
|
|
is(proxyAuthinfo.username, "proxuser", "Checking returned username");
|
|
|
|
is(proxyAuthinfo.password, "proxpass", "Checking returned password");
|
|
|
|
|
|
|
|
// ===== test 511 =====
|
|
|
|
// test proxy login (with autologin), ensure it prompts in Private Browsing mode.
|
|
|
|
testNum++;
|
|
|
|
|
|
|
|
proxyAuthinfo.username = "";
|
|
|
|
proxyAuthinfo.password = "";
|
|
|
|
proxyAuthinfo.realm = "Proxy Realm";
|
|
|
|
proxyAuthinfo.flags = Ci.nsIAuthInformation.AUTH_PROXY;
|
|
|
|
|
|
|
|
if (pb) {
|
|
|
|
prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
|
|
|
|
pb.privateBrowsingEnabled = true;
|
|
|
|
|
|
|
|
time1 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
|
|
|
startCallbackTimer();
|
|
|
|
isOk = prompter2.promptAuth(proxyChannel, level, proxyAuthinfo);
|
|
|
|
time2 = pwmgr.findLogins({}, mozproxy, null, "Proxy Realm")[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
|
|
|
|
|
|
|
ok(isOk, "Checking dialog return value (accept)");
|
|
|
|
ok(didDialog, "handleDialog was invoked");
|
|
|
|
is(time1, time2, "Checking that timeLastUsed was not updated");
|
|
|
|
is(proxyAuthinfo.username, "proxuser", "Checking returned username");
|
|
|
|
is(proxyAuthinfo.password, "proxpass", "Checking returned password");
|
|
|
|
|
|
|
|
pb.privateBrowsingEnabled = false;
|
|
|
|
prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prefs.clearUserPref("signon.autologin.proxy");
|
2008-03-10 17:14:10 -07:00
|
|
|
|
2010-09-09 19:08:26 -07:00
|
|
|
// XXX check for and kill popup notification??
|
2008-03-10 17:14:10 -07:00
|
|
|
// XXX check for checkbox / checkstate on old prompts?
|
|
|
|
// XXX check NTLM domain stuff
|
|
|
|
|
2008-03-16 21:54:16 -07:00
|
|
|
|
2008-03-16 22:42:24 -07:00
|
|
|
var iframe = document.getElementById("iframe");
|
|
|
|
iframe.onload = handleLoad;
|
|
|
|
|
2008-03-18 11:18:29 -07:00
|
|
|
// clear plain HTTP auth sessions before the test, to allow
|
|
|
|
// running them more than once.
|
2008-10-12 20:05:11 -07:00
|
|
|
var authMgr = Cc['@mozilla.org/network/http-auth-manager;1'].
|
|
|
|
getService(Ci.nsIHttpAuthManager);
|
2008-03-18 11:18:29 -07:00
|
|
|
authMgr.clearAll();
|
2008-03-16 22:42:24 -07:00
|
|
|
|
2008-03-16 21:54:16 -07:00
|
|
|
// ===== test 1000 =====
|
|
|
|
testNum = 1000;
|
|
|
|
startCallbackTimer();
|
|
|
|
iframe.src = "authenticate.sjs?user=mochiuser1&pass=mochipass1";
|
|
|
|
|
2008-03-18 11:18:29 -07:00
|
|
|
// ...remaining tests are driven by handleLoad()...
|
2008-03-16 21:54:16 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2008-03-10 17:14:10 -07:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|