Bug 930194 - Add prerequisite checks for MozillaMaintenance Service tests that fail the tests if the build system is not properly configured. r=bbondy
authorRobert Strong <robert.bugzilla@gmail.com>
Mon, 25 Nov 2013 10:25:22 -0800
changeset 157491 af7b718037b521ab049d6622cfbe1c57832146ef
parent 157490 d9ef33623670590f2c24bfdc8a1da1444c205e49
child 157492 401bba5f86948b72a8a54bae813a91e1bcc16208
push id25714
push usercbook@mozilla.com
push dateTue, 26 Nov 2013 11:39:03 +0000
treeherdermozilla-central@4a8c40940659 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy
bugs930194
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 930194 - Add prerequisite checks for MozillaMaintenance Service tests that fail the tests if the build system is not properly configured. r=bbondy
toolkit/mozapps/update/tests/unit_aus_update/head_update.js
--- a/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
+++ b/toolkit/mozapps/update/tests/unit_aus_update/head_update.js
@@ -512,17 +512,17 @@ function getTargetDirFile(aRelPath, allo
 if (IS_WIN) {
   const kLockFileName = "updated.update_in_progress.lock";
   /**
    * Helper function for locking a directory on Windows.
    */
   function lockDirectory(aDir) {
     var file = aDir.clone();
     file.append(kLockFileName);
-    file.create(file.NORMAL_FILE_TYPE, 4 * 64 + 4 * 8 + 4); // 0444
+    file.create(file.NORMAL_FILE_TYPE, 0o444);
     file.QueryInterface(AUS_Ci.nsILocalFileWin);
     file.fileAttributesWin |= file.WFA_READONLY;
     file.fileAttributesWin &= ~file.WFA_READWRITE;
     logTestInfo("testing the successful creation of the lock file");
     do_check_true(file.exists());
     do_check_false(file.isWritable());
   }
   /**
@@ -572,17 +572,17 @@ function copyMinimumAppFiles(aSrcDir, aD
                        "dependentlibs.list"];
 
   // Read the dependent libs file leafnames from the dependentlibs.list file
   // into the array.
   let deplibsFile = aSrcDir.clone();
   deplibsFile.append("dependentlibs.list");
   let istream = AUS_Cc["@mozilla.org/network/file-input-stream;1"].
                 createInstance(AUS_Ci.nsIFileInputStream);
-  istream.init(deplibsFile, 0x01, 4 * 64 + 4 * 8 + 4, 0); // 0444
+  istream.init(deplibsFile, 0x01, 0o444, 0);
   istream.QueryInterface(AUS_Ci.nsILineInputStream);
 
   let hasMore;
   let line = {};
   do {
     hasMore = istream.readLine(line);
     fileLeafNames.push(line.value);
   } while(hasMore);
@@ -718,83 +718,102 @@ let gServiceLaunchedCallbackArgs = null;
  * @return true if the test should run and false if it shouldn't.
  */
 function shouldRunServiceTest(aFirstTest) {
   // In case the machine is running an old maintenance service or if it
   // is not installed, and permissions exist to install it.  Then install
   // the newer bin that we have.
   attemptServiceInstall();
 
-  const REG_PATH = "SOFTWARE\\Mozilla\\MaintenanceService\\" +
-                   "3932ecacee736d366d6436db0f55bce4";
-
-  let key = AUS_Cc["@mozilla.org/windows-registry-key;1"].
-            createInstance(AUS_Ci.nsIWindowsRegKey);
-  try {
-    key.open(AUS_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, REG_PATH,
-             AUS_Ci.nsIWindowsRegKey.ACCESS_READ | key.WOW64_64);
-  }
-  catch (e) {
-    logTestInfo("this test can only run on the buildbot build system at this " +
-                "time.");
-    return false;
-  }
-
   let binDir = getGREDir();
   let updaterBin = binDir.clone();
   updaterBin.append(FILE_UPDATER_BIN);
   if (!updaterBin.exists()) {
     do_throw("Unable to find updater binary!");
   }
 
   let updaterBinPath = updaterBin.path;
   if (/ /.test(updaterBinPath)) {
     updaterBinPath = '"' + updaterBinPath + '"';
   }
 
+  const REG_PATH = "SOFTWARE\\Mozilla\\MaintenanceService\\" +
+                   "3932ecacee736d366d6436db0f55bce4";
+
+  let key = AUS_Cc["@mozilla.org/windows-registry-key;1"].
+            createInstance(AUS_Ci.nsIWindowsRegKey);
+  try {
+    key.open(AUS_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, REG_PATH,
+             AUS_Ci.nsIWindowsRegKey.ACCESS_READ | key.WOW64_64);
+  }
+  catch (e) {
+#ifndef DISABLE_UPDATER_AUTHENTICODE_CHECK
+    // The build system could sign the files and not have the test registry key
+    // in which case we should fail the test by throwing so it can be fixed.
+    if (isBinarySigned(updaterBinPath)) {
+      do_throw("binary is signed but the test registry key does not exists!");
+    }
+#endif
+
+    logTestInfo("this test can only run on the buildbot build system at this " +
+                "time.");
+    return false;
+  }
+
   // Check to make sure the service is installed
   let helperBin = getTestDirFile(FILE_HELPER_BIN);
   let args = ["wait-for-service-stop", "MozillaMaintenance", "10"];
   let process = AUS_Cc["@mozilla.org/process/util;1"].
                 createInstance(AUS_Ci.nsIProcess);
   process.init(helperBin);
   logTestInfo("Checking if the service exists on this machine.");
   process.run(true, args, args.length);
   if (process.exitValue == 0xEE) {
-    logTestInfo("this test can only run when the service is installed.");
-    return false;
+    do_throw("test registry key exists but this test can only run on systems " +
+             "with the maintenance service installed.");
   } else {
     logTestInfo("Service exists, return value: " + process.exitValue);
   }
 
   // If this is the first test in the series, then there is no reason the
   // service should be anything but stopped, so be strict here and throw
   // an error.
   if (aFirstTest && process.exitValue != 0) {
     do_throw("First test, check for service stopped state returned error " +
              process.exitValue);
   }
 
-#ifdef DISABLE_UPDATER_AUTHENTICODE_CHECK
-  // We won't be performing signature checks.
+#ifndef DISABLE_UPDATER_AUTHENTICODE_CHECK
+  if (!isBinarySigned(updaterBinPath)) {
+    logTestInfo("this test can only run on builds with signed binaries.");
+    return false;
+  }
+#endif
   return true;
-#else
-  // Make sure the binaries are signed
-  args = ["check-signature", updaterBinPath];
-  process = AUS_Cc["@mozilla.org/process/util;1"].
-            createInstance(AUS_Ci.nsIProcess);
+}
+
+/**
+ * Helper function to check whether the a binary is signed.
+ *
+ * @param  aBinPath The path to the file to check if it is signed.
+ * @return true if the file is signed and false if it isn't.
+ */
+function isBinarySigned(aBinPath) {
+  let helperBin = getTestDirFile(FILE_HELPER_BIN);
+  let args = ["check-signature", aBinPath];
+  let process = AUS_Cc["@mozilla.org/process/util;1"].
+                createInstance(AUS_Ci.nsIProcess);
   process.init(helperBin);
   process.run(true, args, args.length);
-  if (process.exitValue == 0) {
-    return true;
+  if (process.exitValue != 0) {
+    logTestInfo("binary is not signed. " + FILE_HELPER_BIN + " returned " +
+                process.exitValue + " for file " + aBinPath);
+    return false;
   }
-  logTestInfo("this test can only run on builds with signed binaries. " +
-              FILE_HELPER_BIN + " returned " + process.exitValue)
-  return false;
-#endif
+  return true;
 }
 
 /**
  * Copies the specified filename from the dist/bin
  * directory into the apply-to directory.
  *
  * @param filename The name of the file to copy
 */
@@ -812,17 +831,17 @@ function copyBinToApplyToDir(filename) {
   }
 }
 
 /**
  * Attempts to upgrade the maintenance service if permissions are allowed.
  * This is useful for XP where we have permission to upgrade in case an
  * older service installer exists.  Also if the user manually installed into
  * a unprivileged location.
-*/
+ */
 function attemptServiceInstall() {
   var version = AUS_Cc["@mozilla.org/system-info;1"]
                 .getService(AUS_Ci.nsIPropertyBag2)
                 .getProperty("version");
   var isVistaOrHigher = (parseFloat(version) >= 6.0);
   if (isVistaOrHigher) {
     return;
   }