You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ma...@apache.org on 2019/04/01 13:07:33 UTC

[incubator-openwhisk] branch master updated: Make tests working in case the "provide-api-key" feature is disabled. (#4387)

This is an automated email from the ASF dual-hosted git repository.

markusthoemmes pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new af96c51  Make tests working in case the "provide-api-key" feature is disabled. (#4387)
af96c51 is described below

commit af96c510e358564fa49e49307990fe811bef91f0
Author: Martin Henke <ma...@web.de>
AuthorDate: Mon Apr 1 15:07:26 2019 +0200

    Make tests working in case the "provide-api-key" feature is disabled. (#4387)
---
 ansible/group_vars/all                             |  2 +
 ansible/roles/controller/tasks/deploy.yml          |  2 +
 ansible/templates/whisk.properties.j2              |  3 +-
 tests/src/test/resources/application.conf.j2       |  3 +
 tests/src/test/scala/common/WhiskProperties.java   | 13 ++-
 .../core/cli/test/WskRestBasicUsageTests.scala     | 45 ++++++----
 .../controller/test/ControllerTestCommon.scala     |  6 +-
 .../test/scala/system/basic/WskActionTests.scala   | 21 +++--
 .../scala/system/basic/WskRestBasicTests.scala     | 98 +++++++++++++++++-----
 9 files changed, 143 insertions(+), 50 deletions(-)

diff --git a/ansible/group_vars/all b/ansible/group_vars/all
index c9cb278..9fe87a0 100644
--- a/ansible/group_vars/all
+++ b/ansible/group_vars/all
@@ -34,6 +34,8 @@ hosts_dir: "{{ inventory_dir | default(env_hosts_dir) }}"
 whisk:
   version:
     date: "{{ansible_date_time.iso8601}}"
+  feature_flags:
+    require_api_key_annotation: "{{ require_api_key_annotation | default(true) }}"
 
 ##
 # configuration parameters related to support runtimes (see org.apache.openwhisk.core.entity.ExecManifest for schema of the manifest).
diff --git a/ansible/roles/controller/tasks/deploy.yml b/ansible/roles/controller/tasks/deploy.yml
index 83d522e..e958f79 100644
--- a/ansible/roles/controller/tasks/deploy.yml
+++ b/ansible/roles/controller/tasks/deploy.yml
@@ -206,6 +206,8 @@
       "CONFIG_whisk_concurrencyLimit_max": "{{ limit_action_concurrency_max | default() }}"
       "CONFIG_whisk_concurrencyLimit_std": "{{ limit_action_concurrency_std | default() }}"
 
+      "CONFIG_whisk_featureFlags_requireApiKeyAnnotation" : "{{ whisk.feature_flags.require_api_key_annotation | default(true) }}"
+
       "CONFIG_whisk_activation_payload_max":
         "{{ limit_activation_payload | default() }}"
 
diff --git a/ansible/templates/whisk.properties.j2 b/ansible/templates/whisk.properties.j2
index b821109..5951788 100644
--- a/ansible/templates/whisk.properties.j2
+++ b/ansible/templates/whisk.properties.j2
@@ -31,7 +31,8 @@ whisk.api.host.name={{ whisk_api_host_name | default(groups['edge'] | first) }}
 whisk.api.localhost.name={{ whisk_api_localhost_name | default(whisk_api_host_name) | default(whisk_api_localhost_name_default) }}
 whisk.api.vanity.subdomain.parts=1
 
-whisk.action.concurrency={{runtimes_enable_concurrency | default(false)}}
+whisk.action.concurrency={{ runtimes_enable_concurrency | default(false) }}
+whisk.feature.requireApiKeyAnnotation={{ whisk.feature_flags.require_api_key_annotation | default(true) }}
 
 runtimes.manifest={{ runtimesManifest | to_json }}
 
diff --git a/tests/src/test/resources/application.conf.j2 b/tests/src/test/resources/application.conf.j2
index eaf17f7..85b6298 100644
--- a/tests/src/test/resources/application.conf.j2
+++ b/tests/src/test/resources/application.conf.j2
@@ -16,6 +16,9 @@ akka.http.host-connection-pool.client.idle-timeout = 90 s
 akka.jvm-exit-on-fatal-error = off
 
 whisk {
+    feature-flags {
+      require-api-key-annotation = {{ whisk.feature_flags.require_api_key_annotation | default(true) }}
+    }
     # kafka related configuration
     kafka {
         replication-factor = 1
diff --git a/tests/src/test/scala/common/WhiskProperties.java b/tests/src/test/scala/common/WhiskProperties.java
index 1b717e2..26849f5 100644
--- a/tests/src/test/scala/common/WhiskProperties.java
+++ b/tests/src/test/scala/common/WhiskProperties.java
@@ -125,8 +125,17 @@ public class WhiskProperties {
         return new File(whiskHome, name);
     }
 
-    public static String getProperty(String string) {
-        return whiskProperties.getProperty(string);
+    public static String getProperty(String name) {
+        return whiskProperties.getProperty(name);
+    }
+
+    public static Boolean getBooleanProperty(String name, Boolean defaultValue) {
+        String value = whiskProperties.getProperty(name);
+        if (value == null) {
+            return defaultValue;
+        }
+
+        return Boolean.parseBoolean(value);
     }
 
     public static String getKafkaHosts() {
diff --git a/tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskRestBasicUsageTests.scala b/tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskRestBasicUsageTests.scala
index 65dc1e3..7d65a6d 100644
--- a/tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskRestBasicUsageTests.scala
+++ b/tests/src/test/scala/org/apache/openwhisk/core/cli/test/WskRestBasicUsageTests.scala
@@ -21,7 +21,6 @@ import akka.http.scaladsl.model.StatusCodes.NotFound
 import akka.http.scaladsl.model.StatusCodes.OK
 import akka.http.scaladsl.model.StatusCodes.BadRequest
 import akka.http.scaladsl.model.StatusCodes.Conflict
-
 import java.time.Instant
 import java.time.Clock
 
@@ -56,6 +55,8 @@ class WskRestBasicUsageTests extends TestHelpers with WskTestHelpers with WskAct
   val defaultAction: Some[String] = Some(TestUtils.getTestActionFilename("hello.js"))
   val usrAgentHeaderRegEx: String = """\bUser-Agent\b": \[\s+"OpenWhisk\-CLI/1.\d+.*"""
 
+  val requireAPIKeyAnnotation = WhiskProperties.getBooleanProperty("whisk.feature.requireApiKeyAnnotation", true);
+
   behavior of "Wsk API basic usage"
 
   it should "allow a 3 part Fully Qualified Name (FQN) without a leading '/'" in withAssetCleaner(wskprops) {
@@ -303,7 +304,7 @@ class WskRestBasicUsageTests extends TestHelpers with WskTestHelpers with WskAct
       action.create(
         name,
         Some(TestUtils.getTestActionFilename("helloOpenwhiskPackage.js")),
-        annotations = Map(WhiskAction.provideApiKeyAnnotationName -> JsBoolean(true)))
+        annotations = Map(WhiskAction.provideApiKeyAnnotationName -> JsTrue))
     }
 
     val run = wsk.action.invoke(name, Map("ignore_certs" -> true.toJson, "name" -> name.toJson))
@@ -317,6 +318,7 @@ class WskRestBasicUsageTests extends TestHelpers with WskTestHelpers with WskAct
   }
 
   it should "invoke an action receiving context properties excluding api key" in withAssetCleaner(wskprops) {
+    assume(requireAPIKeyAnnotation)
     (wp, assetHelper) =>
       val namespace = wsk.namespace.whois()
       val name = "context"
@@ -346,7 +348,7 @@ class WskRestBasicUsageTests extends TestHelpers with WskTestHelpers with WskAct
         action.create(
           name,
           Some(TestUtils.getTestActionFilename("helloContext.js")),
-          annotations = Map(WhiskAction.provideApiKeyAnnotationName -> JsBoolean(true)))
+          annotations = Map(WhiskAction.provideApiKeyAnnotationName -> JsTrue))
       }
 
       val start = Instant.now(Clock.systemUTC()).toEpochMilli
@@ -431,12 +433,16 @@ class WskRestBasicUsageTests extends TestHelpers with WskTestHelpers with WskAct
       }
 
       val action = wsk.action.get(name)
-      action.getFieldJsValue("annotations").convertTo[Set[JsObject]] shouldBe Set(
-        JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")),
-        JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsBoolean(false)),
-        JsObject("key" -> JsString("web-export"), "value" -> JsBoolean(webEnabled || rawEnabled)),
-        JsObject("key" -> JsString("raw-http"), "value" -> JsBoolean(rawEnabled)),
-        JsObject("key" -> JsString("final"), "value" -> JsBoolean(webEnabled || rawEnabled)))
+
+      val baseAnnotations = Parameters("exec", "nodejs:6") ++
+        Parameters("web-export", JsBoolean(webEnabled || rawEnabled)) ++
+        Parameters("raw-http", JsBoolean(rawEnabled)) ++
+        Parameters("final", JsBoolean(webEnabled || rawEnabled))
+      val testAnnotations = if (requireAPIKeyAnnotation) {
+        baseAnnotations ++ Parameters(WhiskAction.provideApiKeyAnnotationName, JsFalse)
+      } else baseAnnotations
+
+      action.getFieldJsValue("annotations") shouldBe testAnnotations.toJsArray
     }
   }
 
