browser_bug2008464.js (1961B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ 3 */ 4 5 "use strict"; 6 7 add_task(async function testHostnameDisplayedCorrectly() { 8 const { HttpServer } = ChromeUtils.importESModule( 9 "resource://testing-common/httpd.sys.mjs" 10 ); 11 12 const server = new HttpServer(); 13 registerCleanupFunction(() => new Promise(resolve => server.stop(resolve))); 14 server.registerPathHandler("/auth", (request, response) => { 15 response.setStatusLine(request.httpVersion, 401, "Unauthorized"); 16 response.setHeader("WWW-Authenticate", 'Basic realm="test"', false); 17 }); 18 server.start(-1); 19 const port = server.identity.primaryPort; 20 server.identity.add("http", "localhost", port); 21 22 await SpecialPowers.pushPrefEnv({ 23 set: [ 24 ["dom.security.https_first", false], 25 ["network.http.basic_http_auth.enabled", false], 26 ["browser.http.blank_page_with_error_response.enabled", true], 27 ["security.certerrors.felt-privacy-v1", true], 28 ], 29 }); 30 registerCleanupFunction(() => SpecialPowers.popPrefEnv()); 31 32 const url = `http://localhost:${port}/auth`; 33 info(`Checking URL (${url}) against displayed hostname.`); 34 await BrowserTestUtils.withNewTab( 35 { gBrowser, url, waitForLoad: false }, 36 async browser => { 37 await BrowserTestUtils.waitForErrorPage(browser); 38 await SpecialPowers.spawn(browser, [port], async p => { 39 const netErrorCard = await ContentTaskUtils.waitForCondition( 40 () => 41 content.document.querySelector("net-error-card")?.wrappedJSObject 42 ); 43 await netErrorCard.getUpdateComplete(); 44 45 Assert.equal( 46 netErrorCard.errorInfo.errorCodeString, 47 "NS_ERROR_BASIC_HTTP_AUTH_DISABLED", 48 "Shows HTTP auth disabled error" 49 ); 50 Assert.equal( 51 netErrorCard.hostname, 52 `localhost:${p}`, 53 "Hostname includes the port once" 54 ); 55 }); 56 } 57 ); 58 });