summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSkippedWriteAccess_win.js
blob: aa1336b7ed6f592d1e9f99e88d194e3304228c1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

/**
 * Test an update isn't attempted when the update.status file can't be written
 * to.
 */

async function run_test() {
  if (!setupTestCommon()) {
    return;
  }
  gTestFiles = gTestFilesCompleteSuccess;
  gTestDirs = gTestDirsCompleteSuccess;
  setTestFilesAndDirsForFailure();
  await setupUpdaterTest(FILE_COMPLETE_MAR, false);

  // To simulate a user that doesn't have write access to the update directory
  // lock the relevant files in the update directory.
  let filesToLock = [
    FILE_ACTIVE_UPDATE_XML,
    FILE_UPDATE_MAR,
    FILE_UPDATE_STATUS,
    FILE_UPDATE_TEST,
    FILE_UPDATE_VERSION,
  ];
  filesToLock.forEach(function (aFileLeafName) {
    let file = getUpdateDirFile(aFileLeafName);
    if (!file.exists()) {
      file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o444);
    }
    file.QueryInterface(Ci.nsILocalFileWin);
    file.readOnly = true;
    Assert.ok(file.exists(), MSG_SHOULD_EXIST + getMsgPath(file.path));
    Assert.ok(!file.isWritable(), "the file should not be writeable");
  });

  registerCleanupFunction(() => {
    filesToLock.forEach(function (aFileLeafName) {
      let file = getUpdateDirFile(aFileLeafName);
      if (file.exists()) {
        file.QueryInterface(Ci.nsILocalFileWin);
        file.readOnly = false;
        file.remove(false);
      }
    });
  });

  // Reload the update manager now that the update directory files are locked.
  reloadUpdateManagerData();
  await runUpdateUsingApp(STATE_PENDING);
  standardInit();
  checkPostUpdateRunningFile(false);
  checkFilesAfterUpdateFailure(getApplyDirFile);
  checkUpdateManager(STATE_PENDING, false, STATE_NONE, 0, 0);

  let dir = getUpdateDirFile(DIR_PATCH);
  Assert.ok(dir.exists(), MSG_SHOULD_EXIST + getMsgPath(dir.path));

  let file = getUpdateDirFile(FILE_UPDATES_XML);
  Assert.ok(!file.exists(), MSG_SHOULD_NOT_EXIST + getMsgPath(file.path));

  file = getUpdateDirFile(FILE_UPDATE_LOG);
  Assert.ok(!file.exists(), MSG_SHOULD_NOT_EXIST + getMsgPath(file.path));

  file = getUpdateDirFile(FILE_LAST_UPDATE_LOG);
  Assert.ok(!file.exists(), MSG_SHOULD_NOT_EXIST + getMsgPath(file.path));

  file = getUpdateDirFile(FILE_BACKUP_UPDATE_LOG);
  Assert.ok(!file.exists(), MSG_SHOULD_NOT_EXIST + getMsgPath(file.path));

  waitForFilesInUse();
}