From 815f458666179ae116bc1aeaafc3e9c8f38da7ce Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Fri, 28 Apr 2017 16:36:57 -0700 Subject: [PATCH] Test code - Bug 1342742 - check that the app update patch dir, install dir, and working dir paths are valid. r=mhowell --- .../mozapps/update/tests/TestAUSHelper.cpp | 20 ++++ .../update/tests/data/sharedUpdateXML.js | 37 ++++++-- .../update/tests/data/xpcshellUtilsAUS.js | 93 ++++++++++++------- .../invalidArgInstallDirPathTooLongFailure.js | 47 ++++++++++ ...nvalidArgInstallDirPathTraversalFailure.js | 44 +++++++++ ...nstallWorkingDirPathNotSameFailure_win.js} | 15 ++- .../invalidArgPatchDirPathTraversalFailure.js | 43 +++++++++ ...idArgStageDirNotInInstallDirFailure_win.js | 38 ++++++++ ...lidArgWorkingDirPathLocalUNCFailure_win.js | 38 ++++++++ ...invalidArgWorkingDirPathRelativeFailure.js | 37 ++++++++ .../marAppApplyUpdateSuccess.js | 14 +-- .../marAppInUseStageFailureComplete_win.js | 1 - .../unit_base_updater/marSuccessPartial.js | 13 +-- .../tests/unit_base_updater/xpcshell.ini | 16 +++- ...validArgInstallDirPathTooLongFailureSvc.js | 47 ++++++++++ ...lidArgInstallDirPathTraversalFailureSvc.js | 44 +++++++++ ...tallWorkingDirPathNotSameFailureSvc_win.js | 38 ++++++++ ...validArgPatchDirPathTraversalFailureSvc.js | 43 +++++++++ ...rgStageDirNotInInstallDirFailureSvc_win.js | 38 ++++++++ ...ArgWorkingDirPathLocalUNCFailureSvc_win.js | 38 ++++++++ ...alidArgWorkingDirPathRelativeFailureSvc.js | 37 ++++++++ .../marAppApplyUpdateSuccessSvc.js | 14 +-- .../marAppInUseStageFailureCompleteSvc_win.js | 1 - .../marSuccessPartialSvc.js | 13 +-- .../tests/unit_service_updater/xpcshell.ini | 14 +++ 25 files changed, 690 insertions(+), 93 deletions(-) create mode 100644 toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTooLongFailure.js create mode 100644 toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTraversalFailure.js rename toolkit/mozapps/update/tests/unit_base_updater/{marWrongApplyToDirFailure_win.js => invalidArgInstallWorkingDirPathNotSameFailure_win.js} (64%) create mode 100644 toolkit/mozapps/update/tests/unit_base_updater/invalidArgPatchDirPathTraversalFailure.js create mode 100644 toolkit/mozapps/update/tests/unit_base_updater/invalidArgStageDirNotInInstallDirFailure_win.js create mode 100644 toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathLocalUNCFailure_win.js create mode 100644 toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathRelativeFailure.js create mode 100644 toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTooLongFailureSvc.js create mode 100644 toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTraversalFailureSvc.js create mode 100644 toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js create mode 100644 toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathTraversalFailureSvc.js create mode 100644 toolkit/mozapps/update/tests/unit_service_updater/invalidArgStageDirNotInInstallDirFailureSvc_win.js create mode 100644 toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathLocalUNCFailureSvc_win.js create mode 100644 toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathRelativeFailureSvc.js diff --git a/toolkit/mozapps/update/tests/TestAUSHelper.cpp b/toolkit/mozapps/update/tests/TestAUSHelper.cpp index e3c5d40af127..f71103b7a044 100644 --- a/toolkit/mozapps/update/tests/TestAUSHelper.cpp +++ b/toolkit/mozapps/update/tests/TestAUSHelper.cpp @@ -337,6 +337,26 @@ int NS_main(int argc, NS_tchar **argv) #endif } + if (!NS_tstrcmp(argv[1], NS_T("launch-service"))) { +#ifdef XP_WIN + DWORD ret = LaunchServiceSoftwareUpdateCommand(argc - 2, (LPCWSTR *)argv + 2); + if (ret != ERROR_SUCCESS) { + // 192 is used to avoid reusing a possible return value from the call to + // WaitForServiceStop + return 0x000000C0; + } + // Wait a maximum of 120 seconds. + DWORD lastState = WaitForServiceStop(SVC_NAME, 120); + if (SERVICE_STOPPED == lastState) { + return 0; + } + return lastState; +#else + // Not implemented on non-Windows platforms + return 1; +#endif + } + if (NS_tchdir(argv[1]) != 0) { return 1; } diff --git a/toolkit/mozapps/update/tests/data/sharedUpdateXML.js b/toolkit/mozapps/update/tests/data/sharedUpdateXML.js index 505ba31f22ac..9be8508ab477 100644 --- a/toolkit/mozapps/update/tests/data/sharedUpdateXML.js +++ b/toolkit/mozapps/update/tests/data/sharedUpdateXML.js @@ -37,14 +37,21 @@ const STATE_SUCCEEDED = "succeeded"; const STATE_DOWNLOAD_FAILED = "download-failed"; const STATE_FAILED = "failed"; -const LOADSOURCE_ERROR_WRONG_SIZE = 2; -const CRC_ERROR = 4; -const READ_ERROR = 6; -const WRITE_ERROR = 7; -const MAR_CHANNEL_MISMATCH_ERROR = 22; -const VERSION_DOWNGRADE_ERROR = 23; -const INVALID_APPLYTO_DIR_STAGED_ERROR = 72; -const INVALID_APPLYTO_DIR_ERROR = 74; +const LOADSOURCE_ERROR_WRONG_SIZE = 2; +const CRC_ERROR = 4; +const READ_ERROR = 6; +const WRITE_ERROR = 7; +const MAR_CHANNEL_MISMATCH_ERROR = 22; +const VERSION_DOWNGRADE_ERROR = 23; +const SERVICE_COULD_NOT_COPY_UPDATER = 49; +const SERVICE_INVALID_APPLYTO_DIR_STAGED_ERROR = 52; +const SERVICE_INVALID_APPLYTO_DIR_ERROR = 54; +const SERVICE_INVALID_INSTALL_DIR_PATH_ERROR = 55; +const SERVICE_INVALID_WORKING_DIR_PATH_ERROR = 56; +const INVALID_APPLYTO_DIR_STAGED_ERROR = 72; +const INVALID_APPLYTO_DIR_ERROR = 74; +const INVALID_INSTALL_DIR_PATH_ERROR = 75; +const INVALID_WORKING_DIR_PATH_ERROR = 76; const STATE_FAILED_DELIMETER = ": "; @@ -60,10 +67,24 @@ const STATE_FAILED_MAR_CHANNEL_MISMATCH_ERROR = STATE_FAILED + STATE_FAILED_DELIMETER + MAR_CHANNEL_MISMATCH_ERROR; const STATE_FAILED_VERSION_DOWNGRADE_ERROR = STATE_FAILED + STATE_FAILED_DELIMETER + VERSION_DOWNGRADE_ERROR; +const STATE_FAILED_SERVICE_COULD_NOT_COPY_UPDATER = + STATE_FAILED + STATE_FAILED_DELIMETER + SERVICE_COULD_NOT_COPY_UPDATER +const STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_STAGED_ERROR = + STATE_FAILED + STATE_FAILED_DELIMETER + SERVICE_INVALID_APPLYTO_DIR_STAGED_ERROR; +const STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_ERROR = + STATE_FAILED + STATE_FAILED_DELIMETER + SERVICE_INVALID_APPLYTO_DIR_ERROR; +const STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR = + STATE_FAILED + STATE_FAILED_DELIMETER + SERVICE_INVALID_INSTALL_DIR_PATH_ERROR; +const STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR = + STATE_FAILED + STATE_FAILED_DELIMETER + SERVICE_INVALID_WORKING_DIR_PATH_ERROR; const STATE_FAILED_INVALID_APPLYTO_DIR_STAGED_ERROR = STATE_FAILED + STATE_FAILED_DELIMETER + INVALID_APPLYTO_DIR_STAGED_ERROR; const STATE_FAILED_INVALID_APPLYTO_DIR_ERROR = STATE_FAILED + STATE_FAILED_DELIMETER + INVALID_APPLYTO_DIR_ERROR; +const STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR = + STATE_FAILED + STATE_FAILED_DELIMETER + INVALID_INSTALL_DIR_PATH_ERROR; +const STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR = + STATE_FAILED + STATE_FAILED_DELIMETER + INVALID_WORKING_DIR_PATH_ERROR; /** * Constructs a string representing a remote update xml file. diff --git a/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js b/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js index 78c93ce5a65e..a0804be849f2 100644 --- a/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js +++ b/toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js @@ -39,7 +39,7 @@ const URL_HTTP_UPDATE_SJS = "http://test_details/"; /* global INSTALL_LOCALE, MOZ_APP_NAME, BIN_SUFFIX, MOZ_APP_VENDOR */ /* global MOZ_APP_BASENAME, APP_BIN_SUFFIX, APP_INFO_NAME, APP_INFO_VENDOR */ /* global IS_WIN, IS_MACOSX, IS_UNIX, MOZ_VERIFY_MAR_SIGNATURE */ -/* global MOZ_VERIFY_MAR_SIGNATURE, IS_AUTHENTICODE_CHECK_ENABLED */ +/* global IS_AUTHENTICODE_CHECK_ENABLED */ load("../data/xpcshellConstantsPP.js"); function getLogSuffix() { @@ -159,8 +159,6 @@ var gGREDirOrig; var gGREBinDirOrig; var gAppDirOrig; -var gApplyToDirOverride; - // Variables are used instead of contants so tests can override these values if // necessary. var gCallbackBinFile = "callback_app" + BIN_SUFFIX; @@ -1134,18 +1132,6 @@ function getAppVersion() { return iniParser.getString("App", "Version"); } -/** - * Override the apply-to directory parameter to be passed to the updater. - * This ought to cause the updater to fail when using any value that isn't the - * default, automatically computed one. - * - * @param dir - * Complete string to use as the apply-to directory parameter. - */ -function overrideApplyToDir(dir) { - gApplyToDirOverride = dir; -} - /** * Helper function for getting the relative path to the directory where the * application binary is located (e.g. /dir.app/). @@ -1673,9 +1659,20 @@ function readServiceLogFile() { * tests. * @param aCheckSvcLog * Whether the service log should be checked for service tests. + * @param aPatchDirPath (optional) + * When specified the patch directory path to use for invalid argument + * tests otherwise the normal path will be used. + * @param aInstallDirPath (optional) + * When specified the install directory path to use for invalid + * argument tests otherwise the normal path will be used. + * @param aApplyToDirPath (optional) + * When specified the apply to / working directory path to use for + * invalid argument tests otherwise the normal path will be used. */ -function runUpdate(aExpectedStatus, aSwitchApp, aExpectedExitValue, - aCheckSvcLog) { +function runUpdate(aExpectedStatus, aSwitchApp, aExpectedExitValue, aCheckSvcLog, + aPatchDirPath, aInstallDirPath, aApplyToDirPath) { + let isInvalidArgTest = !!aPatchDirPath || !!aInstallDirPath || !!aApplyToDirPath; + let svcOriginalLog; if (IS_SERVICE_TEST) { copyFileToTestAppDir(FILE_MAINTENANCE_SERVICE_BIN, false); @@ -1690,28 +1687,37 @@ function runUpdate(aExpectedStatus, aSwitchApp, aExpectedExitValue, Assert.ok(updateBin.exists(), MSG_SHOULD_EXIST + getMsgPath(updateBin.path)); - let updatesDirPath = getUpdatesPatchDir().path; - let applyToDirPath = getApplyDirFile(null, true).path; - let stageDirPath = getStageDirFile(null, true).path; + let updatesDirPath = aPatchDirPath || getUpdatesPatchDir().path; + let installDirPath = aInstallDirPath || getApplyDirFile(null, true).path; + let applyToDirPath = aApplyToDirPath || getApplyDirFile(null, true).path; + let stageDirPath = aApplyToDirPath || getStageDirFile(null, true).path; let callbackApp = getApplyDirFile(DIR_RESOURCES + gCallbackBinFile); callbackApp.permissions = PERMS_DIRECTORY; setAppBundleModTime(); - let args = [updatesDirPath, applyToDirPath]; + let args = [updatesDirPath, installDirPath]; if (aSwitchApp) { - args[2] = gApplyToDirOverride || stageDirPath; + args[2] = stageDirPath; args[3] = "0/replace"; } else { - args[2] = gApplyToDirOverride || applyToDirPath; + args[2] = applyToDirPath; args[3] = "0"; } - args = args.concat([callbackApp.parent.path, callbackApp.path]); - args = args.concat(gCallbackArgs); - debugDump("running the updater: " + updateBin.path + " " + args.join(" ")); - if (aSwitchApp) { + let launchBin = IS_SERVICE_TEST && isInvalidArgTest ? callbackApp : updateBin; + + if (!isInvalidArgTest) { + args = args.concat([callbackApp.parent.path, callbackApp.path]); + args = args.concat(gCallbackArgs); + } else if (IS_SERVICE_TEST) { + args = ["launch-service", updateBin.path].concat(args); + } + + debugDump("launching the program: " + launchBin.path + " " + args.join(" ")); + + if (aSwitchApp && !isInvalidArgTest) { // We want to set the env vars again gShouldResetEnv = undefined; } @@ -1720,7 +1726,7 @@ function runUpdate(aExpectedStatus, aSwitchApp, aExpectedExitValue, let process = Cc["@mozilla.org/process/util;1"]. createInstance(Ci.nsIProcess); - process.init(updateBin); + process.init(launchBin); process.run(true, args, args.length); resetEnvironment(); @@ -1751,9 +1757,11 @@ function runUpdate(aExpectedStatus, aSwitchApp, aExpectedExitValue, Assert.notEqual(contents, svcOriginalLog, "the contents of the maintenanceservice.log should not " + "be the same as the original contents"); - Assert.notEqual(contents.indexOf(LOG_SVC_SUCCESSFUL_LAUNCH), -1, - "the contents of the maintenanceservice.log should " + - "contain the successful launch string"); + if (!isInvalidArgTest) { + Assert.notEqual(contents.indexOf(LOG_SVC_SUCCESSFUL_LAUNCH), -1, + "the contents of the maintenanceservice.log should " + + "contain the successful launch string"); + } } do_execute_soon(runUpdateFinished); @@ -2581,8 +2589,12 @@ function waitForHelperExit() { * @param aPostUpdateAsync * When null the updater.ini is not created otherwise this parameter * is passed to createUpdaterINI. + * @param aPostUpdateExeRelPathPrefix + * When aPostUpdateAsync null this value is ignored otherwise it is + * passed to createUpdaterINI. */ -function setupUpdaterTest(aMarFile, aPostUpdateAsync) { +function setupUpdaterTest(aMarFile, aPostUpdateAsync, + aPostUpdateExeRelPathPrefix = "") { let updatesPatchDir = getUpdatesPatchDir(); if (!updatesPatchDir.exists()) { updatesPatchDir.create(Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); @@ -2667,7 +2679,7 @@ function setupUpdaterTest(aMarFile, aPostUpdateAsync) { setupActiveUpdate(); if (aPostUpdateAsync !== null) { - createUpdaterINI(aPostUpdateAsync); + createUpdaterINI(aPostUpdateAsync, aPostUpdateExeRelPathPrefix); } setupAppFilesAsync(); @@ -2690,8 +2702,10 @@ function createUpdateSettingsINI() { * True or undefined if the post update process should be async. If * undefined ExeAsync will not be added to the updater.ini file in * order to test the default launch behavior which is async. + * @param aExeRelPathPrefix + * A string to prefix the ExeRelPath values in the updater.ini. */ -function createUpdaterINI(aIsExeAsync) { +function createUpdaterINI(aIsExeAsync, aExeRelPathPrefix) { let exeArg = "ExeArg=post-update-async\n"; let exeAsync = ""; if (aIsExeAsync !== undefined) { @@ -2703,16 +2717,23 @@ function createUpdaterINI(aIsExeAsync) { } } + if (aExeRelPathPrefix && IS_WIN) { + aExeRelPathPrefix = aExeRelPathPrefix.replace("/", "\\"); + } + + let exeRelPathMac = "ExeRelPath=" + aExeRelPathPrefix + DIR_RESOURCES + + gPostUpdateBinFile + "\n"; + let exeRelPathWin = "ExeRelPath=" + aExeRelPathPrefix + gPostUpdateBinFile + "\n"; let updaterIniContents = "[Strings]\n" + "Title=Update Test\n" + "Info=Running update test " + gTestID + "\n\n" + "[PostUpdateMac]\n" + - "ExeRelPath=" + DIR_RESOURCES + gPostUpdateBinFile + "\n" + + exeRelPathMac + exeArg + exeAsync + "\n" + "[PostUpdateWin]\n" + - "ExeRelPath=" + gPostUpdateBinFile + "\n" + + exeRelPathWin + exeArg + exeAsync; let updaterIni = getApplyDirFile(DIR_RESOURCES + FILE_UPDATER_INI, true); diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTooLongFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTooLongFailure.js new file mode 100644 index 000000000000..d54350dd3564 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTooLongFailure.js @@ -0,0 +1,47 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Too long install directory path failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR + : STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "123456789"; + if (IS_WIN) { + path = "\\" + path; + path = path.repeat(30); // 300 characters + path = "C:" + path; + } else { + path = "/" + path; + path = path.repeat(1000); // 10000 characters + } + + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, path, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTraversalFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTraversalFailure.js new file mode 100644 index 000000000000..234f495e0b10 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallDirPathTraversalFailure.js @@ -0,0 +1,44 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Install directory path traversal failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR + : STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "123456789"; + if (IS_WIN) { + path = "C:\\" + path + "\\..\\" + path; + } else { + path = "/" + path + "/../" + path; + } + + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, path, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marWrongApplyToDirFailure_win.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallWorkingDirPathNotSameFailure_win.js similarity index 64% rename from toolkit/mozapps/update/tests/unit_base_updater/marWrongApplyToDirFailure_win.js rename to toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallWorkingDirPathNotSameFailure_win.js index 7078557c62fd..1cd1dc01d48a 100644 --- a/toolkit/mozapps/update/tests/unit_base_updater/marWrongApplyToDirFailure_win.js +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgInstallWorkingDirPathNotSameFailure_win.js @@ -3,9 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* Test trying to use an apply-to directory different from the install - * directory, which should fail. - */ +/* Different install and working directories for a regular update failure */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_ERROR + : STATE_FAILED_INVALID_APPLYTO_DIR_ERROR; function run_test() { if (!setupTestCommon()) { @@ -21,11 +23,8 @@ function run_test() { * Called after the call to setupUpdaterTest finishes. */ function setupUpdaterTestFinished() { - overrideApplyToDir(getApplyDirPath() + "/../NoSuchDir"); - // If execv is used the updater process will turn into the callback process - // and the updater's return code will be that of the callback process. - runUpdate(STATE_FAILED_INVALID_APPLYTO_DIR_ERROR, false, (USE_EXECV ? 0 : 1), - false); + let path = getApplyDirFile("..", false).path; + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, path); } /** diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgPatchDirPathTraversalFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgPatchDirPathTraversalFailure.js new file mode 100644 index 000000000000..e477e619d165 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgPatchDirPathTraversalFailure.js @@ -0,0 +1,43 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Patch directory path traversal failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_PENDING_SVC : STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getUpdatesPatchDir(); + if (IS_WIN) { + path = path + "\\..\\"; + } else { + path = path + "/../"; + } + + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, path, null, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgStageDirNotInInstallDirFailure_win.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgStageDirNotInInstallDirFailure_win.js new file mode 100644 index 000000000000..092937cb4a6b --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgStageDirNotInInstallDirFailure_win.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Different install and working directories for a regular update failure */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_STAGED_ERROR + : STATE_FAILED_INVALID_APPLYTO_DIR_STAGED_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getApplyDirFile("..", false).path; + runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true, null, null, path); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathLocalUNCFailure_win.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathLocalUNCFailure_win.js new file mode 100644 index 000000000000..13b3e357f431 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathLocalUNCFailure_win.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Working directory path local UNC failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR + : STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "\\\\.\\" + getApplyDirFile(null, false).path; + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, path); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathRelativeFailure.js b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathRelativeFailure.js new file mode 100644 index 000000000000..7c95bbf50725 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_base_updater/invalidArgWorkingDirPathRelativeFailure.js @@ -0,0 +1,37 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Relative working directory path failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR + : STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, "test"); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSuccess.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSuccess.js index 9a11ab920a9a..e76233fe6a74 100644 --- a/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSuccess.js +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSuccess.js @@ -14,7 +14,10 @@ function run_test() { gTestFiles = gTestFilesCompleteSuccess; gTestDirs = gTestDirsCompleteSuccess; - setupUpdaterTest(FILE_COMPLETE_MAR, undefined); + // The third parameter will test that a full path to the post update binary + // doesn't execute. + setupUpdaterTest(FILE_COMPLETE_MAR, undefined, + getApplyDirFile(null, true).path + "/"); } /** @@ -28,13 +31,6 @@ function setupUpdaterTestFinished() { * Called after the call to runUpdateUsingApp finishes. */ function runUpdateFinished() { - checkPostUpdateAppLog(); -} - -/** - * Called after the call to checkPostUpdateAppLog finishes. - */ -function checkPostUpdateAppLogFinished() { checkAppBundleModTime(); standardInit(); Assert.equal(readStatusState(), STATE_NONE, @@ -45,7 +41,7 @@ function checkPostUpdateAppLogFinished() { "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, "the update state" + MSG_SHOULD_EQUAL); - checkPostUpdateRunningFile(true); + checkPostUpdateRunningFile(false); checkFilesAfterUpdateSuccess(getApplyDirFile); checkUpdateLogContents(LOG_COMPLETE_SUCCESS); diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageFailureComplete_win.js b/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageFailureComplete_win.js index 692272539917..b1505d58eb2a 100644 --- a/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageFailureComplete_win.js +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppInUseStageFailureComplete_win.js @@ -13,7 +13,6 @@ function run_test() { } gTestFiles = gTestFilesCompleteSuccess; gTestDirs = gTestDirsCompleteSuccess; - createUpdaterINI(false); setupUpdaterTest(FILE_COMPLETE_MAR, false); } diff --git a/toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartial.js b/toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartial.js index 01da6132c0b0..616390f55cc7 100644 --- a/toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartial.js +++ b/toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartial.js @@ -18,7 +18,9 @@ function run_test() { gTestFiles[gTestFiles.length - 2].comparePerms = 0o644; gTestDirs = gTestDirsPartialSuccess; setupDistributionDir(); - setupUpdaterTest(FILE_PARTIAL_MAR, false); + // The third parameter will test that a relative path that contains a + // directory traversal to the post update binary doesn't execute. + setupUpdaterTest(FILE_PARTIAL_MAR, false, "test/../"); } /** @@ -32,13 +34,6 @@ function setupUpdaterTestFinished() { * Called after the call to runUpdate finishes. */ function runUpdateFinished() { - checkPostUpdateAppLog(); -} - -/** - * Called after the call to checkPostUpdateAppLog finishes. - */ -function checkPostUpdateAppLogFinished() { checkAppBundleModTime(); standardInit(); Assert.equal(readStatusState(), STATE_NONE, @@ -49,7 +44,7 @@ function checkPostUpdateAppLogFinished() { "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, "the update state" + MSG_SHOULD_EQUAL); - checkPostUpdateRunningFile(true); + checkPostUpdateRunningFile(false); checkFilesAfterUpdateSuccess(getApplyDirFile); checkUpdateLogContents(LOG_PARTIAL_SUCCESS); checkDistributionDir(); diff --git a/toolkit/mozapps/update/tests/unit_base_updater/xpcshell.ini b/toolkit/mozapps/update/tests/unit_base_updater/xpcshell.ini index e46aab02af56..5ac694980950 100644 --- a/toolkit/mozapps/update/tests/unit_base_updater/xpcshell.ini +++ b/toolkit/mozapps/update/tests/unit_base_updater/xpcshell.ini @@ -10,6 +10,19 @@ tags = appupdate head = head_update.js +[invalidArgInstallDirPathTooLongFailure.js] +[invalidArgInstallDirPathTraversalFailure.js] +[invalidArgInstallWorkingDirPathNotSameFailure_win.js] +skip-if = os != 'win' +reason = Windows only test +[invalidArgPatchDirPathTraversalFailure.js] +[invalidArgStageDirNotInInstallDirFailure_win.js] +skip-if = os != 'win' +reason = Windows only test +[invalidArgWorkingDirPathLocalUNCFailure_win.js] +skip-if = os != 'win' +reason = Windows only test +[invalidArgWorkingDirPathRelativeFailure.js] [marSuccessComplete.js] [marSuccessPartial.js] [marFailurePartial.js] @@ -81,6 +94,3 @@ skip-if = os != 'win' reason = Windows only test [marAppApplyUpdateSuccess.js] [marAppApplyUpdateStageSuccess.js] -[marWrongApplyToDirFailure_win.js] -skip-if = os != 'win' -reason = Windows only test diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTooLongFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTooLongFailureSvc.js new file mode 100644 index 000000000000..d54350dd3564 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTooLongFailureSvc.js @@ -0,0 +1,47 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Too long install directory path failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR + : STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "123456789"; + if (IS_WIN) { + path = "\\" + path; + path = path.repeat(30); // 300 characters + path = "C:" + path; + } else { + path = "/" + path; + path = path.repeat(1000); // 10000 characters + } + + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, path, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTraversalFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTraversalFailureSvc.js new file mode 100644 index 000000000000..234f495e0b10 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallDirPathTraversalFailureSvc.js @@ -0,0 +1,44 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Install directory path traversal failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_INSTALL_DIR_PATH_ERROR + : STATE_FAILED_INVALID_INSTALL_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "123456789"; + if (IS_WIN) { + path = "C:\\" + path + "\\..\\" + path; + } else { + path = "/" + path + "/../" + path; + } + + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, path, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js new file mode 100644 index 000000000000..1cd1dc01d48a --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Different install and working directories for a regular update failure */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_ERROR + : STATE_FAILED_INVALID_APPLYTO_DIR_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getApplyDirFile("..", false).path; + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, path); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathTraversalFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathTraversalFailureSvc.js new file mode 100644 index 000000000000..e477e619d165 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgPatchDirPathTraversalFailureSvc.js @@ -0,0 +1,43 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Patch directory path traversal failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_PENDING_SVC : STATE_PENDING; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getUpdatesPatchDir(); + if (IS_WIN) { + path = path + "\\..\\"; + } else { + path = path + "/../"; + } + + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, path, null, null); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgStageDirNotInInstallDirFailureSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgStageDirNotInInstallDirFailureSvc_win.js new file mode 100644 index 000000000000..092937cb4a6b --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgStageDirNotInInstallDirFailureSvc_win.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Different install and working directories for a regular update failure */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_APPLYTO_DIR_STAGED_ERROR + : STATE_FAILED_INVALID_APPLYTO_DIR_STAGED_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = getApplyDirFile("..", false).path; + runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true, null, null, path); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathLocalUNCFailureSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathLocalUNCFailureSvc_win.js new file mode 100644 index 000000000000..13b3e357f431 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathLocalUNCFailureSvc_win.js @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Working directory path local UNC failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR + : STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + let path = "\\\\.\\" + getApplyDirFile(null, false).path; + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, path); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathRelativeFailureSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathRelativeFailureSvc.js new file mode 100644 index 000000000000..7c95bbf50725 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_service_updater/invalidArgWorkingDirPathRelativeFailureSvc.js @@ -0,0 +1,37 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* Relative working directory path failure test */ + +const STATE_AFTER_RUNUPDATE = + IS_SERVICE_TEST ? STATE_FAILED_SERVICE_INVALID_WORKING_DIR_PATH_ERROR + : STATE_FAILED_INVALID_WORKING_DIR_PATH_ERROR; + +function run_test() { + if (!setupTestCommon()) { + return; + } + gTestFiles = gTestFilesCompleteSuccess; + gTestDirs = gTestDirsCompleteSuccess; + setTestFilesAndDirsForFailure(); + setupUpdaterTest(FILE_COMPLETE_MAR, false); +} + +/** + * Called after the call to setupUpdaterTest finishes. + */ +function setupUpdaterTestFinished() { + runUpdate(STATE_AFTER_RUNUPDATE, false, 1, true, null, null, "test"); +} + +/** + * Called after the call to runUpdateUsingUpdater finishes. + */ +function runUpdateFinished() { + standardInit(); + checkPostUpdateRunningFile(false); + checkFilesAfterUpdateFailure(getApplyDirFile); + waitForFilesInUse(); +} diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js index 9a11ab920a9a..e76233fe6a74 100644 --- a/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js +++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js @@ -14,7 +14,10 @@ function run_test() { gTestFiles = gTestFilesCompleteSuccess; gTestDirs = gTestDirsCompleteSuccess; - setupUpdaterTest(FILE_COMPLETE_MAR, undefined); + // The third parameter will test that a full path to the post update binary + // doesn't execute. + setupUpdaterTest(FILE_COMPLETE_MAR, undefined, + getApplyDirFile(null, true).path + "/"); } /** @@ -28,13 +31,6 @@ function setupUpdaterTestFinished() { * Called after the call to runUpdateUsingApp finishes. */ function runUpdateFinished() { - checkPostUpdateAppLog(); -} - -/** - * Called after the call to checkPostUpdateAppLog finishes. - */ -function checkPostUpdateAppLogFinished() { checkAppBundleModTime(); standardInit(); Assert.equal(readStatusState(), STATE_NONE, @@ -45,7 +41,7 @@ function checkPostUpdateAppLogFinished() { "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, "the update state" + MSG_SHOULD_EQUAL); - checkPostUpdateRunningFile(true); + checkPostUpdateRunningFile(false); checkFilesAfterUpdateSuccess(getApplyDirFile); checkUpdateLogContents(LOG_COMPLETE_SUCCESS); diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseStageFailureCompleteSvc_win.js b/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseStageFailureCompleteSvc_win.js index 692272539917..b1505d58eb2a 100644 --- a/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseStageFailureCompleteSvc_win.js +++ b/toolkit/mozapps/update/tests/unit_service_updater/marAppInUseStageFailureCompleteSvc_win.js @@ -13,7 +13,6 @@ function run_test() { } gTestFiles = gTestFilesCompleteSuccess; gTestDirs = gTestDirsCompleteSuccess; - createUpdaterINI(false); setupUpdaterTest(FILE_COMPLETE_MAR, false); } diff --git a/toolkit/mozapps/update/tests/unit_service_updater/marSuccessPartialSvc.js b/toolkit/mozapps/update/tests/unit_service_updater/marSuccessPartialSvc.js index 01da6132c0b0..616390f55cc7 100644 --- a/toolkit/mozapps/update/tests/unit_service_updater/marSuccessPartialSvc.js +++ b/toolkit/mozapps/update/tests/unit_service_updater/marSuccessPartialSvc.js @@ -18,7 +18,9 @@ function run_test() { gTestFiles[gTestFiles.length - 2].comparePerms = 0o644; gTestDirs = gTestDirsPartialSuccess; setupDistributionDir(); - setupUpdaterTest(FILE_PARTIAL_MAR, false); + // The third parameter will test that a relative path that contains a + // directory traversal to the post update binary doesn't execute. + setupUpdaterTest(FILE_PARTIAL_MAR, false, "test/../"); } /** @@ -32,13 +34,6 @@ function setupUpdaterTestFinished() { * Called after the call to runUpdate finishes. */ function runUpdateFinished() { - checkPostUpdateAppLog(); -} - -/** - * Called after the call to checkPostUpdateAppLog finishes. - */ -function checkPostUpdateAppLogFinished() { checkAppBundleModTime(); standardInit(); Assert.equal(readStatusState(), STATE_NONE, @@ -49,7 +44,7 @@ function checkPostUpdateAppLogFinished() { "the update manager updateCount attribute" + MSG_SHOULD_EQUAL); Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_SUCCEEDED, "the update state" + MSG_SHOULD_EQUAL); - checkPostUpdateRunningFile(true); + checkPostUpdateRunningFile(false); checkFilesAfterUpdateSuccess(getApplyDirFile); checkUpdateLogContents(LOG_PARTIAL_SUCCESS); checkDistributionDir(); diff --git a/toolkit/mozapps/update/tests/unit_service_updater/xpcshell.ini b/toolkit/mozapps/update/tests/unit_service_updater/xpcshell.ini index fde08b7e08ae..50d4dfd24cfb 100644 --- a/toolkit/mozapps/update/tests/unit_service_updater/xpcshell.ini +++ b/toolkit/mozapps/update/tests/unit_service_updater/xpcshell.ini @@ -10,6 +10,20 @@ head = head_update.js [bootstrapSvc.js] run-sequentially = Uses the Mozilla Maintenance Service. +[invalidArgInstallDirPathTooLongFailureSvc.js] +run-sequentially = Uses the Mozilla Maintenance Service. +[invalidArgInstallDirPathTraversalFailureSvc.js] +run-sequentially = Uses the Mozilla Maintenance Service. +[invalidArgInstallWorkingDirPathNotSameFailureSvc_win.js] +run-sequentially = Uses the Mozilla Maintenance Service. +[invalidArgPatchDirPathTraversalFailureSvc.js] +run-sequentially = Uses the Mozilla Maintenance Service. +[invalidArgStageDirNotInInstallDirFailureSvc_win.js] +run-sequentially = Uses the Mozilla Maintenance Service. +[invalidArgWorkingDirPathLocalUNCFailureSvc_win.js] +run-sequentially = Uses the Mozilla Maintenance Service. +[invalidArgWorkingDirPathRelativeFailureSvc.js] +run-sequentially = Uses the Mozilla Maintenance Service. [marSuccessCompleteSvc.js] run-sequentially = Uses the Mozilla Maintenance Service. [marSuccessPartialSvc.js]