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 certOverrideService
.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
66 chan
.asyncOpen(new ChannelListener(finish
, null, flags
));
70 // Use NodeHTTPServer to create an HTTP server and test if the Http/3 server
71 // can act as a reverse proxy.
72 add_task(async
function testHttp3ServerAsReverseProxy() {
73 trrServer
= new TRRServer();
74 await trrServer
.start();
75 Services
.dns
.clearCache(true);
76 Services
.prefs
.setIntPref("network.trr.mode", 3);
77 Services
.prefs
.setCharPref(
79 `https://foo.example.com:${trrServer.port()}/dns-query`
82 await trrServer
.registerDoHAnswers("test.h3_example.com", "HTTPS", {
85 name
: "test.h3_example.com",
91 name
: "test.h3_example.com",
93 { key
: "alpn", value
: "h3" },
94 { key
: "port", value
: h3Port
},
101 await trrServer
.registerDoHAnswers("test.h3_example.com", "A", {
104 name
: "test.h3_example.com",
113 await
new TRRDNSListener("test.h3_example.com", {
114 type
: Ci
.nsIDNSService
.RESOLVE_TYPE_HTTPSSVC
,
117 let server
= new NodeHTTPServer();
118 await server
.start();
119 registerCleanupFunction(async () => {
123 await server
.registerPathHandler("/test", (req
, resp
) => {
124 if (req
.method
=== "GET") {
126 resp
.end("got GET request");
127 } else if (req
.method
=== "POST") {
129 req
.on("data", function receivePostData(chunk
) {
130 received
+= chunk
.toString();
132 req
.on("end", function finishPost() {
139 // Tell the Http/3 server which port to forward requests.
140 let chan
= makeChan(`https://test.h3_example.com/port?${server.port()}`);
141 await
channelOpenPromise(chan
, CL_ALLOW_UNKNOWN_CL
);
144 chan
= makeChan(`https://test.h3_example.com/test`);
145 let [req
, buf
] = await
channelOpenPromise(chan
, CL_ALLOW_UNKNOWN_CL
);
146 Assert
.equal(req
.protocolVersion
, "h3");
147 Assert
.equal(buf
, "got GET request");
149 var stream
= Cc
["@mozilla.org/io/string-input-stream;1"].createInstance(
150 Ci
.nsIStringInputStream
152 stream
.setByteStringData("b".repeat(500));
155 chan
= makeChan(`https://test.h3_example.com/test`);
157 .QueryInterface(Ci
.nsIUploadChannel
)
158 .setUploadStream(stream
, "text/plain", stream
.available());
159 chan
.requestMethod
= "POST";
161 [req
, buf
] = await
channelOpenPromise(chan
, CL_ALLOW_UNKNOWN_CL
);
162 Assert
.equal(req
.protocolVersion
, "h3");
163 Assert
.equal(buf
, stream
.data
);
165 await trrServer
.stop();