542 changes: 295 additions & 247 deletions netwerk/dns/nsHostResolver.cpp

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions netwerk/dns/nsHostResolver.h
Expand Up @@ -494,6 +494,14 @@ class nsHostResolver : public nsISupports, public AHostResolver {
uint16_t flags, uint16_t af,
nsResolveHostCallback* callback);

nsHostRecord* InitRecord(const nsHostKey& key);

/**
* return a resolved hard coded loopback dns record for the specified key
*/
already_AddRefed<nsHostRecord> InitLoopbackRecord(const nsHostKey& key,
nsresult* aRv);

/**
* removes the specified callback from the nsHostRecord for the given
* hostname, originAttributes, flags, and address family. these parameters
Expand Down
6 changes: 5 additions & 1 deletion netwerk/test/httpserver/test/test_seizepower.js
Expand Up @@ -15,6 +15,7 @@ XPCOMUtils.defineLazyGetter(this, "PORT", function() {
var srv;

function run_test() {
Services.prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);
srv = createServer();

srv.registerPathHandler("/raw-data", handleRawData);
Expand All @@ -25,7 +26,10 @@ function run_test() {

srv.start(-1);

runRawTests(tests, testComplete(srv));
runRawTests(tests, function() {
Services.prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
testComplete(srv)();
});
}

function checkException(fun, err, msg) {
Expand Down
4 changes: 4 additions & 0 deletions netwerk/test/unit/test_about_networking.js
Expand Up @@ -98,6 +98,9 @@ function run_test() {
true
);

// We always resolve localhost as it's hardcoded without the following pref:
Services.prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);

let ioService = Cc["@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService
);
Expand All @@ -112,6 +115,7 @@ function run_test() {
channel.open();

gServerSocket.init(-1, true, -1);
Services.prefs.clearUserPref("network.proxy.allow_hijacking_localhost");

run_next_test();
}
3 changes: 3 additions & 0 deletions netwerk/test/unit/test_dns_offline.js
Expand Up @@ -47,6 +47,8 @@ const defaultOriginAttributes = {};
function run_test() {
do_test_pending();
prefs.setBoolPref("network.dns.offline-localhost", false);
// We always resolve localhost as it's hardcoded without the following pref:
prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);
ioService.offline = true;
try {
dns.asyncResolve(
Expand Down Expand Up @@ -107,4 +109,5 @@ function test3Continued() {

function cleanup() {
prefs.clearUserPref("network.dns.offline-localhost");
prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
}
10 changes: 10 additions & 0 deletions netwerk/test/unit/test_dns_originAttributes.js
Expand Up @@ -4,6 +4,9 @@ var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
var threadManager = Cc["@mozilla.org/thread-manager;1"].getService(
Ci.nsIThreadManager
);
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(
Ci.nsIPrefBranch
);
var mainThread = threadManager.currentThread;

var listener1 = {
Expand Down Expand Up @@ -31,6 +34,7 @@ var listener2 = {
var listener3 = {
onLookupComplete(inRequest, inRecord, inStatus) {
Assert.equal(inStatus, Cr.NS_ERROR_OFFLINE);
cleanup();
do_test_finished();
},
};
Expand All @@ -41,6 +45,7 @@ const secondOriginAttributes = { userContextId: 2 };
// First, we resolve the address normally for first originAttributes.
function run_test() {
do_test_pending();
prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);
dns.asyncResolve(
"localhost",
Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
Expand Down Expand Up @@ -84,6 +89,11 @@ function test3() {
);
} catch (e) {
Assert.equal(e.result, Cr.NS_ERROR_OFFLINE);
cleanup();
do_test_finished();
}
}

function cleanup() {
prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
}
4 changes: 4 additions & 0 deletions netwerk/test/unit/test_http3.js
Expand Up @@ -71,6 +71,9 @@ function run_test() {

prefs.setBoolPref("network.http.http3.enabled", true);
prefs.setCharPref("network.dns.localDomains", "foo.example.com");
// We always resolve elements of localDomains as it's hardcoded without the
// following pref:
prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);

// The certificate for the http3server server is for foo.example.com and
// is signed by http2-ca.pem so add that cert to the trust list as a
Expand Down Expand Up @@ -553,6 +556,7 @@ function test_version_fallback() {
function testsDone() {
prefs.clearUserPref("network.http.http3.enabled");
prefs.clearUserPref("network.dns.localDomains");
prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
dump("testDone\n");
do_test_pending();
h1Server.stop(do_test_finished);
Expand Down
4 changes: 4 additions & 0 deletions netwerk/test/unit/test_http3_421.js
Expand Up @@ -34,6 +34,9 @@ function run_test() {

prefs.setBoolPref("network.http.http3.enabled", true);
prefs.setCharPref("network.dns.localDomains", "foo.example.com");
// We always resolve elements of localDomains as it's hardcoded without the
// following pref:
prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);

// The certificate for the http3server server is for foo.example.com and
// is signed by http2-ca.pem so add that cert to the trust list as a
Expand Down Expand Up @@ -165,6 +168,7 @@ function test_response_421() {
function testsDone() {
prefs.clearUserPref("network.http.http3.enabled");
prefs.clearUserPref("network.dns.localDomains");
prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
dump("testDone\n");
do_test_pending();
do_test_finished();
Expand Down
4 changes: 4 additions & 0 deletions netwerk/test/unit/test_http3_alt_svc.js
Expand Up @@ -36,6 +36,9 @@ function run_test() {

prefs.setBoolPref("network.http.http3.enabled", true);
prefs.setCharPref("network.dns.localDomains", "foo.example.com");
// We always resolve elements of localDomains as it's hardcoded without the
// following pref:
prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);

// The certificate for the http3server server is for foo.example.com and
// is signed by http2-ca.pem so add that cert to the trust list as a
Expand Down Expand Up @@ -121,5 +124,6 @@ function test_https_alt_svc() {
function testsDone() {
prefs.clearUserPref("network.http.http3.enabled");
prefs.clearUserPref("network.dns.localDomains");
prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
dump("testDone\n");
}
4 changes: 4 additions & 0 deletions netwerk/test/unit/test_http3_perf.js
Expand Up @@ -76,6 +76,9 @@ function run_test() {

prefs.setBoolPref("network.http.http3.enabled", true);
prefs.setCharPref("network.dns.localDomains", "foo.example.com");
// We always resolve elements of localDomains as it's hardcoded without the
// following pref:
prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);

// The certificate for the http3server server is for foo.example.com and
// is signed by http2-ca.pem so add that cert to the trust list as a
Expand Down Expand Up @@ -252,6 +255,7 @@ function test_download() {
function testsDone() {
prefs.clearUserPref("network.http.http3.enabled");
prefs.clearUserPref("network.dns.localDomains");
prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
dump("testDone\n");
do_test_pending();
do_test_finished();
Expand Down
3 changes: 3 additions & 0 deletions netwerk/test/unit/test_ping_aboutnetworking.js
Expand Up @@ -58,9 +58,12 @@ function run_test() {
// disable network changed events to avoid the the risk of having the dns
// cache getting flushed behind our back
ps.setBoolPref("network.notify.changed", false);
// Localhost is hardcoded to loopback and isn't cached, disable that with this pref
ps.setBoolPref("network.proxy.allow_hijacking_localhost", true);

registerCleanupFunction(function() {
ps.clearUserPref("network.notify.changed");
ps.clearUserPref("network.proxy.allow_hijacking_localhost");
});

let serverSocket = Cc["@mozilla.org/network/server-socket;1"].createInstance(
Expand Down
2 changes: 2 additions & 0 deletions netwerk/test/unit/xpcshell.ini
Expand Up @@ -201,8 +201,10 @@ skip-if = true # Bug 863738
[test_data_protocol.js]
[test_dns_service.js]
[test_dns_offline.js]
skip-if = socketprocess_networking # Bug 1640105
[test_dns_onion.js]
[test_dns_originAttributes.js]
skip-if = socketprocess_networking # Bug 1640105
[test_dns_localredirect.js]
[test_dns_proxy_bypass.js]
[test_dns_disabled.js]
Expand Down
Expand Up @@ -3,7 +3,7 @@
if (os == "win") and ccov: [OK, TIMEOUT]
if (os == "win") and debug and not webrender and (processor == "x86"): ["OK", "TIMEOUT"]
if (os == "win") and debug and not webrender and (processor == "x86_64"): ["OK", "TIMEOUT"]
if (os == "win") and not debug and webrender and not fission: ["OK", "TIMEOUT"]
if (os == "win") and not debug and webrender: ["OK", "TIMEOUT"]
if (os == "win") and debug and webrender: ["TIMEOUT", "OK"]
[Initialize lineGapOverride with 'normal' should succeed]
expected: FAIL
Expand Down Expand Up @@ -70,7 +70,7 @@
if (os == "win") and ccov: [PASS, NOTRUN]
if (os == "win") and debug and not webrender and (processor == "x86_64"): ["FAIL", "NOTRUN"]
if (os == "win") and debug and not webrender and (processor == "x86"): ["FAIL", "NOTRUN"]
if (os == "win") and not debug and webrender and not fission: ["FAIL", "TIMEOUT"]
if (os == "win") and not debug and webrender: ["FAIL", "TIMEOUT"]
if (os == "win") and debug and webrender: ["NOTRUN", "FAIL"]
FAIL

Expand Down