openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestho...@apache.org
Subject [incubator-openwhisk-runtime-ruby] branch master updated: Fixes #14 - Support zip files without dir entries (#15)
Date Thu, 01 Nov 2018 14:54:21 GMT
This is an automated email from the ASF dual-hosted git repository.

jamesthomas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-ruby.git


The following commit(s) were added to refs/heads/master by this push:
     new 99ceec8  Fixes #14 - Support zip files without dir entries (#15)
99ceec8 is described below

commit 99ceec8e14a66ba38b0b5451228170db37e1b338
Author: James Thomas <jthomas.uk@gmail.com>
AuthorDate: Thu Nov 1 15:54:16 2018 +0100

    Fixes #14 - Support zip files without dir entries (#15)
    
    * Fixes #14 - Support zip files without dir entries
    
    Ensure directories exist before unzipping files.
    Add tests to validate this test case.
    
    * re-formating scala tests to pass ci bot
---
 .gitignore                                             |   3 ++-
 core/ruby2.5Action/rackapp/init.rb                     |   4 +++-
 tests/dat/without_dir_entries.zip                      | Bin 0 -> 592 bytes
 .../actionContainers/Ruby25ActionContainerTests.scala  |  17 +++++++++++++++++
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index ed2c749..0c3444f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,4 +69,5 @@ ansible/roles/nginx/files/*cert.pem
 !tests/dat/actions/python3_virtualenv.zip
 !tests/dat/actions/python_virtualenv_dir.zip
 !tests/dat/actions/python_virtualenv_name.zip
-!tests/dat/actions/zippedaction.zip
\ No newline at end of file
+!tests/dat/actions/zippedaction.zip
+!tests/dat/without_dir_entries.zip
diff --git a/core/ruby2.5Action/rackapp/init.rb b/core/ruby2.5Action/rackapp/init.rb
index eee1767..caefe52 100644
--- a/core/ruby2.5Action/rackapp/init.rb
+++ b/core/ruby2.5Action/rackapp/init.rb
@@ -84,7 +84,9 @@ class InitApp
     def unzip(zipfile_path, destination_folder)
       Zip::File.open(zipfile_path) do |zip|
         zip.each do |file|
-          zip.extract(file, destination_folder + file.name)
+          f_path = destination_folder + file.name
+          FileUtils.mkdir_p(File.dirname(f_path))
+          zip.extract(file, f_path)
         end
       end
       true
diff --git a/tests/dat/without_dir_entries.zip b/tests/dat/without_dir_entries.zip
new file mode 100644
index 0000000..224a5f9
Binary files /dev/null and b/tests/dat/without_dir_entries.zip differ
diff --git a/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
index 1090c14..68146bd 100644
--- a/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
+++ b/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
@@ -23,6 +23,8 @@ import common.WskActorSystem
 import actionContainers.{ActionContainer, BasicActionRunnerTests}
 import actionContainers.ActionContainer.withContainer
 import actionContainers.ResourceHelpers.ZipBuilder
+import actionContainers.ResourceHelpers
+import java.nio.file.FileSystems;
 import spray.json._
 
 @RunWith(classOf[JUnitRunner])
@@ -329,6 +331,21 @@ class Ruby25ActionContainerTests extends BasicActionRunnerTests with
WskActorSys
     }
   }
 
+  it should "support zip-encoded packages without directory entries" in {
+    val path = FileSystems.getDefault().getPath("dat", "without_dir_entries.zip");
+    val code = ResourceHelpers.readAsBase64(path)
+
+    val (out, err) = withRuby25Container { c =>
+      c.init(initPayload(code))._1 should be(200)
+
+      val (runCode, runRes) = c.run(runPayload(JsObject()))
+
+      runCode should be(200)
+      runRes.get.fields.get("greeting") shouldBe defined
+      runRes.get.fields.get("greeting") shouldBe Some(JsString("Hello stranger!"))
+    }
+  }
+
   it should "fail gracefully on invalid zip files" in {
     // Some text-file encoded to base64.
     val code = "Q2VjaSBuJ2VzdCBwYXMgdW4gemlwLgo="


Mime
View raw message