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/07/05 17:41:01 UTC
[incubator-openwhisk-runtime-php] branch master updated: Ensure
that /init cannot be called more than once (#34)
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-runtime-php.git
The following commit(s) were added to refs/heads/master by this push:
new d5fa692 Ensure that /init cannot be called more than once (#34)
d5fa692 is described below
commit d5fa692d53861b54dcc51a9a7f5e3715cea16288
Author: Rob Allen <ro...@akrabat.com>
AuthorDate: Thu Jul 5 20:40:56 2018 +0300
Ensure that /init cannot be called more than once (#34)
---
core/php7.1Action/router.php | 5 +++++
core/php7.2Action/router.php | 5 +++++
.../runtime/actionContainers/Php7ActionContainerTests.scala | 9 +++++++++
3 files changed, 19 insertions(+)
diff --git a/core/php7.1Action/router.php b/core/php7.1Action/router.php
index 63e3a75..3c24ff3 100644
--- a/core/php7.1Action/router.php
+++ b/core/php7.1Action/router.php
@@ -91,6 +91,11 @@ function route(string $uri) : array
*/
function init() : array
{
+ // check that we haven't already been initialised
+ if (file_exists(ACTION_CONFIG_FILE)) {
+ throw new RuntimeException('Cannot initialize the action more than once.', 403);
+ }
+
// data is POSTed to us as a JSON string
$post = file_get_contents('php://input');
$data = json_decode($post, true)['value'] ?? [];
diff --git a/core/php7.2Action/router.php b/core/php7.2Action/router.php
index 6a2c570..890d55c 100644
--- a/core/php7.2Action/router.php
+++ b/core/php7.2Action/router.php
@@ -122,6 +122,11 @@ function sendResponse(array $result) : void
*/
function init() : array
{
+ // check that we haven't already been initialised
+ if (file_exists(ACTION_CONFIG_FILE)) {
+ throw new RuntimeException('Cannot initialize the action more than once.', 403);
+ }
+
// data is POSTed to us as a JSON string
$post = file_get_contents('php://input');
$data = json_decode($post, true)['value'] ?? [];
diff --git a/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala
index 8ac62c7..000d0b0 100644
--- a/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala
@@ -95,6 +95,15 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA
},
enforceEmptyOutputStream)
+ testInitCannotBeCalledMoreThanOnce("""
+ |<?php
+ |function main(array $args) : array {
+ | echo 'hello stdout';
+ | error_log('hello stderr');
+ | return $args;
+ |}
+ """.stripMargin)
+
it should "fail to initialize with bad code" in {
val (out, err) = withPhp7Container { c =>
val code = """