diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /netwerk/test/unit/test_port_remapping.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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_port_remapping.js')
-rw-r--r-- | netwerk/test/unit/test_port_remapping.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_port_remapping.js b/netwerk/test/unit/test_port_remapping.js new file mode 100644 index 0000000000..537d8d6f46 --- /dev/null +++ b/netwerk/test/unit/test_port_remapping.js @@ -0,0 +1,48 @@ +// This test is checking the `network.socket.forcePort` preference has an effect. +// We remap an ilusional port `8765` to go to the port the server actually binds to. + +"use strict"; + +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); + +function make_channel(url, callback, ctx) { + return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true }); +} + +const REMAPPED_PORT = 8765; + +add_task(async function check_protocols() { + function contentHandler(metadata, response) { + let responseBody = "The server should never return this!"; + response.setHeader("Content-Type", "text/plain"); + response.bodyOutputStream.write(responseBody, responseBody.length); + } + + const httpserv = new HttpServer(); + httpserv.registerPathHandler("/content", contentHandler); + httpserv.start(-1); + + do_get_profile(); + Services.prefs.setCharPref( + "network.socket.forcePort", + `${REMAPPED_PORT}=${httpserv.identity.primaryPort}` + ); + + function get_response() { + return new Promise(resolve => { + const URL = `http://localhost:${REMAPPED_PORT}/content`; + const channel = make_channel(URL); + channel.asyncOpen( + new ChannelListener((request, data) => { + resolve(data); + }) + ); + }); + } + + // We expect "Bad request" from the test server because the server doesn't + // have identity for the remapped port. We don't want to add it too, because + // that would not prove we actualy remap the port number. + Assert.equal(await get_response(), "Bad request\n"); + await new Promise(resolve => httpserv.stop(resolve)); +}); |