toolkit/components/passwordmgr/test/test_bug_654348.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/passwordmgr/test/test_bug_654348.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=654348
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 654348</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body onload="startTest()">
    1.15 +<script class="testbody" type="text/javascript">
    1.16 +
    1.17 +/**
    1.18 + * This test checks we correctly ignore authentication entry
    1.19 + * for a subpath and use creds from the URL when provided when XHR
    1.20 + * is used with filled user name and password.
    1.21 + *
    1.22 + * 1. connect authenticate.sjs that excepts user1:pass1 password
    1.23 + * 2. connect authenticate.sjs that this time expects differentuser2:pass2 password
    1.24 + *    we must use the creds that are provided to the xhr witch are different and expected
    1.25 + */
    1.26 +
    1.27 +SimpleTest.waitForExplicitFinish();
    1.28 +
    1.29 +function clearAuthCache()
    1.30 +{
    1.31 +  var authMgr = SpecialPowers.Cc['@mozilla.org/network/http-auth-manager;1']
    1.32 +                             .getService(SpecialPowers.Ci.nsIHttpAuthManager);
    1.33 +  authMgr.clearAll();
    1.34 +}
    1.35 +
    1.36 +function doxhr(URL, user, pass, code, next)
    1.37 +{
    1.38 +  var xhr = new XMLHttpRequest();
    1.39 +  if (user && pass)
    1.40 +    xhr.open("POST", URL, true, user, pass);
    1.41 +  else
    1.42 +    xhr.open("POST", URL, true);
    1.43 +  xhr.onload = function()
    1.44 +  {
    1.45 +    is(xhr.status, code, "expected response code " + code);
    1.46 +    next();
    1.47 +  }
    1.48 +  xhr.onerror = function()
    1.49 +  {
    1.50 +    ok(false, "request passed");
    1.51 +    finishTest();
    1.52 +  }
    1.53 +  xhr.send();
    1.54 +}
    1.55 +
    1.56 +function startTest()
    1.57 +{
    1.58 +  clearAuthCache();
    1.59 +  doxhr("authenticate.sjs?user=dummy&pass=pass1&realm=realm1&formauth=1", "dummy", "dummy", 403, function() {
    1.60 +    doxhr("authenticate.sjs?user=dummy&pass=pass1&realm=realm1&formauth=1", "dummy", "pass1", 200, finishTest);
    1.61 +  });
    1.62 +}
    1.63 +
    1.64 +function finishTest()
    1.65 +{
    1.66 +  clearAuthCache();
    1.67 +  SimpleTest.finish();
    1.68 +}
    1.69 +
    1.70 +</script>
    1.71 +</body>
    1.72 +</html>
    1.73 +

mercurial