Bug 1371445 - Pre: Fail unit tests if unlimited strength JCE is not installed. r=maliu draft
authorNick Alexander <nalexander@mozilla.com>
Tue, 04 Jul 2017 13:57:27 -0700
changeset 607764 783c40122a0e50eb62d8b12ccbfc4f8457724e0f
parent 607763 8d48b664903bce32def8f0762a86d31c250c3853
child 607765 1850e7365b903269c034efc6b89257ebe3834161
push id68104
push usernalexander@mozilla.com
push dateWed, 12 Jul 2017 21:11:53 +0000
reviewersmaliu
bugs1371445
milestone56.0a1
Bug 1371445 - Pre: Fail unit tests if unlimited strength JCE is not installed. r=maliu This has been a problem as far back as the android-sync repository -- https://github.com/mozilla-services/android-sync#download-prerequisites! MozReview-Commit-ID: dIWI8WtHKu
mobile/android/app/build.gradle
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -474,16 +474,27 @@ def makeTaskExecutionListener(artifactRo
 
 // TASK_ID and RUN_ID are provided by docker-worker; see
 // https://docs.taskcluster.net/manual/execution/workers/docker-worker.
 if (System.env.TASK_ID && System.env.RUN_ID) {
     def artifactRootUrl = "https://queue.taskcluster.net/v1/task/${System.env.TASK_ID}/runs/${System.env.RUN_ID}/artifacts"
     gradle.addListener(makeTaskExecutionListener(artifactRootUrl))
 }
 
+if (gradle.startParameter.taskNames.any { it.endsWith('UnitTest') }) {
+    // Approach cribbed from https://github.com/rwinch/jce-checker.
+    int maxKeyLen = javax.crypto.Cipher.getMaxAllowedKeyLength("AES")
+    if (maxKeyLen <= 128) {
+        throw new GradleException(
+            "Android unit tests require " +
+            "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy, see " +
+            "http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html")
+    }
+}
+
 // Bug 1320035: Gradle configuration for running findbugs.  Findbugs only allows
 // to generate one report per invocation: https://stackoverflow.com/a/42720235.
 // Run two tasks, accepting the cost of duplicate work.
 android.applicationVariants.all { variant ->
     task("findbugsHtml${variant.name.capitalize()}", type: FindBugs) {
         // TODO: figure out how to share the shared configuration.
         description "Analyze ${variant.name} code with findbugs (HTML report)"
         group "Verification"