test_sss_migration.js (2141B)
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/. */ 4 "use strict"; 5 6 // The purpose of this test is to create a site security service state file 7 // and see that the site security service reads and migrates it properly. 8 9 function run_test() { 10 let profileDir = do_get_profile(); 11 let stateFile = profileDir.clone(); 12 stateFile.append(SSS_STATE_OLD_FILE_NAME); 13 // Assuming we're working with a clean slate, the file shouldn't exist 14 // until we create it. 15 ok(!stateFile.exists()); 16 let outputStream = FileUtils.openFileOutputStream(stateFile); 17 let now = Date.now(); 18 let lines = []; 19 lines.push( 20 `no-origin-attributes.example.com:HSTS\t0\t0\t${now + 100000},1,0` 21 ); 22 lines.push(`not-hsts.example.com:HPKP\t0\t0\t${now + 100000},1,0`); 23 lines.push( 24 `with-port.example.com^partitionKey=%28http%2Cexample.com%2C8443%29:HSTS\t0\t0\t${ 25 now + 100000 26 },1,0` 27 ); 28 for (let i = 0; lines.length < 1024; i++) { 29 lines.push(`filler-${i}.example.com:HPKP\t0\t0\t${now + 100000},1,0`); 30 } 31 writeLinesAndClose(lines, outputStream); 32 let sss = Cc["@mozilla.org/ssservice;1"].getService( 33 Ci.nsISiteSecurityService 34 ); 35 notEqual(sss, null); 36 37 // nsISiteSecurityService.isSecureURI will block until the backing file is read. 38 ok( 39 sss.isSecureURI( 40 Services.io.newURI("https://no-origin-attributes.example.com") 41 ) 42 ); 43 ok(!sss.isSecureURI(Services.io.newURI("https://not-hsts.example.com"))); 44 ok( 45 sss.isSecureURI(Services.io.newURI("https://with-port.example.com"), { 46 partitionKey: "(http,example.com,8443)", 47 }) 48 ); 49 ok( 50 sss.isSecureURI(Services.io.newURI("https://with-port.example.com"), { 51 partitionKey: "(http,example.com)", 52 }) 53 ); 54 ok( 55 sss.isSecureURI(Services.io.newURI("https://with-port.example.com"), { 56 partitionKey: "(http,example.com,8000)", 57 }) 58 ); 59 ok( 60 sss.isSecureURI(Services.io.newURI("https://with-port.example.com"), { 61 partitionKey: "(https,example.com)", 62 }) 63 ); 64 }