4 // Test the case when a channel is cancelled when "negotiate" authentication
13 const { HttpServer } = ChromeUtils.importESModule(
14 "resource://testing-common/httpd.sys.mjs"
17 ChromeUtils.defineLazyGetter(this, "URL", function () {
18 return "http://localhost:" + httpserv.identity.primaryPort;
21 function makeChan(url, loadingUrl) {
22 var principal = Services.scriptSecurityManager.createContentPrincipal(
23 Services.io.newURI(loadingUrl),
26 return NetUtil.newChannel({
28 loadingPrincipal: principal,
29 securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
30 contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER,
34 function authHandler(metadata, response) {
35 var body = "blablabla";
37 response.seizePower();
38 response.write("HTTP/1.1 401 Unauthorized\r\n");
39 response.write("WWW-Authenticate: Negotiate\r\n");
40 response.write("WWW-Authenticate: Basic realm=test\r\n");
41 response.write("\r\n");
47 prefs = Services.prefs;
49 prefs.setIntPref("network.auth.subresource-http-auth-allow", 2);
50 prefs.setStringPref("network.negotiate-auth.trusted-uris", "localhost");
52 httpserv = new HttpServer();
53 httpserv.registerPathHandler("/auth", authHandler);
58 registerCleanupFunction(async () => {
59 prefs.clearUserPref("network.auth.subresource-http-auth-allow");
60 prefs.clearUserPref("network.negotiate-auth.trusted-uris");
61 await httpserv.stop();
64 function channelOpenPromise(chan) {
65 return new Promise(resolve => {
66 let topic = "http-on-transaction-suspended-authentication";
68 QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
69 observe(aSubject, aTopic, aData) {
70 if (aTopic == topic) {
71 Services.obs.removeObserver(observer, topic);
72 let channel = aSubject.QueryInterface(Ci.nsIChannel);
73 channel.cancel(Cr.NS_BINDING_ABORTED);
78 Services.obs.addObserver(observer, topic);
80 chan.asyncOpen(new ChannelListener(finish, null, CL_EXPECT_FAILURE));
87 add_task(async function testCancelAuthentication() {
88 let chan = makeChan(URL + "/auth", URL);
89 await channelOpenPromise(chan);
90 Assert.equal(chan.status, Cr.NS_BINDING_ABORTED);