tor-browser

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

test_readonly-immutable-nolock_vfs.js (1798B)


      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 
      5 // This file tests the readonly-immutable-nolock VFS.
      6 
      7 add_task(async function test() {
      8  const path = PathUtils.join(PathUtils.profileDir, "ro");
      9  await IOUtils.makeDirectory(path);
     10  const dbpath = PathUtils.join(path, "test-immutable.sqlite");
     11 
     12  let conn = await Sqlite.openConnection({ path: dbpath });
     13  await conn.execute("PRAGMA journal_mode = WAL");
     14  await conn.execute("CREATE TABLE test (id INTEGER PRIMARY KEY)");
     15  Assert.ok(await IOUtils.exists(dbpath + "-wal"), "wal journal exists");
     16  await conn.close();
     17 
     18  // The wal should have been merged at this point, but just in case...
     19  info("Remove auxiliary files and set the folder as readonly");
     20  await IOUtils.remove(dbpath + "-wal", { ignoreAbsent: true });
     21  await IOUtils.setPermissions(path, 0o555);
     22  registerCleanupFunction(async () => {
     23    await IOUtils.setPermissions(path, 0o777);
     24    await IOUtils.remove(path, { recursive: true });
     25  });
     26 
     27  // Windows doesn't disallow creating files in read only folders.
     28  if (AppConstants.platform == "macosx" || AppConstants.platform == "linux") {
     29    await Assert.rejects(
     30      Sqlite.openConnection({ path: dbpath, readOnly: true }),
     31      /NS_ERROR_FILE/,
     32      "Should not be able to open the db because it can't create a wal journal"
     33    );
     34  }
     35 
     36  // Open the database with ignoreLockingMode.
     37  let conn2 = await Sqlite.openConnection({
     38    path: dbpath,
     39    ignoreLockingMode: true,
     40  });
     41  await conn2.execute("SELECT * FROM sqlite_master");
     42  Assert.ok(
     43    !(await IOUtils.exists(dbpath + "-wal")),
     44    "wal journal was not created"
     45  );
     46  await conn2.close();
     47 });