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, response) {
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();
54 async function sleep(time) {
55 return new Promise(resolve => {
56 do_timeout(time * 1000, resolve);
60 function makeChan(url) {
61 let chan = NetUtil.newChannel({
63 loadUsingSystemPrincipal: true,
64 }).QueryInterface(Ci.nsIHttpChannel);
66 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
70 function channelOpenPromise(chan, flags) {
71 return new Promise(resolve => {
73 new ChannelListener((req, buffer) => resolve([req, buffer]), null, flags)
80 skip_if: () => AppConstants.MOZ_SYSTEM_NSS,
82 async function testRetry0Rtt() {
84 "0rtt-alert-bad-mac.example.com",
85 "0rtt-alert-protocol-version.example.com",
86 //"0rtt-alert-unexpected.example.com", // TODO(bug 1753204): uncomment this
89 Services.prefs.setCharPref("network.dns.localDomains", retryDomains);
91 Services.prefs.setBoolPref("network.ssl_tokens_cache_enabled", true);
93 for (var i = 0; i < retryDomains.length; i++) {
95 let countOfEarlyData = handlerCount("/callback/1");
96 let chan = makeChan(`https://${retryDomains[i]}:8443`);
97 let [, buf] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
100 handlerCount("/callback/1"),
106 // The server has an anti-replay mechanism that prohibits it from
107 // accepting 0-RTT connections immediately at startup.
111 let countOfEarlyData = handlerCount("/callback/1");
112 let chan = makeChan(`https://${retryDomains[i]}:8443`);
113 let [, buf] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
116 handlerCount("/callback/1"),
117 countOfEarlyData + 1,