toolkit/components/passwordmgr/test/test_bug_627616.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test bug 627616</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="prompt_common.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <script class="testbody" type="text/javascript">
michael@0 11 SimpleTest.waitForExplicitFinish();
michael@0 12
michael@0 13 var Cc = SpecialPowers.Cc;
michael@0 14
michael@0 15 testNum = 1;
michael@0 16
michael@0 17 var login, login2;
michael@0 18
michael@0 19 var resolveCallback = SpecialPowers.wrapCallbackObject({
michael@0 20
michael@0 21 QueryInterface : function (iid) {
michael@0 22 const interfaces = [Ci.nsIProtocolProxyCallback, Ci.nsISupports];
michael@0 23
michael@0 24 if (!interfaces.some( function(v) { return iid.equals(v) } ))
michael@0 25 throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
michael@0 26 return this;
michael@0 27 },
michael@0 28
michael@0 29 onProxyAvailable : function (req, uri, pi, status) {
michael@0 30 init2(SpecialPowers.wrap(pi).host, SpecialPowers.wrap(pi).port);
michael@0 31 }
michael@0 32 });
michael@0 33
michael@0 34 function init1() {
michael@0 35 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
michael@0 36 var pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].getService();
michael@0 37
michael@0 38 var uri = ios.newURI("http://example.com", null, null);
michael@0 39 pps.asyncResolve(uri, 0, resolveCallback);
michael@0 40 }
michael@0 41
michael@0 42 function init2(proxyHost, proxyPort) {
michael@0 43
michael@0 44 var mozproxy = "moz-proxy://" + proxyHost + ":" + proxyPort;
michael@0 45
michael@0 46 var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
michael@0 47 login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
michael@0 48 login.init(mozproxy, null, "proxy_realm", "proxy_user", "proxy_pass", "", "");
michael@0 49 pwmgr.addLogin(login);
michael@0 50
michael@0 51 login2 = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
michael@0 52 login2.init("http://mochi.test:8888", null, "mochirealm", "user1name", "user1pass", "", "");
michael@0 53 pwmgr.addLogin(login2);
michael@0 54 startCallbackTimer();
michael@0 55 }
michael@0 56 function cleanup() {
michael@0 57 var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
michael@0 58 pwmgr.removeLogin(login);
michael@0 59 pwmgr.removeLogin(login2);
michael@0 60 timer.cancel();
michael@0 61 }
michael@0 62
michael@0 63 function makeXHR(expectedStatus, expectedText, extra) {
michael@0 64 var xhr = new XMLHttpRequest();
michael@0 65 xhr.open("GET", "authenticate.sjs?" +
michael@0 66 "proxy_user=proxy_user&" +
michael@0 67 "proxy_pass=proxy_pass&" +
michael@0 68 "proxy_realm=proxy_realm&" +
michael@0 69 "user=user1name&" +
michael@0 70 "pass=user1pass&" +
michael@0 71 "realm=mochirealm&" +
michael@0 72 extra || "");
michael@0 73 xhr.onloadend = function() {
michael@0 74 is(xhr.status, expectedStatus, "xhr.status");
michael@0 75 is(xhr.statusText, expectedText, "xhr.statusText");
michael@0 76 runNextTest();
michael@0 77 }
michael@0 78 return xhr;
michael@0 79 }
michael@0 80
michael@0 81 function testNonAnonymousCredentials() {
michael@0 82 var xhr = makeXHR(200, "OK");
michael@0 83 xhr.send();
michael@0 84 }
michael@0 85
michael@0 86 function testAnonymousCredentials() {
michael@0 87 // Test that an anonymous request correctly performs proxy authentication
michael@0 88 var xhr = makeXHR(401, "Authentication required");
michael@0 89 SpecialPowers.wrap(xhr).channel.loadFlags |= Ci.nsIChannel.LOAD_ANONYMOUS;
michael@0 90 xhr.send();
michael@0 91 }
michael@0 92
michael@0 93 function testAnonymousNoAuth() {
michael@0 94 // Next, test that an anonymous request still does not include any non-proxy
michael@0 95 // authentication headers.
michael@0 96 var xhr = makeXHR(200, "Authorization header not found", "anonymous=1");
michael@0 97 SpecialPowers.wrap(xhr).channel.loadFlags |= Ci.nsIChannel.LOAD_ANONYMOUS;
michael@0 98 xhr.send();
michael@0 99 }
michael@0 100
michael@0 101 var gExpectedDialogs = 0;
michael@0 102 var gCurrentTest;
michael@0 103 function runNextTest() {
michael@0 104 is(gExpectedDialogs, 0, "received expected number of auth dialogs");
michael@0 105 Cc["@mozilla.org/network/http-auth-manager;1"].getService(SpecialPowers.Ci.nsIHttpAuthManager).clearAll();
michael@0 106 if (pendingTests.length > 0) {
michael@0 107 ({expectedDialogs: gExpectedDialogs,
michael@0 108 test: gCurrentTest}) = pendingTests.shift();
michael@0 109 gCurrentTest.call(this);
michael@0 110 } else {
michael@0 111 cleanup();
michael@0 112 SimpleTest.finish();
michael@0 113 }
michael@0 114 }
michael@0 115
michael@0 116 var pendingTests = [{expectedDialogs: 2, test: testNonAnonymousCredentials},
michael@0 117 {expectedDialogs: 1, test: testAnonymousCredentials},
michael@0 118 {expectedDialogs: 0, test: testAnonymousNoAuth}];
michael@0 119 init1();
michael@0 120 runNextTest();
michael@0 121
michael@0 122 function handleDialog(doc, testNum)
michael@0 123 {
michael@0 124 var dialog = doc.getElementById("commonDialog");
michael@0 125 dialog.acceptDialog();
michael@0 126 gExpectedDialogs--;
michael@0 127 startCallbackTimer();
michael@0 128 }
michael@0 129 </script>
michael@0 130 </body>
michael@0 131 </html>

mercurial