toolkit/components/passwordmgr/test/test_bug_776171.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_776171.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=776171
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 776171</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 auth2/authenticate.sjs that excepts user1:pass1 password
    1.23 + * 2. connect a dummy URL at the same path
    1.24 + * 3. connect authenticate.sjs that again expects user1:pass1 password
    1.25 + *    in this case, however, we have an entry without an identity
    1.26 + *    for this path (that is a parent for auth2 path in the first step)
    1.27 + */
    1.28 +
    1.29 +SimpleTest.waitForExplicitFinish();
    1.30 +
    1.31 +function clearAuthCache()
    1.32 +{
    1.33 +  var authMgr = SpecialPowers.Cc['@mozilla.org/network/http-auth-manager;1']
    1.34 +                             .getService(SpecialPowers.Ci.nsIHttpAuthManager);
    1.35 +  authMgr.clearAll();
    1.36 +}
    1.37 +
    1.38 +function doxhr(URL, user, pass, next)
    1.39 +{
    1.40 +  var xhr = new XMLHttpRequest();
    1.41 +  if (user && pass)
    1.42 +    xhr.open("POST", URL, true, user, pass);
    1.43 +  else
    1.44 +    xhr.open("POST", URL, true);
    1.45 +  xhr.onload = function()
    1.46 +  {
    1.47 +    is(xhr.status, 200, "Got status 200");
    1.48 +    next();
    1.49 +  }
    1.50 +  xhr.onerror = function()
    1.51 +  {
    1.52 +    ok(false, "request passed");
    1.53 +    finishTest();
    1.54 +  }
    1.55 +  xhr.send();
    1.56 +}
    1.57 +
    1.58 +function startTest()
    1.59 +{
    1.60 +  clearAuthCache();
    1.61 +  doxhr("auth2/authenticate.sjs?user=user1&pass=pass1&realm=realm1", "user1", "pass1", function() {
    1.62 +    doxhr("auth2", null, null, function() {
    1.63 +      doxhr("authenticate.sjs?user=user1&pass=pass1&realm=realm1", "user1", "pass1", finishTest);
    1.64 +    });
    1.65 +  });
    1.66 +}
    1.67 +
    1.68 +function finishTest()
    1.69 +{
    1.70 +  clearAuthCache();
    1.71 +  SimpleTest.finish();
    1.72 +}
    1.73 +
    1.74 +</script>
    1.75 +</body>
    1.76 +</html>
    1.77 +

mercurial