1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 const certOverrideService = Cc[
12 "@mozilla.org/security/certoverride;1"
13 ].getService(Ci.nsICertOverrideService);
14 const { TestUtils } = ChromeUtils.importESModule(
15 "resource://testing-common/TestUtils.sys.mjs"
18 add_setup(async function setup() {
19 h2Port = Services.env.get("MOZHTTP2_PORT");
20 Assert.notEqual(h2Port, null);
21 Assert.notEqual(h2Port, "");
23 h3Port = Services.env.get("MOZHTTP3_PORT_PROXY");
24 Assert.notEqual(h3Port, null);
25 Assert.notEqual(h3Port, "");
29 Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true);
30 Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true);
32 registerCleanupFunction(async () => {
34 Services.prefs.clearUserPref("network.dns.upgrade_with_https_rr");
35 Services.prefs.clearUserPref("network.dns.use_https_rr_as_altsvc");
36 Services.prefs.clearUserPref("network.dns.disablePrefetch");
37 await trrServer.stop();
40 if (mozinfo.socketprocess_networking) {
42 await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched);
46 function makeChan(url) {
47 let chan = NetUtil.newChannel({
49 loadUsingSystemPrincipal: true,
50 contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
51 }).QueryInterface(Ci.nsIHttpChannel);
55 function channelOpenPromise(chan, flags) {
56 return new Promise(resolve => {
57 function finish(req, buffer) {
58 certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
61 resolve([req, buffer]);
63 let internal = chan.QueryInterface(Ci.nsIHttpChannelInternal);
64 internal.setWaitForHTTPSSVCRecord();
65 certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
68 chan.asyncOpen(new ChannelListener(finish, null, flags));
72 // Use NodeHTTPServer to create an HTTP server and test if the Http/3 server
73 // can act as a reverse proxy.
74 add_task(async function testHttp3ServerAsReverseProxy() {
75 trrServer = new TRRServer();
76 await trrServer.start();
77 Services.dns.clearCache(true);
78 Services.prefs.setIntPref("network.trr.mode", 3);
79 Services.prefs.setCharPref(
81 `https://foo.example.com:${trrServer.port()}/dns-query`
84 await trrServer.registerDoHAnswers("test.h3_example.com", "HTTPS", {
87 name: "test.h3_example.com",
93 name: "test.h3_example.com",
95 { key: "alpn", value: "h3-29" },
96 { key: "port", value: h3Port },
103 await trrServer.registerDoHAnswers("test.h3_example.com", "A", {
106 name: "test.h3_example.com",
115 await new TRRDNSListener("test.h3_example.com", {
116 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
119 let server = new NodeHTTPServer();
120 await server.start();
121 registerCleanupFunction(async () => {
125 await server.registerPathHandler("/test", (req, resp) => {
126 if (req.method === "GET") {
128 resp.end("got GET request");
129 } else if (req.method === "POST") {
131 req.on("data", function receivePostData(chunk) {
132 received += chunk.toString();
134 req.on("end", function finishPost() {
141 // Tell the Http/3 server which port to forward requests.
142 let chan = makeChan(`https://test.h3_example.com/port?${server.port()}`);
143 await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
146 chan = makeChan(`https://test.h3_example.com/test`);
147 let [req, buf] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
148 Assert.equal(req.protocolVersion, "h3-29");
149 Assert.equal(buf, "got GET request");
151 var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
152 Ci.nsIStringInputStream
154 stream.data = "b".repeat(500);
157 chan = makeChan(`https://test.h3_example.com/test`);
159 .QueryInterface(Ci.nsIUploadChannel)
160 .setUploadStream(stream, "text/plain", stream.available());
161 chan.requestMethod = "POST";
163 [req, buf] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
164 Assert.equal(req.protocolVersion, "h3-29");
165 Assert.equal(buf, stream.data);
167 await trrServer.stop();