Add more boundary checking to pass new test cases
diff --git a/core/ruby2.5Action/rackapp/init.rb b/core/ruby2.5Action/rackapp/init.rb
index d5316e8..55f7151 100644
--- a/core/ruby2.5Action/rackapp/init.rb
+++ b/core/ruby2.5Action/rackapp/init.rb
@@ -5,10 +5,21 @@
class InitApp
include Filepath
- def call(env)
+ def call(env)
+ # Make sure that this action is not initialised more than once
+ if File.exist? CONFIG then
+ return ErrorResponse.new 'Cannot initialize the action more than once.', 403
+ end
+
# Expect JSON data input
body = Rack::Request.new(env).body.read
data = JSON.parse(body)['value'] || {}
+
+ # Is the input data empty?
+ if data == {} then
+ return ErrorResponse.new 'Missing main/no code to execute.', 500
+ end
+
name = data['name'] || '' # action name
main = data['main'] || '' # function to call
code = data['code'] || '' # source code to run
@@ -79,4 +90,4 @@
rescue
false
end
-end
\ No newline at end of file
+end
diff --git a/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
index cd23809..6622cc0 100644
--- a/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
+++ b/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
@@ -145,19 +145,6 @@
})
}
- it should "fail to initialize with no code" in {
- val (out, err) = withRuby25Container { c =>
- val code = ""
-
- val (initCode, error) = c.init(initPayload(code))
-
- initCode should not be (200)
- error shouldBe a[Some[_]]
- error.get shouldBe a[JsObject]
- error.get.fields("error").toString should include("method checking failed")
- }
- }
-
it should "return some error on action error" in {
val (out, err) = withRuby25Container { c =>
val code = """
@@ -407,20 +394,6 @@
})
}
- it should "support actions using non-default entry point" in {
- val (out, err) = withRuby25Container { c =>
- val code = """
- | def niam(args)
- | { :result => "it works" }
- | end
- """.stripMargin
-
- c.init(initPayload(code, main = "niam"))._1 should be(200)
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("result") shouldBe Some(JsString("it works"))
- }
- }
-
it should "support zipped actions using non-default entry point" in {
val srcs = Seq(Seq("main.rb") -> """
| def niam(args)