Bug 1838498 - Extend test_speculative_connect.js to cover https r=necko-reviewers,kershaw

Extending this test to cover https since that's most connections. Tested negative case by cancelling https connections in nsHttpHandler::SpeculativeConnectInternal

Differential Revision: https://phabricator.services.mozilla.com/D180985
This commit is contained in:
Andrew Creskey 2023-06-19 10:51:21 +00:00
parent 511eebcef9
commit d4b539e54c

View File

@ -54,13 +54,15 @@ var localIPLiterals = localIPv4Literals.concat(localIPv6Literals);
/** Test function list and descriptions.
*/
var testList = [
test_speculative_connect,
test_localhost_http_speculative_connect,
test_localhost_https_speculative_connect,
test_hostnames_resolving_to_local_addresses,
test_proxies_with_local_addresses,
];
var testDescription = [
"Expect pass with localhost",
"Expect pass with localhost, http",
"Expect pass with localhost, https",
"Expect failure with resolved local IPs",
"Expect failure for proxies with local IPs",
];
@ -145,12 +147,12 @@ TestFailedStreamCallback.prototype = {
},
};
/** test_speculative_connect
/** test_localhost_http_speculative_connect
*
* Tests a basic positive case using nsIOService.SpeculativeConnect:
* connecting to localhost.
* connecting to localhost via http.
*/
function test_speculative_connect() {
function test_localhost_http_speculative_connect() {
serv = new TestServer();
var ssm = Services.scriptSecurityManager;
var URI = ios.newURI(
@ -163,6 +165,24 @@ function test_speculative_connect() {
.speculativeConnect(URI, principal, null, false);
}
/** test_localhost_https_speculative_connect
*
* Tests a basic positive case using nsIOService.SpeculativeConnect:
* connecting to localhost via https.
*/
function test_localhost_https_speculative_connect() {
serv = new TestServer();
var ssm = Services.scriptSecurityManager;
var URI = ios.newURI(
"https://localhost:" + serv.listener.port + "/just/a/test"
);
var principal = ssm.createContentPrincipal(URI, {});
ios
.QueryInterface(Ci.nsISpeculativeConnect)
.speculativeConnect(URI, principal, null, false);
}
/* Speculative connections should not be allowed for hosts with local IP
* addresses (Bug 853423). That list includes:
* -- IPv4 RFC1918 and Link Local Addresses.