Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test runs only with pattern: os != 'android'
- Manifest: toolkit/components/ipprotection/tests/xpcshell/xpcshell.toml
/* 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
"use strict";
const { IPPProxyableRuleProvider } = ChromeUtils.importESModule(
"moz-src:///toolkit/components/ipprotection/IPPSiteRuleProviders.sys.mjs"
);
const makePrincipal = url =>
Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI(url),
{}
);
const provider = new IPPProxyableRuleProvider();
/**
* Only http(s) traffic can be proxied, so anything else is EXCLUDED. A missing
* principal is treated the same way, which is what makes the channel path fail
* safe when it cannot attribute a channel to an origin.
*/
add_task(function test_non_http_schemes_are_excluded() {
Assert.equal(
provider.getRule(makePrincipal(url)),
IPPPrincipalRules.EXCLUDED,
`${url} -> EXCLUDED`
);
}
Assert.equal(
provider.getRule(null),
IPPPrincipalRules.EXCLUDED,
"missing principal -> EXCLUDED"
);
});
/**
* A null principal's scheme is moz-nullprincipal even when it backs real
* http(s) content (e.g. a sandboxed iframe), so the scheme says nothing about
* whether the traffic should be proxied and the provider must abstain.
*/
add_task(function test_null_principal_is_not_excluded_on_scheme() {
Assert.equal(
provider.getRule(Services.scriptSecurityManager.createNullPrincipal({})),
null,
"null principal -> no opinion"
);
});
/**
* Loopback hosts and LAN addresses never leave the machine or the local
* network, so proxying them is pointless and breaks local development.
*/
add_task(function test_local_connections_are_excluded() {
const tests = [
// True either LAN or Loopback
// False, anything else
];
for (const [url, isLocal] of tests) {
Assert.equal(
provider.getRule(makePrincipal(url)),
isLocal ? IPPPrincipalRules.EXCLUDED : null,
url
);
}
});
/**
* A normal https site is left to the providers further down the list.
*/
add_task(function test_proxyable_site_abstains() {
Assert.equal(
null,
"plain https principal -> no opinion"
);
});