зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1552176 - Unit test for TRRMode for individual channels r=dragana
Differential Revision: https://phabricator.services.mozilla.com/D48362 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
27252b4558
Коммит
236b69b1c0
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { NodeServer } = ChromeUtils.import("resource://testing-common/httpd.js");
|
const { NodeServer, HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
|
||||||
const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
|
const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
|
||||||
Ci.nsIDNSService
|
Ci.nsIDNSService
|
||||||
);
|
);
|
||||||
|
@ -144,7 +144,6 @@ class DNSListener {
|
||||||
return this.promise.then.apply(this.promise, arguments);
|
return this.promise.then.apply(this.promise, arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_task(async function test0_nodeExecute() {
|
add_task(async function test0_nodeExecute() {
|
||||||
// This test checks that moz-http2.js running in node is working.
|
// This test checks that moz-http2.js running in node is working.
|
||||||
// This should always be the first test in this file (except for setup)
|
// This should always be the first test in this file (except for setup)
|
||||||
|
@ -156,6 +155,126 @@ add_task(async function test0_nodeExecute() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function makeChan(url, mode) {
|
||||||
|
let chan = NetUtil.newChannel({
|
||||||
|
uri: url,
|
||||||
|
loadUsingSystemPrincipal: true,
|
||||||
|
}).QueryInterface(Ci.nsIHttpChannel);
|
||||||
|
chan.setTRRMode(mode);
|
||||||
|
return chan;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_task(async function test_trr_flags() {
|
||||||
|
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);
|
||||||
|
const URL = `http://example.com:${httpserv.identity.primaryPort}/`;
|
||||||
|
|
||||||
|
dns.clearCache(true);
|
||||||
|
Services.prefs.setCharPref(
|
||||||
|
"network.trr.uri",
|
||||||
|
`https://localhost:${h2Port}/doh?responseIP=127.9.0.9`
|
||||||
|
);
|
||||||
|
|
||||||
|
Services.prefs.setIntPref("network.trr.mode", 0);
|
||||||
|
dns.clearCache(true);
|
||||||
|
let chan = makeChan(URL, Ci.nsIRequest.TRR_DEFAULT_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
equal(chan.getTRRMode(), Ci.nsIRequest.TRR_DEFAULT_MODE);
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_DISABLED_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
equal(chan.getTRRMode(), Ci.nsIRequest.TRR_DISABLED_MODE);
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_FIRST_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
equal(chan.getTRRMode(), Ci.nsIRequest.TRR_FIRST_MODE);
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(
|
||||||
|
`http://example.com:${httpserv.identity.primaryPort}/`,
|
||||||
|
Ci.nsIRequest.TRR_ONLY_MODE
|
||||||
|
);
|
||||||
|
// Should fail as it tries to connect to local but unavailable IP
|
||||||
|
await new Promise(resolve =>
|
||||||
|
chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE))
|
||||||
|
);
|
||||||
|
equal(chan.getTRRMode(), Ci.nsIRequest.TRR_ONLY_MODE);
|
||||||
|
|
||||||
|
dns.clearCache(true);
|
||||||
|
Services.prefs.setCharPref(
|
||||||
|
"network.trr.uri",
|
||||||
|
`https://localhost:${h2Port}/doh?responseIP=127.9.2.9`
|
||||||
|
);
|
||||||
|
Services.prefs.setIntPref("network.trr.mode", 2);
|
||||||
|
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_DEFAULT_MODE);
|
||||||
|
// Does get the IP from TRR, but failure means it falls back to DNS.
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_DISABLED_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
dns.clearCache(true);
|
||||||
|
// Does get the IP from TRR, but failure means it falls back to DNS.
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_FIRST_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_ONLY_MODE);
|
||||||
|
await new Promise(resolve =>
|
||||||
|
chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE))
|
||||||
|
);
|
||||||
|
|
||||||
|
dns.clearCache(true);
|
||||||
|
Services.prefs.setCharPref(
|
||||||
|
"network.trr.uri",
|
||||||
|
`https://localhost:${h2Port}/doh?responseIP=127.9.3.9`
|
||||||
|
);
|
||||||
|
Services.prefs.setIntPref("network.trr.mode", 3);
|
||||||
|
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_DEFAULT_MODE);
|
||||||
|
await new Promise(resolve =>
|
||||||
|
chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE))
|
||||||
|
);
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_DISABLED_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_FIRST_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_ONLY_MODE);
|
||||||
|
await new Promise(resolve =>
|
||||||
|
chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE))
|
||||||
|
);
|
||||||
|
|
||||||
|
dns.clearCache(true);
|
||||||
|
Services.prefs.setIntPref("network.trr.mode", 5);
|
||||||
|
Services.prefs.setCharPref(
|
||||||
|
"network.trr.uri",
|
||||||
|
`https://localhost:${h2Port}/doh?responseIP=1.1.1.1`
|
||||||
|
);
|
||||||
|
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_DEFAULT_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_DISABLED_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_FIRST_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
dns.clearCache(true);
|
||||||
|
chan = makeChan(URL, Ci.nsIRequest.TRR_ONLY_MODE);
|
||||||
|
await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve)));
|
||||||
|
|
||||||
|
await new Promise(resolve => httpserv.stop(resolve));
|
||||||
|
});
|
||||||
|
|
||||||
// verify basic A record
|
// verify basic A record
|
||||||
add_task(async function test1() {
|
add_task(async function test1() {
|
||||||
dns.clearCache(true);
|
dns.clearCache(true);
|
||||||
|
@ -1009,9 +1128,9 @@ add_task(async function test_connection_closed_no_bootstrap_localhost() {
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(async function test_connection_closed_no_bootstrap_no_excluded() {
|
add_task(async function test_connection_closed_no_bootstrap_no_excluded() {
|
||||||
// This test exists to document what happens when we're in TRR only mode
|
// This test makes sure that even in mode 3 without a bootstrap address
|
||||||
// and we don't set a bootstrap address. We use DNS to resolve the
|
// we are able to restart the TRR connection if it drops - the TRR service
|
||||||
// initial URI, but if the connection fails, we don't fallback to DNS
|
// channel will use regular DNS to resolve the TRR address.
|
||||||
dns.clearCache(true);
|
dns.clearCache(true);
|
||||||
Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
|
Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
|
||||||
Services.prefs.setCharPref("network.trr.excluded-domains", "");
|
Services.prefs.setCharPref("network.trr.excluded-domains", "");
|
||||||
|
@ -1031,11 +1150,8 @@ add_task(async function test_connection_closed_no_bootstrap_no_excluded() {
|
||||||
!Components.isSuccessCode(inStatus),
|
!Components.isSuccessCode(inStatus),
|
||||||
`${inStatus} should be an error code`
|
`${inStatus} should be an error code`
|
||||||
);
|
);
|
||||||
[, , inStatus] = await new DNSListener("bar2.example.com", undefined, false);
|
dns.clearCache(true);
|
||||||
Assert.ok(
|
await new DNSListener("bar2.example.com", "3.3.3.3");
|
||||||
!Components.isSuccessCode(inStatus),
|
|
||||||
`${inStatus} should be an error code`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(async function test_connection_closed_trr_first() {
|
add_task(async function test_connection_closed_trr_first() {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче