1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 // Ensures nsISiteSecurityService APIs respects origin attributes.
11 const GOOD_MAX_AGE_SECONDS = 69403;
12 const GOOD_MAX_AGE = `max-age=${GOOD_MAX_AGE_SECONDS};`;
14 do_get_profile(); // must be done before instantiating nsIX509CertDB
16 let sss = Cc["@mozilla.org/ssservice;1"].getService(Ci.nsISiteSecurityService);
17 let host = "a.pinning.example.com";
18 let uri = Services.io.newURI("https://" + host);
20 // Check if originAttributes1 and originAttributes2 are isolated with respect
22 function doTest(originAttributes1, originAttributes2, shouldShare) {
24 let header = GOOD_MAX_AGE;
25 // Set HSTS for originAttributes1.
26 sss.processHeader(uri, header, originAttributes1);
28 sss.isSecureURI(uri, originAttributes1),
29 "URI should be secure given original origin attributes"
32 sss.isSecureURI(uri, originAttributes2),
34 "URI should be secure given different origin attributes if and " +
35 "only if shouldShare is true"
39 // Remove originAttributes2 from the storage.
40 sss.resetState(uri, originAttributes2);
42 sss.isSecureURI(uri, originAttributes1),
43 "URI should still be secure given original origin attributes"
47 // Remove originAttributes1 from the storage.
48 sss.resetState(uri, originAttributes1);
50 !sss.isSecureURI(uri, originAttributes1),
51 "URI should not be secure after removeState"
57 function testInvalidOriginAttributes(originAttributes) {
58 let header = GOOD_MAX_AGE;
61 () => sss.processHeader(uri, header, originAttributes),
62 () => sss.isSecureURI(uri, originAttributes),
63 () => sss.resetState(uri, originAttributes),
66 for (let callback of callbacks) {
69 /NS_ERROR_ILLEGAL_VALUE/,
70 "Should get an error with invalid origin attributes"
78 let originAttributesList = [];
79 for (let userContextId of [0, 1, 2]) {
80 for (let firstPartyDomain of ["", "foo.com", "bar.com"]) {
81 originAttributesList.push({ userContextId, firstPartyDomain });
84 for (let attrs1 of originAttributesList) {
85 for (let attrs2 of originAttributesList) {
86 // SSS storage is not isolated by userContext
90 attrs1.firstPartyDomain == attrs2.firstPartyDomain
96 { partitionKey: "(http,example.com,8443)" },
97 { partitionKey: "(https,example.com)" },
101 testInvalidOriginAttributes(undefined);
102 testInvalidOriginAttributes(null);
103 testInvalidOriginAttributes(1);
104 testInvalidOriginAttributes("foo");