diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /netwerk/test/unit/test_trr_case_sensitivity.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_trr_case_sensitivity.js')
-rw-r--r-- | netwerk/test/unit/test_trr_case_sensitivity.js | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_trr_case_sensitivity.js b/netwerk/test/unit/test_trr_case_sensitivity.js new file mode 100644 index 0000000000..c2c9572fac --- /dev/null +++ b/netwerk/test/unit/test_trr_case_sensitivity.js @@ -0,0 +1,153 @@ +/* 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"; + +trr_test_setup(); +registerCleanupFunction(async () => { + trr_clear_prefs(); +}); + +function makeChan(url) { + let chan = NetUtil.newChannel({ + uri: url, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); + return chan; +} + +function channelOpenPromise(chan) { + return new Promise(resolve => { + function finish(req, buffer) { + resolve([req, buffer]); + } + chan.asyncOpen(new ChannelListener(finish)); + }); +} + +add_task(async function test_trr_casing() { + let trrServer = new TRRServer(); + registerCleanupFunction(async () => { + await trrServer.stop(); + }); + await trrServer.start(); + dump(`port = ${trrServer.port}\n`); + let chan = makeChan(`https://localhost:${trrServer.port}/test?bla=some`); + let [, resp] = await channelOpenPromise(chan); + equal(resp, "<h1> 404 Path not found: /test?bla=some</h1>"); + + Services.dns.clearCache(true); + Services.prefs.setIntPref("network.trr.mode", 3); + Services.prefs.setCharPref( + "network.trr.uri", + `https://foo.example.com:${trrServer.port}/dns-query` + ); + + // This CNAME response goes to B.example.com (uppercased) + // It should be lowercased by the code + await trrServer.registerDoHAnswers("a.example.com", "A", { + answers: [ + { + name: "a.example.com", + ttl: 55, + type: "CNAME", + flush: false, + data: "B.example.com", + }, + ], + }); + // Like in bug 1635566, the response for B.example.com will be lowercased + // by the server too -> b.example.com + // Requesting this resource would case the browser to reject the resource + await trrServer.registerDoHAnswers("B.example.com", "A", { + answers: [ + { + name: "b.example.com", + ttl: 55, + type: "CNAME", + flush: false, + data: "c.example.com", + }, + ], + }); + + // The browser should request this one + await trrServer.registerDoHAnswers("b.example.com", "A", { + answers: [ + { + name: "b.example.com", + ttl: 55, + type: "CNAME", + flush: false, + data: "c.example.com", + }, + ], + }); + // Finally, it gets an IP + await trrServer.registerDoHAnswers("c.example.com", "A", { + answers: [ + { + name: "c.example.com", + ttl: 55, + type: "A", + flush: false, + data: "1.2.3.4", + }, + ], + }); + await new TRRDNSListener("a.example.com", { expectedAnswer: "1.2.3.4" }); + + await trrServer.registerDoHAnswers("a.test.com", "A", { + answers: [ + { + name: "a.test.com", + ttl: 55, + type: "CNAME", + flush: false, + data: "B.test.com", + }, + ], + }); + // We try this again, this time we explicitly make sure this resource + // is never used + await trrServer.registerDoHAnswers("B.test.com", "A", { + answers: [ + { + name: "B.test.com", + ttl: 55, + type: "A", + flush: false, + data: "9.9.9.9", + }, + ], + }); + await trrServer.registerDoHAnswers("b.test.com", "A", { + answers: [ + { + name: "b.test.com", + ttl: 55, + type: "A", + flush: false, + data: "8.8.8.8", + }, + ], + }); + await new TRRDNSListener("a.test.com", { expectedAnswer: "8.8.8.8" }); + + await trrServer.registerDoHAnswers("CAPITAL.COM", "A", { + answers: [ + { + name: "capital.com", + ttl: 55, + type: "A", + flush: false, + data: "2.2.2.2", + }, + ], + }); + await new TRRDNSListener("CAPITAL.COM", { expectedAnswer: "2.2.2.2" }); + await new TRRDNSListener("CAPITAL.COM.", { expectedAnswer: "2.2.2.2" }); + + await trrServer.stop(); +}); |