@@ -449,13 +455,22 @@ class WskRestBasicUsageTests extends TestHelpers with WskTestHelpers with WskAct
         action.create(name, file, web = Some("true"), update = true)
       }
 
+      val baseAnnotations =
+        Parameters("web-export", JsBoolean(true)) ++
+          Parameters("raw-http", JsBoolean(false)) ++
+          Parameters("final", JsBoolean(true))
+
+      val testAnnotations = if (requireAPIKeyAnnotation) {
+        baseAnnotations ++
+          Parameters(WhiskAction.provideApiKeyAnnotationName, JsBoolean(false)) ++
+          Parameters("exec", "nodejs:6")
+      } else {
+        baseAnnotations ++
+          Parameters("exec", "nodejs:6")
+      }
+
       val action = wsk.action.get(name)
-      action.getFieldJsValue("annotations") shouldBe JsArray(
-        JsObject("key" -> JsString("web-export"), "value" -> JsBoolean(true)),
-        JsObject("key" -> JsString("raw-http"), "value" -> JsBoolean(false)),
-        JsObject("key" -> JsString("final"), "value" -> JsBoolean(true)),
-        JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsBoolean(false)),
-        JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
+      action.getFieldJsValue("annotations") shouldBe testAnnotations.toJsArray
   }
 
   it should "invoke action while not encoding &, <, > characters" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
diff --git a/tests/src/test/scala/org/apache/openwhisk/core/controller/test/ControllerTestCommon.scala b/tests/src/test/scala/org/apache/openwhisk/core/controller/test/ControllerTestCommon.scala
index 56df5e2..51e06fd 100644
--- a/tests/src/test/scala/org/apache/openwhisk/core/controller/test/ControllerTestCommon.scala
+++ b/tests/src/test/scala/org/apache/openwhisk/core/controller/test/ControllerTestCommon.scala
@@ -30,7 +30,7 @@ import akka.http.scaladsl.testkit.ScalatestRouteTest
 import akka.http.scaladsl.testkit.RouteTestTimeout
 import spray.json._
 import org.apache.openwhisk.common.TransactionId
-import org.apache.openwhisk.core.WhiskConfig
+import org.apache.openwhisk.core.{FeatureFlags, WhiskConfig}
 import org.apache.openwhisk.core.connector.ActivationMessage
 import org.apache.openwhisk.core.containerpool.logging.LogStoreProvider
 import org.apache.openwhisk.core.controller.{CustomHeaders, RestApiCommons, WhiskServices}
@@ -86,8 +86,8 @@ protected trait ControllerTestCommon
   }
 
   def systemAnnotations(kind: String, create: Boolean = true): Parameters = {
-    val base = if (create) {
-      Parameters(WhiskAction.provideApiKeyAnnotationName, JsBoolean(false))
+    val base = if (create && FeatureFlags.requireApiKeyAnnotation) {
+      Parameters(WhiskAction.provideApiKeyAnnotationName, JsFalse)
     } else {
       Parameters()
     }
diff --git a/tests/src/test/scala/system/basic/WskActionTests.scala b/tests/src/test/scala/system/basic/WskActionTests.scala
index 8e6bf3d..49f950c 100644
--- a/tests/src/test/scala/system/basic/WskActionTests.scala
+++ b/tests/src/test/scala/system/basic/WskActionTests.scala
@@ -26,6 +26,7 @@ import common._
 import common.rest.WskRestOperations
 import org.apache.openwhisk.core.entity.WhiskAction
 import org.apache.commons.io.FileUtils
+import org.apache.openwhisk.core.FeatureFlags
 import spray.json._
 import spray.json.DefaultJsonProtocol._
 
@@ -183,13 +184,16 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers with
         JsObject("key" -> JsString("copiedParam2"), "value" -> JsNumber(123)),
         JsObject("key" -> JsString("origParam1"), "value" -> JsString("origParamValue1")),
         JsObject("key" -> JsString("origParam2"), "value" -> JsNumber(999)))
-      val resAnnots = Seq(
+      val baseAnnots = Seq(
         JsObject("key" -> JsString("origAnnot1"), "value" -> JsString("origAnnotValue1")),
-        JsObject("key" -> JsString("copiedAnnot2"), "value" -> JsBoolean(false)),
+        JsObject("key" -> JsString("copiedAnnot2"), "value" -> JsFalse),
         JsObject("key" -> JsString("copiedAnnot1"), "value" -> JsString("copiedAnnotValue1")),
-        JsObject("key" -> JsString("origAnnot2"), "value" -> JsBoolean(true)),
+        JsObject("key" -> JsString("origAnnot2"), "value" -> JsTrue),
         JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")),
-        JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsBoolean(false)))
+        JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsFalse))
+      val resAnnots: Seq[JsObject] = if (FeatureFlags.requireApiKeyAnnotation) {
+        baseAnnots ++ Seq(JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsFalse))
+      } else baseAnnots
 
       assetHelper.withCleaner(wsk.action, origName) {
         val file = Some(TestUtils.getTestActionFilename("echo.js"))
@@ -250,10 +254,11 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers with
     val child = "wc"
 
     assetHelper.withCleaner(wsk.action, name) { (action, _) =>
-      action.create(
-        name,
-        Some(TestUtils.getTestActionFilename("wcbin.js")),
-        annotations = Map(WhiskAction.provideApiKeyAnnotationName -> JsBoolean(true)))
+      val annotations =
+        if (FeatureFlags.requireApiKeyAnnotation) Map(WhiskAction.provideApiKeyAnnotationName -> JsTrue)
+        else Map.empty[String, JsValue]
+      action.create(name, Some(TestUtils.getTestActionFilename("wcbin.js")), annotations = annotations)
+
     }
     assetHelper.withCleaner(wsk.action, child) { (action, _) =>
       action.create(child, Some(TestUtils.getTestActionFilename("wc.js")))
diff --git a/tests/src/test/scala/system/basic/WskRestBasicTests.scala b/tests/src/test/scala/system/basic/WskRestBasicTests.scala
index ca6796e..86c35c6 100644
--- a/tests/src/test/scala/system/basic/WskRestBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskRestBasicTests.scala
@@ -44,6 +44,8 @@ class WskRestBasicTests extends TestHelpers with WskTestHelpers with WskActorSys
 
   val defaultAction: Some[String] = Some(TestUtils.getTestActionFilename("hello.js"))
 
+  val requireAPIKeyAnnotation = WhiskProperties.getBooleanProperty("whisk.feature.requireApiKeyAnnotation", true);
+
   /**
    * Retry operations that need to settle the controller cache
    */
@@ -138,15 +140,37 @@ class WskRestBasicTests extends TestHelpers with WskTestHelpers with WskActorSys
     val action = result.getFieldListJsObject("actions")(0)
     RestResult.getField(action, "name") shouldBe actionName
     val annoAction = RestResult.getFieldJsValue(action, "annotations")
-    annoAction shouldBe JsArray(
-      JsObject("key" -> JsString("description"), "value" -> JsString("Action description")),
-      JsObject(
-        "key" -> JsString("parameters"),
-        "value" -> JsArray(
-          JsObject("name" -> JsString("paramName1"), "description" -> JsString("Parameter description 1")),
-          JsObject("name" -> JsString("paramName2"), "description" -> JsString("Parameter description 2")))),
-      JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsBoolean(false)),
-      JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
+
+    annoAction shouldBe (if (requireAPIKeyAnnotation) {
+                           JsArray(
+                             JsObject("key" -> JsString("description"), "value" -> JsString("Action description")),
+                             JsObject(
+                               "key" -> JsString("parameters"),
+                               "value" -> JsArray(
+                                 JsObject(
+                                   "name" -> JsString("paramName1"),
+                                   "description" -> JsString("Parameter description 1")),
+                                 JsObject(
+                                   "name" -> JsString("paramName2"),
+                                   "description" -> JsString("Parameter description 2")))),
+                             JsObject(
+                               "key" -> WhiskAction.provideApiKeyAnnotationName.toJson,
+                               "value" -> JsBoolean(false)),
+                             JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
+                         } else {
+                           JsArray(
+                             JsObject("key" -> JsString("description"), "value" -> JsString("Action description")),
+                             JsObject(
+                               "key" -> JsString("parameters"),
+                               "value" -> JsArray(
+                                 JsObject(
+                                   "name" -> JsString("paramName1"),
+                                   "description" -> JsString("Parameter description 1")),
+                                 JsObject(
+                                   "name" -> JsString("paramName2"),
+                                   "description" -> JsString("Parameter description 2")))),
+                             JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
+                         })
   }
 
   it should "create a package with a name that contains spaces" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
@@ -344,9 +368,21 @@ class WskRestBasicTests extends TestHelpers with WskTestHelpers with WskActorSys
       RestResult.getField(exec, "code") should not be ""
       result.getFieldJsValue("parameters") shouldBe JsArray(
         JsObject("key" -> JsString("payload"), "value" -> JsString("test")))
-      result.getFieldJsValue("annotations") shouldBe JsArray(
-        JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsBoolean(false)),
-        JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
+
+      result.getFieldJsValue("annotations") shouldBe (if (requireAPIKeyAnnotation) {
+                                                        JsArray(
+                                                          JsObject(
+                                                            "key" -> WhiskAction.provideApiKeyAnnotationName.toJson,
+                                                            "value" -> JsBoolean(false)),
+                                                          JsObject(
+                                                            "key" -> JsString("exec"),
+                                                            "value" -> JsString("nodejs:6")))
+                                                      } else {
+                                                        JsArray(
+                                                          JsObject(
+                                                            "key" -> JsString("exec"),
+                                                            "value" -> JsString("nodejs:6")))
+                                                      })
       result.getFieldJsValue("limits") shouldBe JsObject(
         "timeout" -> JsNumber(60000),
         "memory" -> JsNumber(256),
@@ -444,16 +480,36 @@ class WskRestBasicTests extends TestHelpers with WskTestHelpers with WskActorSys
 
     result.getField("name") shouldBe name
     result.getField("namespace") shouldBe ns
+
     val annos = result.getFieldJsValue("annotations")
-    annos shouldBe JsArray(
-      JsObject("key" -> JsString("description"), "value" -> JsString("Action description")),
-      JsObject(
-        "key" -> JsString("parameters"),
-        "value" -> JsArray(
-          JsObject("name" -> JsString("paramName1"), "description" -> JsString("Parameter description 1")),
-          JsObject("name" -> JsString("paramName2"), "description" -> JsString("Parameter description 2")))),
-      JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsBoolean(false)),
-      JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
+    annos shouldBe (if (requireAPIKeyAnnotation) {
+                      JsArray(
+                        JsObject("key" -> JsString("description"), "value" -> JsString("Action description")),
+                        JsObject(
+                          "key" -> JsString("parameters"),
+                          "value" -> JsArray(
+                            JsObject(
+                              "name" -> JsString("paramName1"),
+                              "description" -> JsString("Parameter description 1")),
+                            JsObject(
+                              "name" -> JsString("paramName2"),
+                              "description" -> JsString("Parameter description 2")))),
+                        JsObject("key" -> WhiskAction.provideApiKeyAnnotationName.toJson, "value" -> JsBoolean(false)),
+                        JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
+                    } else {
+                      JsArray(
+                        JsObject("key" -> JsString("description"), "value" -> JsString("Action description")),
+                        JsObject(
+                          "key" -> JsString("parameters"),
+                          "value" -> JsArray(
+                            JsObject(
+                              "name" -> JsString("paramName1"),
+                              "description" -> JsString("Parameter description 1")),
+                            JsObject(
+                              "name" -> JsString("paramName2"),
+                              "description" -> JsString("Parameter description 2")))),
+                        JsObject("key" -> JsString("exec"), "value" -> JsString("nodejs:6")))
+                    })
   }
 
   it should "create an action with a name that contains spaces" in withAssetCleaner(wskprops) { (wp, assetHelper) =>