|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=776171 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 776171</title> |
|
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
10 </head> |
|
11 <body onload="startTest()"> |
|
12 <script class="testbody" type="text/javascript"> |
|
13 |
|
14 /** |
|
15 * This test checks we correctly ignore authentication entry |
|
16 * for a subpath and use creds from the URL when provided when XHR |
|
17 * is used with filled user name and password. |
|
18 * |
|
19 * 1. connect auth2/authenticate.sjs that excepts user1:pass1 password |
|
20 * 2. connect a dummy URL at the same path |
|
21 * 3. connect authenticate.sjs that again expects user1:pass1 password |
|
22 * in this case, however, we have an entry without an identity |
|
23 * for this path (that is a parent for auth2 path in the first step) |
|
24 */ |
|
25 |
|
26 SimpleTest.waitForExplicitFinish(); |
|
27 |
|
28 function clearAuthCache() |
|
29 { |
|
30 var authMgr = SpecialPowers.Cc['@mozilla.org/network/http-auth-manager;1'] |
|
31 .getService(SpecialPowers.Ci.nsIHttpAuthManager); |
|
32 authMgr.clearAll(); |
|
33 } |
|
34 |
|
35 function doxhr(URL, user, pass, next) |
|
36 { |
|
37 var xhr = new XMLHttpRequest(); |
|
38 if (user && pass) |
|
39 xhr.open("POST", URL, true, user, pass); |
|
40 else |
|
41 xhr.open("POST", URL, true); |
|
42 xhr.onload = function() |
|
43 { |
|
44 is(xhr.status, 200, "Got status 200"); |
|
45 next(); |
|
46 } |
|
47 xhr.onerror = function() |
|
48 { |
|
49 ok(false, "request passed"); |
|
50 finishTest(); |
|
51 } |
|
52 xhr.send(); |
|
53 } |
|
54 |
|
55 function startTest() |
|
56 { |
|
57 clearAuthCache(); |
|
58 doxhr("auth2/authenticate.sjs?user=user1&pass=pass1&realm=realm1", "user1", "pass1", function() { |
|
59 doxhr("auth2", null, null, function() { |
|
60 doxhr("authenticate.sjs?user=user1&pass=pass1&realm=realm1", "user1", "pass1", finishTest); |
|
61 }); |
|
62 }); |
|
63 } |
|
64 |
|
65 function finishTest() |
|
66 { |
|
67 clearAuthCache(); |
|
68 SimpleTest.finish(); |
|
69 } |
|
70 |
|
71 </script> |
|
72 </body> |
|
73 </html> |
|
74 |