rabbah closed pull request #3473: Support string based status code from actions. URL: https://github.com/apache/incubator-openwhisk/pull/3473
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): 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 b0cd6ba231..708ad71df8 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 36555b92e3..59d4b8e2ca 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) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services