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/. */
7 const { HttpServer
} = ChromeUtils
.importESModule(
8 "resource://testing-common/httpd.sys.mjs"
10 var httpServer
= null;
12 let handlerCallbacks
= {};
14 function listenHandler(metadata
) {
16 handlerCallbacks
[metadata
.path
] = (handlerCallbacks
[metadata
.path
] || 0) + 1;
19 function handlerCount(path
) {
20 return handlerCallbacks
[path
] || 0;
23 ChromeUtils
.importESModule("resource://gre/modules/AppConstants.sys.mjs");
25 // Bug 1805371: Tests that require FaultyServer can't currently be built
29 skip_if
: () => AppConstants
.MOZ_SYSTEM_NSS
,
32 httpServer
= new HttpServer();
33 httpServer
.registerPrefixHandler("/callback/", listenHandler
);
36 registerCleanupFunction(async () => {
37 await httpServer
.stop();
41 "FAULTY_SERVER_CALLBACK_PORT",
42 httpServer
.identity
.primaryPort
44 Services
.env
.set("MOZ_TLS_SERVER_0RTT", "1");
45 await
asyncStartTLSTestServer(
47 "../../../security/manager/ssl/tests/unit/test_faulty_server"
49 let nssComponent
= Cc
["@mozilla.org/psm;1"].getService(Ci
.nsINSSComponent
);
50 await nssComponent
.asyncClearSSLExternalAndInternalSessionCache();
53 Services
.prefs
.setIntPref("network.http.speculative-parallel-limit", 0);
54 registerCleanupFunction(async () => {
55 Services
.prefs
.clearUserPref("network.http.speculative-parallel-limit");
60 async
function sleep(time
) {
61 return new Promise(resolve
=> {
62 do_timeout(time
* 1000, resolve
);
66 function makeChan(url
) {
67 let chan
= NetUtil
.newChannel({
69 loadUsingSystemPrincipal
: true,
70 }).QueryInterface(Ci
.nsIHttpChannel
);
72 chan
.loadFlags
= Ci
.nsIChannel
.LOAD_INITIAL_DOCUMENT_URI
;
76 function channelOpenPromise(chan
, flags
) {
77 return new Promise(resolve
=> {
79 new ChannelListener((req
, buffer
) => resolve([req
, buffer
]), null, flags
)
86 skip_if
: () => AppConstants
.MOZ_SYSTEM_NSS
,
88 async
function testRetry0Rtt() {
90 "0rtt-alert-bad-mac.example.com",
91 "0rtt-alert-protocol-version.example.com",
92 "0rtt-alert-unexpected.example.com",
95 Services
.prefs
.setCharPref("network.dns.localDomains", retryDomains
);
97 Services
.prefs
.setBoolPref("network.ssl_tokens_cache_enabled", true);
99 for (var i
= 0; i
< retryDomains
.length
; i
++) {
101 let countOfEarlyData
= handlerCount("/callback/1");
102 let chan
= makeChan(`https://${retryDomains[i]}:8443`);
103 let [, buf
] = await
channelOpenPromise(chan
, CL_ALLOW_UNKNOWN_CL
);
106 handlerCount("/callback/1"),
112 // The server has an anti-replay mechanism that prohibits it from
113 // accepting 0-RTT connections immediately at startup.
117 let countOfEarlyData
= handlerCount("/callback/1");
118 let chan
= makeChan(`https://${retryDomains[i]}:8443`);
119 let [, buf
] = await
channelOpenPromise(chan
, CL_ALLOW_UNKNOWN_CL
);
122 handlerCount("/callback/1"),
123 countOfEarlyData
+ 1,