diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /netwerk/test/unit/test_trr_noPrefetch.js | |
parent | Initial commit. (diff) | |
download | thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_trr_noPrefetch.js')
-rw-r--r-- | netwerk/test/unit/test_trr_noPrefetch.js | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_trr_noPrefetch.js b/netwerk/test/unit/test_trr_noPrefetch.js new file mode 100644 index 0000000000..32b0847a46 --- /dev/null +++ b/netwerk/test/unit/test_trr_noPrefetch.js @@ -0,0 +1,174 @@ +/* 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"; + +let trrServer = null; +add_setup(async function setup() { + if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) { + return; + } + + trr_test_setup(); + Services.prefs.setBoolPref("network.dns.disablePrefetch", true); + registerCleanupFunction(async () => { + Services.prefs.clearUserPref("network.dns.disablePrefetch"); + trr_clear_prefs(); + }); + + trrServer = new TRRServer(); + registerCleanupFunction(async () => { + await trrServer.stop(); + }); + await trrServer.start(); + + Services.prefs.setCharPref( + "network.trr.uri", + `https://foo.example.com:${trrServer.port}/dns-query` + ); + Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRONLY); + + let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u"); + + // We need to define both A and AAAA responses, otherwise + // we might race and pick up the skip reason for the other request. + await trrServer.registerDoHAnswers(`myfoo.test`, "A", { + answers: [], + }); + await trrServer.registerDoHAnswers(`myfoo.test`, "AAAA", { + answers: [], + }); + + // myfoo2.test will return sever error as it's not defined + + // return nxdomain for this one + await trrServer.registerDoHAnswers(`myfoo3.test`, "A", { + flags: 0x03, + answers: [], + }); + await trrServer.registerDoHAnswers(`myfoo3.test`, "AAAA", { + flags: 0x03, + answers: [], + }); + + await trrServer.registerDoHAnswers(`alt1.example.com`, "A", { + answers: [ + { + name: "alt1.example.com", + ttl: 55, + type: "A", + flush: false, + data: "127.0.0.1", + }, + ], + }); +}); + +add_task(async function test_failure() { + let req = await new Promise(resolve => { + let chan = NetUtil.newChannel({ + uri: `http://myfoo.test/`, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); + chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE)); + }); + + equal(req.status, Cr.NS_ERROR_UNKNOWN_HOST); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode, + Ci.nsIRequest.TRR_ONLY_MODE + ); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason, + Ci.nsITRRSkipReason.TRR_NO_ANSWERS + ); + + req = await new Promise(resolve => { + let chan = NetUtil.newChannel({ + uri: `http://myfoo2.test/`, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); + chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE)); + }); + + equal(req.status, Cr.NS_ERROR_UNKNOWN_HOST); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode, + Ci.nsIRequest.TRR_ONLY_MODE + ); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason, + Ci.nsITRRSkipReason.TRR_RCODE_FAIL + ); + + req = await new Promise(resolve => { + let chan = NetUtil.newChannel({ + uri: `http://myfoo3.test/`, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); + chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE)); + }); + + equal(req.status, Cr.NS_ERROR_UNKNOWN_HOST); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode, + Ci.nsIRequest.TRR_ONLY_MODE + ); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason, + Ci.nsITRRSkipReason.TRR_NXDOMAIN + ); +}); + +add_task(async function test_success() { + let httpServer = new NodeHTTP2Server(); + await httpServer.start(); + await httpServer.registerPathHandler("/", (req, resp) => { + resp.writeHead(200); + resp.end("done"); + }); + registerCleanupFunction(async () => { + await httpServer.stop(); + }); + + let req = await new Promise(resolve => { + let chan = NetUtil.newChannel({ + uri: `https://alt1.example.com:${httpServer.port()}/`, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); + chan.asyncOpen(new ChannelListener(resolve, null, CL_ALLOW_UNKNOWN_CL)); + }); + + equal(req.status, Cr.NS_OK); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode, + Ci.nsIRequest.TRR_ONLY_MODE + ); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason, + Ci.nsITRRSkipReason.TRR_OK + ); + + // Another request to check connection reuse + req = await new Promise(resolve => { + let chan = NetUtil.newChannel({ + uri: `https://alt1.example.com:${httpServer.port()}/second`, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); + chan.asyncOpen(new ChannelListener(resolve, null, CL_ALLOW_UNKNOWN_CL)); + }); + + equal(req.status, Cr.NS_OK); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode, + Ci.nsIRequest.TRR_ONLY_MODE + ); + equal( + req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason, + Ci.nsITRRSkipReason.TRR_OK + ); +}); |