diff --git a/toolkit/mozapps/update/test/unit/data/old_version_mar.mar b/toolkit/mozapps/update/test/unit/data/old_version_mar.mar new file mode 100644 index 00000000000..31550698a0f Binary files /dev/null and b/toolkit/mozapps/update/test/unit/data/old_version_mar.mar differ diff --git a/toolkit/mozapps/update/test/unit/data/wrong_product_channel_mar.mar b/toolkit/mozapps/update/test/unit/data/wrong_product_channel_mar.mar new file mode 100644 index 00000000000..1e39cc214f9 Binary files /dev/null and b/toolkit/mozapps/update/test/unit/data/wrong_product_channel_mar.mar differ diff --git a/toolkit/mozapps/update/test/unit/head_update.js.in b/toolkit/mozapps/update/test/unit/head_update.js.in index a21d67aeee3..4be57247fcf 100644 --- a/toolkit/mozapps/update/test/unit/head_update.js.in +++ b/toolkit/mozapps/update/test/unit/head_update.js.in @@ -87,11 +87,14 @@ const APPLY_TO_DIR_SUFFIX = "_applyToDir/"; const HELPER_BIN_FILE = "TestAUSHelper" + BIN_SUFFIX; const MAR_COMPLETE_FILE = "data/complete.mar"; const MAR_PARTIAL_FILE = "data/partial.mar"; +const MAR_OLD_VERSION_FILE = "data/old_version_mar.mar"; +const MAR_WRONG_CHANNEL_FILE = "data/wrong_product_channel_mar.mar"; const UPDATER_BIN_FILE = "updater" + BIN_SUFFIX; const MAINTENANCE_SERVICE_BIN_FILE = "maintenanceservice.exe"; const MAINTENANCE_SERVICE_INSTALLER_BIN_FILE = "maintenanceservice_installer.exe"; const UPDATE_SETTINGS_INI_FILE = "update-settings.ini"; -const UPDATE_SETTINGS_CONTENTS = "[Settings]\nMAR_CHANNEL_ID=xpcshell-test\n" +const UPDATE_SETTINGS_CONTENTS = "[Settings]\n" + + "ACCEPTED_MAR_CHANNEL_IDS=xpcshell-test\n" const UPDATES_DIR_SUFFIX = "_mar"; const LOG_COMPLETE_SUCCESS = "data/complete_log_success"; diff --git a/toolkit/mozapps/update/test/unit/test_0113_versionDowngradeCheck.js b/toolkit/mozapps/update/test/unit/test_0113_versionDowngradeCheck.js new file mode 100644 index 00000000000..a27a51f7b6e --- /dev/null +++ b/toolkit/mozapps/update/test/unit/test_0113_versionDowngradeCheck.js @@ -0,0 +1,65 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2012 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian R. Bondy (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** + */ + +/* Test version downgrade MAR security check */ + +const TEST_ID = "0113"; + +// We don't actually care if the MAR has any data, we only care about the +// application return code and update.status result. +const TEST_FILES = []; + +const VERSION_DOWNGRADE_ERROR = "23"; + +function run_test() { + // Setup an old version MAR file + do_register_cleanup(cleanupUpdaterTest); + setupUpdaterTest(MAR_OLD_VERSION_FILE); + + // Apply the MAR + let exitValue = runUpdate(); + logTestInfo("testing updater binary process exitValue for failure when " + + "applying a version downgrade MAR"); + // Make sure the updater executed successfully + do_check_eq(exitValue, 0); + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + + //Make sure we get a version downgrade error + let updateStatus = readStatusFile(updatesDir); + do_check_eq(updateStatus.split(": ")[1], VERSION_DOWNGRADE_ERROR); +} diff --git a/toolkit/mozapps/update/test/unit/test_0114_productChannelCheck.js b/toolkit/mozapps/update/test/unit/test_0114_productChannelCheck.js new file mode 100644 index 00000000000..3d5f7174852 --- /dev/null +++ b/toolkit/mozapps/update/test/unit/test_0114_productChannelCheck.js @@ -0,0 +1,65 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2012 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian R. Bondy (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** + */ + +/* Test product/channel MAR security check */ + +const TEST_ID = "0114"; + +// We don't actually care if the MAR has any data, we only care about the +// application return code and update.status result. +const TEST_FILES = []; + +const MAR_CHANNEL_MISMATCH_ERROR = "22"; + +function run_test() { + // Setup a wrong channel MAR file + do_register_cleanup(cleanupUpdaterTest); + setupUpdaterTest(MAR_WRONG_CHANNEL_FILE); + + // Apply the MAR + let exitValue = runUpdate(); + logTestInfo("testing updater binary process exitValue for failure when " + + "applying a wrong product and channel MAR file"); + // Make sure the updater executed successfully + do_check_eq(exitValue, 0); + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + + //Make sure we get a version downgrade error + let updateStatus = readStatusFile(updatesDir); + do_check_eq(updateStatus.split(": ")[1], MAR_CHANNEL_MISMATCH_ERROR); +} diff --git a/toolkit/mozapps/update/test/unit/xpcshell_updater_windows.ini b/toolkit/mozapps/update/test/unit/xpcshell_updater_windows.ini index cdda5ec9b4d..8aaa26607b5 100644 --- a/toolkit/mozapps/update/test/unit/xpcshell_updater_windows.ini +++ b/toolkit/mozapps/update/test/unit/xpcshell_updater_windows.ini @@ -1,3 +1,5 @@ +[test_0113_versionDowngradeCheck.js] +[test_0114_productChannelCheck.js] [test_0150_appBinReplaced_xp_win_complete.js] [test_0151_appBinPatched_xp_win_partial.js] [test_0160_appInUse_xp_win_complete.js]