tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_sss_eviction.js (1578B)


      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 check that a frequently visited site
      7 // will not be evicted over an infrequently visited site.
      8 function run_test() {
      9  let stateFile = do_get_profile();
     10  stateFile.append(SSS_STATE_FILE_NAME);
     11  // Assuming we're working with a clean slate, the file shouldn't exist
     12  // until we create it.
     13  ok(!stateFile.exists());
     14  let outputStream = FileUtils.openFileOutputStream(stateFile);
     15  let now = new Date().getTime();
     16  let key = "frequentlyused.example.com";
     17  let value = `${now + 100000},1,0`;
     18  append_line_to_data_storage_file(outputStream, 4, 1000, key, value);
     19  outputStream.close();
     20  let siteSecurityService = Cc["@mozilla.org/ssservice;1"].getService(
     21    Ci.nsISiteSecurityService
     22  );
     23  notEqual(siteSecurityService, null);
     24  // isSecureURI blocks until the backing data is read.
     25  ok(
     26    siteSecurityService.isSecureURI(
     27      Services.io.newURI("https://frequentlyused.example.com")
     28    )
     29  );
     30  // The storage limit is currently 2048, so this should cause evictions.
     31  for (let i = 0; i < 3000; i++) {
     32    let uri = Services.io.newURI("http://bad" + i + ".example.com");
     33    siteSecurityService.processHeader(uri, "max-age=1000");
     34  }
     35  // The frequently used entry should not be evicted.
     36  ok(
     37    siteSecurityService.isSecureURI(
     38      Services.io.newURI("https://frequentlyused.example.com")
     39    )
     40  );
     41 }