openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csantan...@apache.org
Subject [incubator-openwhisk-cli] 04/36: Promote web actions from experimental (#2010)
Date Mon, 26 Jun 2017 15:59:44 GMT
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 773a55648d084bc67be3e1540656fa65110cf194
Author: James Dubee <jwdubee@us.ibm.com>
AuthorDate: Wed Mar 15 01:09:22 2017 -0400

      Promote web actions from experimental (#2010)
    
    - Remove "experimental" from web actions URL (now available on "/api/v1/web".
    - Share connection services amongst experimental and new web routes
    - Don't send CORS Header for new web routes (deferred to actions)
    - Provide additional HTTP Verbs (PATCH, HEAD, OPTIONS)
    - Increase test coverage for all allowed verbs
    - Add integration tests for web action direction OPTIONS
    - Return appropriate error message when a web action is invoked with incompatible accept
content-type header (demote autentication errors in rejection list)
    - Drop "meta" from "__ow_meta_*" property names for "v2"
    - Change "code" to "statusCode" for "v2"
    - Make .http extension optional for "v2"
    - Add .svg extension
    - Add 'raw-http' annotation to box query and body parameters (also skips parameter override
checks, conflict free by definition)
    - Hoist action validation earlier to treat request opaquely for raw-http web actions
    - Fix multiple entity matches on response/accept mismatch
    - Updated documentation, and add examples for raw-http support
---
 .../whisk/core/cli/test/WskWebActionsTests.scala   | 88 +++++++++++++++++++++-
 1 file changed, 85 insertions(+), 3 deletions(-)

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 bdb75f7..9d12be8 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
@@ -16,6 +16,8 @@
 
 package whisk.core.cli.test
 
+import java.nio.charset.StandardCharsets
+
 import org.junit.runner.RunWith
 import org.scalatest.junit.JUnitRunner
 
@@ -35,7 +37,16 @@ import system.rest.RestUtil
  * Tests web actions.
  */
 @RunWith(classOf[JUnitRunner])
-class WskWebActionsTests
+class WskWebActionsTestsV1 extends WskWebActionsTests {
+    override val testRoutePath = "/api/v1/experimental/web"
+}
+
+@RunWith(classOf[JUnitRunner])
+class WskWebActionsTestsV2 extends WskWebActionsTests {
+    override val testRoutePath = "/api/v1/web"
+}
+
+abstract class WskWebActionsTests
     extends TestHelpers
     with WskTestHelpers
     with RestUtil {
@@ -45,6 +56,7 @@ class WskWebActionsTests
     implicit val wskprops = WskProps()
     val wsk = new Wsk
     val namespace = WskAdmin.getUser(wskprops.authKey)._2
+    protected val testRoutePath: String
 
     behavior of "Wsk Web Actions"
 
@@ -62,7 +74,7 @@ class WskWebActionsTests
             }
 
             val host = getServiceURL()
-            val requestPath = host + s"/api/v1/experimental/web/$namespace/default/webaction.text/a?a="
+            val requestPath = host + s"$testRoutePath/$namespace/default/webaction.text/a?a="
             val padAmount = MAX_URL_LENGTH - requestPath.length
             Seq(("A", 200),
                 ("A" * padAmount, 200),
@@ -101,7 +113,11 @@ class WskWebActionsTests
             }
 
             val host = getServiceURL()
-            val url = host + s"/api/v1/experimental/web/$namespace/default/webaction.text/__ow_meta_namespace"
+            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
@@ -111,7 +127,73 @@ class WskWebActionsTests
                 .config(sslconfig)
                 .auth().preemptive().basic(wskprops.authKey.split(":")(0), wskprops.authKey.split(":")(1))
                 .get(url)
+
             authorizedResponse.statusCode shouldBe 200
             authorizedResponse.body().asString() shouldBe namespace
     }
+
+    if (testRoutePath == "/api/v1/web") {
+        it should "ensure that CORS header is preserved" in withAssetCleaner(wskprops) {
+            (wp, assetHelper) =>
+                val name = "webaction"
+                val file = Some(TestUtils.getTestActionFilename("corsHeaderMod.js"))
+
+                assetHelper.withCleaner(wsk.action, name) {
+                    (action, _) =>
+                        action.create(name, file, annotations = Map("web-export" -> true.toJson))
+                }
+
+                val host = getServiceURL()
+                val url = host + s"$testRoutePath/$namespace/default/webaction.http"
+
+                val response = RestAssured.given().config(sslconfig).options(url)
+                response.statusCode shouldBe 200
+                response.header("Access-Control-Allow-Origin") shouldBe "Origin set from
Web Action"
+                response.header("Access-Control-Allow-Headers") shouldBe "Headers set from
Web Action"
+        }
+    }
+
+    it should "invoke web action to ensure the returned body argument is correct" in withAssetCleaner(wskprops)
{
+        (wp, assetHelper) =>
+            val name = "webaction"
+            val file = Some(TestUtils.getTestActionFilename("echo.js"))
+            val bodyContent = "This is the body"
+
+            assetHelper.withCleaner(wsk.action, name) {
+                (action, _) =>
+                    action.create(name, file, annotations = Map("web-export" -> true.toJson))
+            }
+
+            val host = getServiceURL()
+            val url = if (testRoutePath == "/api/v1/experimental/web") {
+                s"$host$testRoutePath/$namespace/default/webaction.text/__ow_meta_body"
+            } else {
+                s"$host$testRoutePath/$namespace/default/webaction.text/__ow_body"
+            }
+
+            val paramRes = RestAssured.given().contentType("text/html").param("key", "value").config(sslconfig).post(url)
+            paramRes.statusCode shouldBe 200
+            new String(paramRes.body.asByteArray, StandardCharsets.UTF_8) shouldBe "key=value"
+
+            val bodyRes = RestAssured.given().contentType("text/html").body(bodyContent).config(sslconfig).post(url)
+            bodyRes.statusCode shouldBe 200
+            new String(bodyRes.body.asByteArray, StandardCharsets.UTF_8) shouldBe bodyContent
+    }
+
+    it should "reject invocation of web action with invalid accept header" in withAssetCleaner(wskprops)
{
+        (wp, assetHelper) =>
+            val name = "webaction"
+            val file = Some(TestUtils.getTestActionFilename("textBody.js"))
+
+            assetHelper.withCleaner(wsk.action, name) {
+                (action, _) =>
+                    action.create(name, file, annotations = Map("web-export" -> true.toJson))
+            }
+
+            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 Content-Types:\\ntext/html")
+    }
 }

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

Mime
View raw message