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/06/30 23:30:14 UTC

[incubator-openwhisk] branch master updated: Add default allow headers. (#2451)

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.git


The following commit(s) were added to refs/heads/master by this push:
     new 38b1df9  Add default allow headers. (#2451)
38b1df9 is described below

commit 38b1df93efcefda198db3cd78d2b3f8b0afc83d8
Author: rodric rabbah <ro...@gmail.com>
AuthorDate: Fri Jun 30 19:30:11 2017 -0400

    Add default allow headers. (#2451)
---
 ansible/group_vars/all                                            | 2 +-
 ansible/roles/cli/files/createContentJson.sh                      | 2 +-
 .../src/main/scala/whisk/core/controller/WebActions.scala         | 8 +++++---
 tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala | 3 ++-
 .../scala/whisk/core/controller/test/WebActionsApiTests.scala     | 1 +
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/ansible/group_vars/all b/ansible/group_vars/all
index 2c78b29..da24b84 100644
--- a/ansible/group_vars/all
+++ b/ansible/group_vars/all
@@ -284,7 +284,7 @@ openwhisk_cli:
 #    name: OpenWhisk_CLI
 #    dest_name: OpenWhisk_CLI
 #    location: "https://github.com/apache/incubator-openwhisk-cli/releases/download/{{ openwhisk_cli_tag }}"
- 
+
 # The list of operating systems for which openwhisk cli binaries are downloaded,
 # if the installation_mode is remote.
 cli_os:
diff --git a/ansible/roles/cli/files/createContentJson.sh b/ansible/roles/cli/files/createContentJson.sh
index 6171568..cc59622 100755
--- a/ansible/roles/cli/files/createContentJson.sh
+++ b/ansible/roles/cli/files/createContentJson.sh
@@ -27,7 +27,7 @@ get_binary_path() {
     if [ $os = "linux" ]; then
         comp_name="$comp_name.tgz"
     else
-    		comp_name="$comp_name.zip"
+        comp_name="$comp_name.zip"
     fi
     echo $os/$arch/$comp_name;
 };
diff --git a/core/controller/src/main/scala/whisk/core/controller/WebActions.scala b/core/controller/src/main/scala/whisk/core/controller/WebActions.scala
index a7cefab..9ac63ff 100644
--- a/core/controller/src/main/scala/whisk/core/controller/WebActions.scala
+++ b/core/controller/src/main/scala/whisk/core/controller/WebActions.scala
@@ -318,8 +318,10 @@ trait WhiskWebActionsApi
     private lazy val validNameSegment = pathPrefix(EntityName.REGEX.r)
     private lazy val packagePrefix = pathPrefix("default".r | EntityName.REGEX.r)
 
-    private val allowOrigin = `Access-Control-Allow-Origin`(AllOrigins)
-    private val allowMethods = `Access-Control-Allow-Methods`(OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH)
+    private val defaultCorsResponse = List(
+        `Access-Control-Allow-Origin`(AllOrigins),
+        `Access-Control-Allow-Methods`(OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH),
+        `Access-Control-Allow-Headers`(`Authorization`.name, `Content-Type`.name))
 
     /** Extracts the HTTP method, headers, query params and unmatched (remaining) path. */
     private val requestMethodParamsAndPath = {
@@ -414,7 +416,7 @@ trait WhiskWebActionsApi
                                 onComplete(verifyWebAction(fullActionName, onBehalfOf.isDefined)) {
                                     case Success((actionOwnerIdentity, action)) =>
                                         if (!action.annotations.asBool("web-custom-options").exists(identity)) {
-                                            respondWithHeaders(allowOrigin, allowMethods) {
+                                            respondWithHeaders(defaultCorsResponse) {
                                                 if (context.method == OPTIONS) {
                                                     complete(OK, HttpEntity.Empty)
                                                 } else {
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 5a1a653..7c1e014 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskWebActionsTests.scala
@@ -225,8 +225,8 @@ trait WskWebActionsTests
 
             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"
             response.header("Access-Control-Allow-Methods") shouldBe "Methods set from Web Action"
+            response.header("Access-Control-Allow-Headers") shouldBe "Headers set from Web Action"
             response.header("Location") shouldBe "openwhisk.org"
             response.header("Set-Cookie") shouldBe "cookie-cookie-cookie"
     }
@@ -250,6 +250,7 @@ trait WskWebActionsTests
                 response.statusCode shouldBe 200
                 response.header("Access-Control-Allow-Origin") shouldBe "*"
                 response.header("Access-Control-Allow-Methods") shouldBe "OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH"
+                response.header("Access-Control-Allow-Headers") shouldBe "Authorization, Content-Type"
                 response.header("Location") shouldBe null
                 response.header("Set-Cookie") shouldBe null
             }
diff --git a/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala b/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala
index af57577..ebf1f2d 100644
--- a/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala
@@ -1138,6 +1138,7 @@ trait WebActionsApiTests extends ControllerTestCommon with BeforeAndAfterEach wi
                         m(s"$testRoutePath/$path") ~> sealRoute(routes(creds)) ~> check {
                             header("Access-Control-Allow-Origin").get.toString shouldBe "Access-Control-Allow-Origin: *"
                             header("Access-Control-Allow-Methods").get.toString shouldBe "Access-Control-Allow-Methods: OPTIONS, GET, DELETE, POST, PUT, HEAD, PATCH"
+                            header("Access-Control-Allow-Headers").get.toString shouldBe "Access-Control-Allow-Headers: Authorization, Content-Type"
                         }
                     }
                 }

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