3 Create two http requests with the same URL in which has a user name. We allow
4 first http request to be loaded and saved in the cache, so the second request
5 will be served from the cache. However, we disallow loading by returning 1
6 in the prompt service. In the end, the second request will be failed.
12 const { HttpServer
} = ChromeUtils
.importESModule(
13 "resource://testing-common/httpd.sys.mjs"
16 const { MockRegistrar
} = ChromeUtils
.importESModule(
17 "resource://testing-common/MockRegistrar.sys.mjs"
20 var httpProtocolHandler
= Cc
[
21 "@mozilla.org/network/protocol;1?name=http"
22 ].getService(Ci
.nsIHttpProtocolHandler
);
24 ChromeUtils
.defineLazyGetter(this, "URL", function () {
25 return "http://foo@localhost:" + httpServer
.identity
.primaryPort
;
28 var httpServer
= null;
30 const gMockPromptService
= {
31 firstTimeCalled
: false,
33 if (!this.firstTimeCalled
) {
34 this.firstTimeCalled
= true;
41 QueryInterface
: ChromeUtils
.generateQI(["nsIPromptService"]),
44 var gMockPromptServiceCID
= MockRegistrar
.register(
45 "@mozilla.org/prompter;1",
49 registerCleanupFunction(() => {
50 MockRegistrar
.unregister(gMockPromptServiceCID
);
53 function makeChan(uri
) {
54 let chan
= NetUtil
.newChannel({
56 loadUsingSystemPrincipal
: true,
57 }).QueryInterface(Ci
.nsIHttpChannel
);
58 chan
.loadFlags
= Ci
.nsIChannel
.LOAD_INITIAL_DOCUMENT_URI
;
62 const responseBody
= "body";
64 function contentHandler(metadata
, response
) {
65 response
.setHeader("Content-Type", "text/plain");
66 response
.setHeader("ETag", "Just testing");
67 response
.setHeader("Cache-Control", "max-age=99999");
68 response
.setHeader("Content-Length", "" + responseBody
.length
);
69 response
.bodyOutputStream
.write(responseBody
, responseBody
.length
);
75 Services
.prefs
.setBoolPref("network.http.rcwn.enabled", false);
76 Services
.prefs
.setBoolPref("network.auth.confirmAuth.enabled", true);
78 httpServer
= new HttpServer();
79 httpServer
.registerPathHandler("/content", contentHandler
);
82 httpProtocolHandler
.EnsureHSTSDataReady().then(function () {
83 var chan1
= makeChan(URL
+ "/content");
84 chan1
.asyncOpen(new ChannelListener(firstTimeThrough
, null));
85 var chan2
= makeChan(URL
+ "/content");
87 new ChannelListener(secondTimeThrough
, null, CL_EXPECT_FAILURE
)
94 function firstTimeThrough(request
, buffer
) {
95 Assert
.equal(buffer
, responseBody
);
96 Assert
.ok(gMockPromptService
.firstTimeCalled
, "Prompt service invoked");
99 function secondTimeThrough(request
) {
100 Assert
.equal(request
.status
, Cr
.NS_ERROR_SUPERFLUOS_AUTH
);
101 httpServer
.stop(do_test_finished
);