summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_retry_0rtt.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/unit/test_retry_0rtt.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_retry_0rtt.js')
-rw-r--r--netwerk/test/unit/test_retry_0rtt.js121
1 files changed, 121 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_retry_0rtt.js b/netwerk/test/unit/test_retry_0rtt.js
new file mode 100644
index 0000000000..3ccb8b9c11
--- /dev/null
+++ b/netwerk/test/unit/test_retry_0rtt.js
@@ -0,0 +1,121 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
+var httpServer = null;
+
+let handlerCallbacks = {};
+
+function listenHandler(metadata, response) {
+ info(metadata.path);
+ handlerCallbacks[metadata.path] = (handlerCallbacks[metadata.path] || 0) + 1;
+}
+
+function handlerCount(path) {
+ return handlerCallbacks[path] || 0;
+}
+
+ChromeUtils.importESModule("resource://gre/modules/AppConstants.sys.mjs");
+
+// Bug 1805371: Tests that require FaultyServer can't currently be built
+// with system NSS.
+add_setup(
+ {
+ skip_if: () => AppConstants.MOZ_SYSTEM_NSS,
+ },
+ async () => {
+ httpServer = new HttpServer();
+ httpServer.registerPrefixHandler("/callback/", listenHandler);
+ httpServer.start(-1);
+
+ registerCleanupFunction(async () => {
+ await httpServer.stop();
+ });
+
+ Services.env.set(
+ "FAULTY_SERVER_CALLBACK_PORT",
+ httpServer.identity.primaryPort
+ );
+ Services.env.set("MOZ_TLS_SERVER_0RTT", "1");
+ await asyncStartTLSTestServer(
+ "FaultyServer",
+ "../../../security/manager/ssl/tests/unit/test_faulty_server"
+ );
+ let nssComponent = Cc["@mozilla.org/psm;1"].getService(Ci.nsINSSComponent);
+ await nssComponent.asyncClearSSLExternalAndInternalSessionCache();
+ }
+);
+
+async function sleep(time) {
+ return new Promise(resolve => {
+ do_timeout(time * 1000, resolve);
+ });
+}
+
+function makeChan(url) {
+ let chan = NetUtil.newChannel({
+ uri: url,
+ loadUsingSystemPrincipal: true,
+ }).QueryInterface(Ci.nsIHttpChannel);
+
+ chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
+ return chan;
+}
+
+function channelOpenPromise(chan, flags) {
+ return new Promise(resolve => {
+ chan.asyncOpen(
+ new ChannelListener((req, buffer) => resolve([req, buffer]), null, flags)
+ );
+ });
+}
+
+add_task(
+ {
+ skip_if: () => AppConstants.MOZ_SYSTEM_NSS,
+ },
+ async function testRetry0Rtt() {
+ var retryDomains = [
+ "0rtt-alert-bad-mac.example.com",
+ "0rtt-alert-protocol-version.example.com",
+ //"0rtt-alert-unexpected.example.com", // TODO(bug 1753204): uncomment this
+ ];
+
+ Services.prefs.setCharPref("network.dns.localDomains", retryDomains);
+
+ Services.prefs.setBoolPref("network.ssl_tokens_cache_enabled", true);
+
+ for (var i = 0; i < retryDomains.length; i++) {
+ {
+ let countOfEarlyData = handlerCount("/callback/1");
+ let chan = makeChan(`https://${retryDomains[i]}:8443`);
+ let [, buf] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
+ ok(buf);
+ equal(
+ handlerCount("/callback/1"),
+ countOfEarlyData,
+ "no early data sent"
+ );
+ }
+
+ // The server has an anti-replay mechanism that prohibits it from
+ // accepting 0-RTT connections immediately at startup.
+ await sleep(1);
+
+ {
+ let countOfEarlyData = handlerCount("/callback/1");
+ let chan = makeChan(`https://${retryDomains[i]}:8443`);
+ let [, buf] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
+ ok(buf);
+ equal(
+ handlerCount("/callback/1"),
+ countOfEarlyData + 1,
+ "got early data"
+ );
+ }
+ }
+ }
+);