tor-browser

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

test_BackupService_recoverFromSnapshotFolderIntoSelectableProfile.js (3183B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { AppConstants } = ChromeUtils.importESModule(
      7  "resource://gre/modules/AppConstants.sys.mjs"
      8 );
      9 const { ArchiveUtils } = ChromeUtils.importESModule(
     10  "resource:///modules/backup/ArchiveUtils.sys.mjs"
     11 );
     12 const { JsonSchema } = ChromeUtils.importESModule(
     13  "resource://gre/modules/JsonSchema.sys.mjs"
     14 );
     15 
     16 /**
     17 * Tests that if the backup-manifest.json provides an appName different from
     18 * AppConstants.MOZ_APP_NAME of the currently running application, then
     19 * recoverFromSnapshotFolderIntoSelectableProfile should throw an exception.
     20 */
     21 add_task(async function test_different_appName() {
     22  let testRecoveryPath = await IOUtils.createUniqueDirectory(
     23    PathUtils.tempDir,
     24    "testDifferentAppName"
     25  );
     26 
     27  let meta = Object.assign({}, FAKE_METADATA);
     28  meta.appName = "Some other application";
     29  Assert.notEqual(
     30    meta.appName,
     31    AppConstants.MOZ_APP_NAME,
     32    "Set up a different appName in the manifest correctly."
     33  );
     34 
     35  let manifest = {
     36    version: ArchiveUtils.SCHEMA_VERSION,
     37    meta,
     38    resources: {},
     39  };
     40  let schema = await BackupService.MANIFEST_SCHEMA;
     41  let validationResult = JsonSchema.validate(manifest, schema);
     42  Assert.ok(validationResult.valid, "Schema matches manifest");
     43 
     44  await IOUtils.writeJSON(
     45    PathUtils.join(testRecoveryPath, BackupService.MANIFEST_FILE_NAME),
     46    manifest
     47  );
     48 
     49  let bs = new BackupService();
     50  // This should reject and mention the invalid appName from the manifest.
     51  await Assert.rejects(
     52    bs.recoverFromSnapshotFolderIntoSelectableProfile(testRecoveryPath),
     53    new RegExp(`${meta.appName}`)
     54  );
     55 
     56  await IOUtils.remove(testRecoveryPath, { recursive: true });
     57 });
     58 
     59 /**
     60 * Tests that if the backup-manifest.json provides an appVersion greater than
     61 * AppConstants.MOZ_APP_VERSION of the currently running application, then
     62 * recoverFromSnapshotFolderIntoSelectableProfile should throw an exception.
     63 */
     64 add_task(async function test_newer_appVersion() {
     65  let testRecoveryPath = await IOUtils.createUniqueDirectory(
     66    PathUtils.tempDir,
     67    "testNewerAppVersion"
     68  );
     69 
     70  let meta = Object.assign({}, FAKE_METADATA);
     71  // Hopefully this static version number will do for now.
     72  meta.appVersion = "999.0.0";
     73  Assert.equal(
     74    Services.vc.compare(AppConstants.MOZ_APP_VERSION, meta.appVersion),
     75    -1,
     76    "The current application version is less than 999.0.0."
     77  );
     78 
     79  let manifest = {
     80    version: ArchiveUtils.SCHEMA_VERSION,
     81    meta,
     82    resources: {},
     83  };
     84  let schema = await BackupService.MANIFEST_SCHEMA;
     85  let validationResult = JsonSchema.validate(manifest, schema);
     86  Assert.ok(validationResult.valid, "Schema matches manifest");
     87 
     88  await IOUtils.writeJSON(
     89    PathUtils.join(testRecoveryPath, BackupService.MANIFEST_FILE_NAME),
     90    manifest
     91  );
     92 
     93  let bs = new BackupService();
     94  // This should reject and mention the invalid appVersion from the manifest.
     95  await Assert.rejects(
     96    bs.recoverFromSnapshotFolderIntoSelectableProfile(testRecoveryPath),
     97    new RegExp(`${meta.appVersion}`)
     98  );
     99 
    100  await IOUtils.remove(testRecoveryPath, { recursive: true });
    101 });