You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/03/26 12:02:33 UTC

[incubator-openwhisk] branch master updated: Support string based status code from actions. (#3473)

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

rabbah 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 5017bfb  Support string based status code from actions. (#3473)
5017bfb is described below

commit 5017bfbc23b7b768edcd7b9f70b74d0ab121b40f
Author: Tzu-Chiao Yeh <su...@gmail.com>
AuthorDate: Mon Mar 26 20:02:30 2018 +0800

    Support string based status code from actions. (#3473)
    
    Add an additional option to parse status code from string to int, throws
    out illegal code if parsing failed. Adds relevant tests.
    
    Signed-off-by: Tzu-Chiao Yeh <su...@gmail.com>
---
 .../src/main/scala/whisk/core/controller/WebActions.scala |  9 ++++++---
 .../whisk/core/controller/test/WebActionsApiTests.scala   | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

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 b0cd6ba..708ad71 100644
--- a/core/controller/src/main/scala/whisk/core/controller/WebActions.scala
+++ b/core/controller/src/main/scala/whisk/core/controller/WebActions.scala
@@ -233,11 +233,14 @@ protected[core] object WhiskWebActionsApi extends Directives {
 
       val code = fields.get(rp.statusCode).map {
         case JsNumber(c) =>
-          // the following throws an exception if the code is
-          // not a whole number or a valid code
+          // the following throws an exception if the code is not a whole number or a valid code
           StatusCode.int2StatusCode(c.toIntExact)
+        case JsString(c) =>
+          // parse the string to an Int (not a BigInt) matching JsNumber case match above
+          // c.toInt could throw an exception if the string isn't an integer
+          StatusCode.int2StatusCode(c.toInt)
 
-        case _ => throw new Throwable("Illegal code")
+        case _ => throw new Throwable("Illegal status code")
       }
 
       body.collect {
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 36555b9..59d4b8e 100644
--- a/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala
@@ -1711,6 +1711,21 @@ trait WebActionsApiBaseTests extends ControllerTestCommon with BeforeAndAfterEac
           }
         }
     }
+
+    it should s"allowed string based status code (auth? ${creds.isDefined})" in {
+      implicit val tid = transid()
+      invocationsAllowed += 2
+
+      actionResult = Some(JsObject(webApiDirectives.statusCode -> JsString("200")))
+      Head(s"$testRoutePath/$systemId/proxy/export_c.http") ~> Route.seal(routes(creds)) ~> check {
+        status should be(OK)
+      }
+
+      actionResult = Some(JsObject(webApiDirectives.statusCode -> JsString("xyz")))
+      Head(s"$testRoutePath/$systemId/proxy/export_c.http") ~> Route.seal(routes(creds)) ~> check {
+        status should be(BadRequest)
+      }
+    }
   }
 
   class TestingEntitlementProvider(config: WhiskConfig, loadBalancer: LoadBalancer)

-- 
To stop receiving notification emails like this one, please contact
rabbah@apache.org.