/* This test checks that a TRRServiceChannel can connect to the server with a proxy. Steps: - Setup the proxy (PAC, proxy filter, and system proxy settings) - Test when "network.trr.async_connInfo" is false. In this case, every TRRServicChannel waits for the proxy info to be resolved. - Test when "network.trr.async_connInfo" is true. In this case, every TRRServicChannel uses an already created connection info to connect. - The test test_trr_uri_change() is about checking if trr connection info is updated correctly when trr uri changed.
*/
"use strict";
var { setTimeout } = ChromeUtils.importESModule( "resource://gre/modules/Timer.sys.mjs"
);
/* import-globals-from trr_common.js */
let filter;
let systemProxySettings;
let trrProxy; const pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].getService();
function setup() {
h2Port = trr_test_setup();
SetParentalControlEnabled(false);
}
async function doTest(proxySetup, delay) {
info("Verifying a basic A record");
Services.dns.clearCache(true); // Close all previous connections.
Services.obs.notifyObservers(null, "net:cancel-all-connections"); // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(resolve => setTimeout(resolve, 1000));
trrProxy = new TRRProxy();
await trrProxy.start(h2Port);
info("port=" + trrProxy.port);
await proxySetup(trrProxy.port);
if (delay) {
await new Promise(resolve => do_timeout(delay, resolve));
}
await new TRRDNSListener("bar.example.com", "2.2.2.2");
// A non-zero request count indicates that TRR requests are being routed // through the proxy. Assert.ok(
(await trrProxy.request_count()) >= 1,
`Request count should be at least 1`
);
// clean up
Services.prefs.clearUserPref("network.proxy.type");
Services.prefs.clearUserPref("network.proxy.autoconfig_url"); if (filter) {
pps.unregisterFilter(filter);
filter = null;
} if (systemProxySettings) {
MockRegistrar.unregister(systemProxySettings);
systemProxySettings = null;
}
await trrProxy.stop();
trrProxy = null;
}
add_task(async function test_trr_proxy() {
async function setupPACWithDataURL(proxyPort) { var pac = `data:text/plain, function FindProxyForURL(url, host) { return"HTTPS foo.example.com:${proxyPort}";}`;
Services.prefs.setIntPref("network.proxy.type", 2);
Services.prefs.setCharPref("network.proxy.autoconfig_url", pac);
}
async function setupPACWithHttpURL(proxyPort) {
let httpserv = new HttpServer();
httpserv.registerPathHandler("/", function handler(metadata, response) {
response.setStatusLine(metadata.httpVersion, 200, "OK");
let content = `function FindProxyForURL(url, host) { return"HTTPS foo.example.com:${proxyPort}";}`;
response.setHeader("Content-Length", `${content.length}`);
response.bodyOutputStream.write(content, content.length);
});
httpserv.start(-1);
Services.prefs.setIntPref("network.proxy.type", 2);
let pacUri = `http://127.0.0.1:${httpserv.identity.primaryPort}/`;
Services.prefs.setCharPref("network.proxy.autoconfig_url", pacUri);
function consoleMessageObserved() { returnnew Promise(resolve => {
let listener = {
QueryInterface: ChromeUtils.generateQI(["nsIConsoleListener"]),
observe(msg) { if (msg == `PAC file installed from ${pacUri}`) {
Services.console.unregisterListener(listener);
resolve();
}
},
};
Services.console.registerListener(listener);
});
}
await consoleMessageObserved();
}
async function setupProxyFilter(proxyPort) {
filter = new ProxyFilter("https", "foo.example.com", proxyPort, 0);
pps.registerFilter(filter, 10);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.