1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 // The purpose of this test is to create a site security service state file
7 // and see that the site security service reads it properly.
10 let stateFile = do_get_profile();
11 stateFile.append(SSS_STATE_FILE_NAME);
12 // Assuming we're working with a clean slate, the file shouldn't exist
13 // until we create it.
14 ok(!stateFile.exists());
15 let outputStream = FileUtils.openFileOutputStream(stateFile);
18 { key: "expired.example.com", value: `${now - 100000},1,0` },
19 { key: "notexpired.example.com", value: `${now + 100000},1,0` },
20 // This overrides an entry on the preload list.
21 { key: "includesubdomains.preloaded.test", value: `${now + 100000},1,0` },
22 { key: "incsubdomain.example.com", value: `${now + 100000},1,1` },
23 // This overrides an entry on the preload list.
24 { key: "includesubdomains2.preloaded.test", value: "0,2,0" },
26 for (let keyValuePair of keyValuePairs) {
27 append_line_to_data_storage_file(
35 // Append a line with a bad checksum.
36 append_line_to_data_storage_file(
40 "badchecksum.example.com",
41 `${now + 100000},1,0`,
46 let siteSecurityService = Cc["@mozilla.org/ssservice;1"].getService(
47 Ci.nsISiteSecurityService
49 notEqual(siteSecurityService, null);
51 // The backing data storage will block until the background task that reads
52 // the backing file has finished.
54 !siteSecurityService.isSecureURI(
55 Services.io.newURI("https://expired.example.com")
59 siteSecurityService.isSecureURI(
60 Services.io.newURI("https://notexpired.example.com")
64 siteSecurityService.isSecureURI(
65 Services.io.newURI("https://includesubdomains.preloaded.test")
69 !siteSecurityService.isSecureURI(
70 Services.io.newURI("https://sub.includesubdomains.preloaded.test")
74 siteSecurityService.isSecureURI(
75 Services.io.newURI("https://incsubdomain.example.com")
79 siteSecurityService.isSecureURI(
80 Services.io.newURI("https://sub.incsubdomain.example.com")
84 !siteSecurityService.isSecureURI(
85 Services.io.newURI("https://includesubdomains2.preloaded.test")
89 !siteSecurityService.isSecureURI(
90 Services.io.newURI("https://sub.includesubdomains2.preloaded.test")
94 // Clearing the data should make everything go back to default.
95 siteSecurityService.clearAll();
97 !siteSecurityService.isSecureURI(
98 Services.io.newURI("https://expired.example.com")
102 !siteSecurityService.isSecureURI(
103 Services.io.newURI("https://notexpired.example.com")
107 siteSecurityService.isSecureURI(
108 Services.io.newURI("https://includesubdomains.preloaded.test")
112 siteSecurityService.isSecureURI(
113 Services.io.newURI("https://sub.includesubdomains.preloaded.test")
117 !siteSecurityService.isSecureURI(
118 Services.io.newURI("https://incsubdomain.example.com")
122 !siteSecurityService.isSecureURI(
123 Services.io.newURI("https://sub.incsubdomain.example.com")
127 siteSecurityService.isSecureURI(
128 Services.io.newURI("https://includesubdomains2.preloaded.test")
132 siteSecurityService.isSecureURI(
133 Services.io.newURI("https://sub.includesubdomains2.preloaded.test")
137 !siteSecurityService.isSecureURI(
138 Services.io.newURI("https://badchecksum.example.com")