зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1640091 - Add test for using PAC script with TRR r=kershaw,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D78524
This commit is contained in:
Родитель
eb72b7bc89
Коммит
b0af883a42
|
@ -68,6 +68,7 @@ function trr_clear_prefs() {
|
|||
Services.prefs.clearUserPref("network.trr.excluded-domains");
|
||||
Services.prefs.clearUserPref("network.trr.builtin-excluded-domains");
|
||||
Services.prefs.clearUserPref("network.trr.clear-cache-on-pref-change");
|
||||
Services.prefs.clearUserPref("network.trr.fetch_off_main_thread");
|
||||
Services.prefs.clearUserPref("captivedetect.canonicalURL");
|
||||
|
||||
Services.prefs.clearUserPref("network.http.spdy.enabled");
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
/* globals dnsResolve */
|
||||
|
||||
const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
|
||||
const { MockRegistrar } = ChromeUtils.import(
|
||||
"resource://testing-common/MockRegistrar.jsm"
|
||||
);
|
||||
const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
|
||||
Ci.nsIDNSService
|
||||
);
|
||||
|
||||
trr_test_setup();
|
||||
registerCleanupFunction(async () => {
|
||||
trr_clear_prefs();
|
||||
});
|
||||
|
||||
function FindProxyForURL(url, host) {
|
||||
alert(`PAC resolving: ${host}`);
|
||||
alert(dnsResolve(host));
|
||||
return "DIRECT";
|
||||
}
|
||||
|
||||
const CID = Components.ID("{5645d2c1-d6d8-4091-b117-fe7ee4027db7}");
|
||||
XPCOMUtils.defineLazyGetter(this, "systemSettings", function() {
|
||||
return {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsISystemProxySettings"]),
|
||||
|
||||
mainThreadOnly: true,
|
||||
PACURI: `data:application/x-ns-proxy-autoconfig;charset=utf-8,${encodeURIComponent(
|
||||
FindProxyForURL.toString()
|
||||
)}`,
|
||||
getProxyForURI(aURI) {
|
||||
throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
|
||||
Ci.nsINativeDNSResolverOverride
|
||||
);
|
||||
|
||||
add_task(async function test_pac_dnsResolve() {
|
||||
Services.console.reset();
|
||||
// Create a console listener.
|
||||
let consolePromise = new Promise(resolve => {
|
||||
let listener = {
|
||||
observe(message) {
|
||||
// Ignore unexpected messages.
|
||||
if (!(message instanceof Ci.nsIConsoleMessage)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.message.includes("PAC file installed from")) {
|
||||
Services.console.unregisterListener(listener);
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Services.console.registerListener(listener);
|
||||
});
|
||||
|
||||
MockRegistrar.register(
|
||||
"@mozilla.org/system-proxy-settings;1",
|
||||
systemSettings
|
||||
);
|
||||
Services.prefs.setIntPref(
|
||||
"network.proxy.type",
|
||||
Ci.nsIProtocolProxyService.PROXYCONFIG_SYSTEM
|
||||
);
|
||||
|
||||
let httpserv = new HttpServer();
|
||||
httpserv.registerPathHandler("/", function handler(metadata, response) {
|
||||
let content = "ok";
|
||||
response.setHeader("Content-Length", `${content.length}`);
|
||||
response.bodyOutputStream.write(content, content.length);
|
||||
});
|
||||
httpserv.start(-1);
|
||||
|
||||
Services.prefs.setBoolPref("network.dns.native-is-localhost", false);
|
||||
Services.prefs.setIntPref("network.trr.mode", 0); // Disable TRR until the PAC is loaded
|
||||
override.addIPOverride("example.org", "127.0.0.1");
|
||||
let chan = NetUtil.newChannel({
|
||||
uri: `http://example.org:${httpserv.identity.primaryPort}/`,
|
||||
loadUsingSystemPrincipal: true,
|
||||
}).QueryInterface(Ci.nsIHttpChannel);
|
||||
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||
await consolePromise;
|
||||
|
||||
let env = Cc["@mozilla.org/process/environment;1"].getService(
|
||||
Ci.nsIEnvironment
|
||||
);
|
||||
let h2Port = env.get("MOZHTTP2_PORT");
|
||||
Assert.notEqual(h2Port, null);
|
||||
Assert.notEqual(h2Port, "");
|
||||
|
||||
override.addIPOverride("foo.example.com", "127.0.0.1");
|
||||
Services.prefs.setCharPref(
|
||||
"network.trr.uri",
|
||||
`https://foo.example.com:${h2Port}/doh?responseIP=127.0.0.1`
|
||||
);
|
||||
|
||||
async function test_with(DOMAIN, trrMode, fetchOffMainThread) {
|
||||
Services.prefs.setIntPref("network.trr.mode", trrMode); // TRR first
|
||||
Services.prefs.setBoolPref(
|
||||
"network.trr.fetch_off_main_thread",
|
||||
fetchOffMainThread
|
||||
);
|
||||
override.addIPOverride(DOMAIN, "127.0.0.1");
|
||||
|
||||
chan = NetUtil.newChannel({
|
||||
uri: `http://${DOMAIN}:${httpserv.identity.primaryPort}/`,
|
||||
loadUsingSystemPrincipal: true,
|
||||
}).QueryInterface(Ci.nsIHttpChannel);
|
||||
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||
|
||||
await override.clearHostOverride(DOMAIN);
|
||||
}
|
||||
|
||||
await test_with("test1.com", 2, true);
|
||||
await test_with("test2.com", 3, true);
|
||||
await test_with("test3.com", 2, false);
|
||||
await test_with("test4.com", 3, false);
|
||||
await httpserv.stop();
|
||||
});
|
|
@ -433,3 +433,4 @@ skip-if = true || asan || tsan || os == 'win' || os =='android'
|
|||
[test_trr_httpssvc.js]
|
||||
[test_trr_case_sensitivity.js]
|
||||
skip-if = os == "android" || verify
|
||||
[test_trr_proxy.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче