You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2017/08/17 17:17:50 UTC

[incubator-openwhisk-cli] 09/10: Fix illegal header warnings for web actions specifying content type (#2619)

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

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

commit ff70485517a167d544f716d34c8fa84d714657e9
Author: James Dubee <jw...@us.ibm.com>
AuthorDate: Wed Aug 16 22:12:29 2017 -0400

    Fix illegal header warnings for web actions specifying content type (#2619)
---
 gradle/wrapper/gradle-wrapper.properties           |  1 -
 tests/dat/actions/base64Web.js                     |  9 ++++
 .../test/scala/system/basic/WskSequenceTests.scala |  1 -
 .../scala/whisk/core/cli/test/ApiGwTests.scala     |  2 +-
 .../whisk/core/cli/test/WskWebActionsTests.scala   | 63 ++++++++++++++--------
 5 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index f348859..f16d266 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,3 @@ distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
 distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
-
diff --git a/tests/dat/actions/base64Web.js b/tests/dat/actions/base64Web.js
new file mode 100644
index 0000000..3e4773e
--- /dev/null
+++ b/tests/dat/actions/base64Web.js
@@ -0,0 +1,9 @@
+function main() {
+    return {
+        headers: {
+            "content-type": "application/json"
+        },
+        statusCode: 200,
+        body: new Buffer(JSON.stringify({'status': 'success'})).toString('base64')
+    }
+}
diff --git a/tests/src/test/scala/system/basic/WskSequenceTests.scala b/tests/src/test/scala/system/basic/WskSequenceTests.scala
index 6151968..688c5c6 100644
--- a/tests/src/test/scala/system/basic/WskSequenceTests.scala
+++ b/tests/src/test/scala/system/basic/WskSequenceTests.scala
@@ -41,7 +41,6 @@ import akka.http.scaladsl.testkit.ScalatestRouteTest
 import spray.json._
 import spray.json.DefaultJsonProtocol._
 
-import whisk.core.WhiskConfig
 import whisk.http.Messages.sequenceIsTooLong
 
 /**
diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala b/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
index e3f2067..e99c88f 100644
--- a/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwTests.scala
@@ -911,7 +911,7 @@ class ApiGwTests
     it should "list api alphabetically by Base/Rel/Verb" in {
         val baseName = "/BaseTestPathApiList"
         val actionName = "actionName"
-        val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
+        val file = TestCLIUtils.getTestActionFilename(s"echo-web-http.js")
         try {
             // Create Action for apis
             var action = wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala b/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
index 0f67588..2834948 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
@@ -86,8 +86,8 @@ class WskWebActionsTestsV2 extends WskWebActionsTests with BeforeAndAfterAll {
     "vanity subdomain" should "access a web action via namespace subdomain" in withAssetCleaner(wskPropsForSubdomainTest) {
         (wp, assetHelper) =>
             val actionName = "webaction"
-
             val file = Some(TestCLIUtils.getTestActionFilename("echo.js"))
+
             assetHelper.withCleaner(wsk.action, actionName) {
                 (action, _) => action.create(actionName, file, web = Some(true.toString))(wp)
             }
@@ -145,14 +145,14 @@ trait WskWebActionsTests
         (wp, assetHelper) =>
             val name = "webaction"
             val file = Some(TestCLIUtils.getTestActionFilename("echo.js"))
+            val host = getServiceURL()
+            val requestPath = host + s"$testRoutePath/$namespace/default/$name.text/a?a="
+            val padAmount = MAX_URL_LENGTH - requestPath.length
 
             assetHelper.withCleaner(wsk.action, name) {
                 (action, _) => action.create(name, file, web = Some("true"))
             }
 
-            val host = getServiceURL()
-            val requestPath = host + s"$testRoutePath/$namespace/default/webaction.text/a?a="
-            val padAmount = MAX_URL_LENGTH - requestPath.length
             Seq(("A", 200),
                 ("A" * padAmount, 200),
                 // ideally the bad case is just +1 but there's some differences
@@ -183,19 +183,18 @@ trait WskWebActionsTests
         (wp, assetHelper) =>
             val name = "webaction"
             val file = Some(TestCLIUtils.getTestActionFilename("echo.js"))
+            val host = getServiceURL()
+            val url = if (testRoutePath == "/api/v1/experimental/web") {
+                s"$host$testRoutePath/$namespace/default/$name.text/__ow_meta_namespace"
+            } else {
+                s"$host$testRoutePath/$namespace/default/$name.text/__ow_user"
+            }
 
             assetHelper.withCleaner(wsk.action, name) {
                 (action, _) =>
                     action.create(name, file, web = Some("true"), annotations = Map("require-whisk-auth" -> true.toJson))
             }
 
-            val host = getServiceURL()
-            val url = if (testRoutePath == "/api/v1/experimental/web") {
-                s"$host$testRoutePath/$namespace/default/webaction.text/__ow_meta_namespace"
-            } else {
-                s"$host$testRoutePath/$namespace/default/webaction.text/__ow_user"
-            }
-
             val unauthorizedResponse = RestAssured.given().config(sslconfig).get(url)
             unauthorizedResponse.statusCode shouldBe 401
 
@@ -214,7 +213,7 @@ trait WskWebActionsTests
             val name = "webaction"
             val file = Some(TestCLIUtils.getTestActionFilename("corsHeaderMod.js"))
             val host = getServiceURL()
-            val url = host + s"$testRoutePath/$namespace/default/webaction.http"
+            val url = host + s"$testRoutePath/$namespace/default/$name.http"
 
             assetHelper.withCleaner(wsk.action, name) {
                 (action, _) =>
@@ -236,7 +235,7 @@ trait WskWebActionsTests
             val name = "webaction"
             val file = Some(TestCLIUtils.getTestActionFilename("corsHeaderMod.js"))
             val host = getServiceURL()
-            val url = host + s"$testRoutePath/$namespace/default/webaction"
+            val url = host + s"$testRoutePath/$namespace/default/$name"
 
             assetHelper.withCleaner(wsk.action, name) {
                 (action, _) => action.create(name, file, web = Some("true"))
@@ -261,16 +260,15 @@ trait WskWebActionsTests
             val name = "webaction"
             val file = Some(TestCLIUtils.getTestActionFilename("echo.js"))
             val bodyContent = "This is the body"
-
-            assetHelper.withCleaner(wsk.action, name) {
-                (action, _) => action.create(name, file, web = Some("true"))
-            }
-
             val host = getServiceURL()
             val url = if (testRoutePath == "/api/v1/experimental/web") {
-                s"$host$testRoutePath/$namespace/default/webaction.text/__ow_meta_body"
+                s"$host$testRoutePath/$namespace/default/$name.text/__ow_meta_body"
             } else {
-                s"$host$testRoutePath/$namespace/default/webaction.text/__ow_body"
+                s"$host$testRoutePath/$namespace/default/$name.text/__ow_body"
+            }
+
+            assetHelper.withCleaner(wsk.action, name) {
+                (action, _) => action.create(name, file, web = Some("true"))
             }
 
             val paramRes = RestAssured.given().contentType("text/html").param("key", "value").config(sslconfig).post(url)
@@ -286,13 +284,13 @@ trait WskWebActionsTests
         (wp, assetHelper) =>
             val name = "webaction"
             val file = Some(TestCLIUtils.getTestActionFilename("textBody.js"))
+            val host = getServiceURL()
+            val url = host + s"$testRoutePath/$namespace/default/$name.http"
 
             assetHelper.withCleaner(wsk.action, name) {
                 (action, _) => action.create(name, file, web = Some("true"))
             }
 
-            val host = getServiceURL()
-            val url = host + s"$testRoutePath/$namespace/default/webaction.http"
             val response = RestAssured.given().header("accept", "application/json").config(sslconfig).get(url)
             response.statusCode shouldBe 406
             response.body.asString should include("Resource representation is only available with these types:\\ntext/html")
@@ -303,7 +301,7 @@ trait WskWebActionsTests
             val name = "webaction"
             val file = Some(TestCLIUtils.getTestActionFilename("multipleHeaders.js"))
             val host = getServiceURL()
-            val url = host + s"$testRoutePath/$namespace/default/webaction.http"
+            val url = host + s"$testRoutePath/$namespace/default/$name.http"
 
             assetHelper.withCleaner(wsk.action, name) {
                 (action, _) =>
@@ -319,4 +317,23 @@ trait WskWebActionsTests
                 new Header("Set-Cookie", "c=d")
             )
     }
+
+    it should "handle http web action with base64 encoded response" in withAssetCleaner(wskprops) {
+        (wp, assetHelper) =>
+            val name = "base64Web"
+            val file = Some(TestCLIUtils.getTestActionFilename("base64Web.js"))
+            val host = getServiceURL
+            val url = host + s"$testRoutePath/$namespace/default/$name.http"
+
+            assetHelper.withCleaner(wsk.action, name) {
+                (action, _) =>
+                    action.create(name, file, web = Some("raw"))
+            }
+
+            val response = RestAssured.given().config(sslconfig).get(url)
+
+            response.statusCode shouldBe 200
+            response.header("Content-type") shouldBe "application/json"
+            response.body.asString.parseJson.asJsObject shouldBe JsObject("status" -> "success".toJson)
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>.