You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2017/06/26 15:59:52 UTC

[incubator-openwhisk-cli] 12/36: Disable HTML Encoding of JSON Content in CLI (#2043)

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

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

commit 51da32a5cf1fd26768034d27139a413efd2f213e
Author: James Dubee <jw...@us.ibm.com>
AuthorDate: Thu Mar 30 15:29:25 2017 -0400

    Disable HTML Encoding of JSON Content in CLI (#2043)
    
    * Disable HTML Encoding of JSON Content
    
    - Do not encode &, <, and > to \u0026, \u003c, and \u003e
    
    * Remove Extra New Line When Printing JSON
    
    * Update Test
---
 .../src/test/scala/system/basic/WskActionTests.scala |  2 +-
 .../src/test/scala/system/basic/WskBasicTests.scala  |  9 +++++----
 tests/src/test/scala/system/basic/WskRuleTests.scala |  4 ++--
 .../whisk/core/cli/test/WskBasicUsageTests.scala     | 20 ++++++++++++++++++++
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/tests/src/test/scala/system/basic/WskActionTests.scala b/tests/src/test/scala/system/basic/WskActionTests.scala
index d7b7dbe..45f8da4 100644
--- a/tests/src/test/scala/system/basic/WskActionTests.scala
+++ b/tests/src/test/scala/system/basic/WskActionTests.scala
@@ -247,7 +247,7 @@ class WskActionTests
             withActivation(wsk.activation, run2) {
                 activation =>
                     activation.response.status shouldBe "success"
-                    activation.logs.get.mkString(" ") should include(s"hello $testString")
+                    activation.logs.get.mkString(" ") should include(s"hello, $testString")
             }
     }
 
diff --git a/tests/src/test/scala/system/basic/WskBasicTests.scala b/tests/src/test/scala/system/basic/WskBasicTests.scala
index db3f944..6d81100 100644
--- a/tests/src/test/scala/system/basic/WskBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskBasicTests.scala
@@ -291,7 +291,8 @@ class WskBasicTests
 
             wsk.action.get(name, fieldFilter = Some("name")).stdout should include(s"""$successMsg name\n"$name"""")
             wsk.action.get(name, fieldFilter = Some("version")).stdout should include(s"""$successMsg version\n"0.0.1"""")
-            wsk.action.get(name, fieldFilter = Some("exec")).stdout should include regex (s"""$successMsg exec\n\\{\\s+"kind":\\s+"nodejs:6",\\s+"code":\\s+"\\/\\*\\*[\\\\r]*\\\\n \\* Hello, world.[\\\\r]*\\\\n \\*\\/[\\\\r]*\\\\nfunction main\\(params\\) \\{[\\\\r]*\\\\n    console.log\\('hello', params.payload\\+'!'\\);[\\\\r]*\\\\n\\}[\\\\r]*\\\\n"\n\\}""")
+            wsk.action.get(name, fieldFilter = Some("exec")).stdout should include (s"""$successMsg""")
+            wsk.action.get(name, fieldFilter = Some("exec")).stdout should include regex (s"""$successMsg exec\n\\{\\s+"kind":\\s+"nodejs:6",\\s+"code":\\s+"\\/\\*\\*[\\\\r]*\\\\n \\* Hello, world.[\\\\r]*\\\\n \\*\\/[\\\\r]*\\\\nfunction main\\(params\\) \\{[\\\\r]*\\\\n    greeting \\= 'hello, ' \\+ params.payload \\+ '!'[\\\\r]*\\\\n    console.log\\(greeting\\);[\\\\r]*\\\\n    return \\{payload: greeting\\}[\\\\r]*\\\\n\\}""")
             wsk.action.get(name, fieldFilter = Some("parameters")).stdout should include regex (s"""$successMsg parameters\n\\[\\s+\\{\\s+"key":\\s+"payload",\\s+"value":\\s+"test"\\s+\\}\\s+\\]""")
             wsk.action.get(name, fieldFilter = Some("annotations")).stdout should include regex (s"""$successMsg annotations\n\\[\\s+\\{\\s+"key":\\s+"exec",\\s+"value":\\s+"nodejs:6"\\s+\\}\\s+\\]""")
             wsk.action.get(name, fieldFilter = Some("limits")).stdout should include regex (s"""$successMsg limits\n\\{\\s+"timeout":\\s+60000,\\s+"memory":\\s+256,\\s+"logs":\\s+10\\s+\\}""")
@@ -396,13 +397,13 @@ class WskBasicTests
         (wp, assetHelper) =>
             val name = "emptyJSONAction"
 
-            val res = assetHelper.withCleaner(wsk.action, name) {
+            assetHelper.withCleaner(wsk.action, name) {
                 (action, _) =>
                     action.create(name, Some(TestUtils.getTestActionFilename("emptyJSONResult.js")))
-                    action.invoke(name, blocking = true, result = true)
             }
 
-            res.stdout shouldBe ("{}\n")
+            val stdout = wsk.action.invoke(name, blocking = true, result = true).stdout
+            stdout.parseJson.asJsObject shouldBe JsObject()
     }
 
     it should "create, and invoke an action that times out to ensure the proper response is received" in withAssetCleaner(wskprops) {
diff --git a/tests/src/test/scala/system/basic/WskRuleTests.scala b/tests/src/test/scala/system/basic/WskRuleTests.scala
index aef370d..6b3ce51 100644
--- a/tests/src/test/scala/system/basic/WskRuleTests.scala
+++ b/tests/src/test/scala/system/basic/WskRuleTests.scala
@@ -312,7 +312,7 @@ class WskRuleTests
                         _.head.response.result shouldBe Some(testResult)
                     }
                     withActivationsFromEntity(wsk.activation, actionName2, since = Some(triggerActivation.start)) {
-                        _.head.logs.get.mkString(" ") should include(s"hello $testString")
+                        _.head.logs.get.mkString(" ") should include(s"hello, $testString")
                     }
             }
     }
@@ -350,7 +350,7 @@ class WskRuleTests
                         activations =>
                             // drops the leftmost 39 characters (timestamp + streamname)
                             val logs = activations.map(_.logs.get.map(_.drop(39))).flatten
-                            val expectedLogs = testPayloads.map { payload => s"hello $payload!" }
+                            val expectedLogs = testPayloads.map { payload => s"hello, $payload!" }
 
                             logs should contain theSameElementsAs expectedLogs
                     }
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
index 7ee62ff..d8adf1c 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
@@ -609,6 +609,26 @@ class WskBasicUsageTests
             wsk.action.create(name, file, web = Some(invalidInput), update = true, expectedExitCode = ERROR_EXIT).stderr should include(errorMsg)
     }
 
+    it should "invoke action while not encoding &, <, > characters" in withAssetCleaner(wskprops) {
+        (wp, assetHelper) =>
+            val name = "nonescape"
+            val file = Some(TestUtils.getTestActionFilename("hello.js"))
+            val nonescape = "&<>"
+            val input = Map("payload" -> nonescape.toJson)
+            val output = JsObject("payload" -> JsString(s"hello, $nonescape!"))
+
+            assetHelper.withCleaner(wsk.action, name) {
+                (action, _) => action.create(name, file)
+            }
+
+            withActivation(wsk.activation, wsk.action.invoke(name, parameters = input)) {
+                activation =>
+                    activation.response.success shouldBe true
+                    activation.response.result shouldBe Some(output)
+                    activation.logs.toList.flatten.filter(_.contains(nonescape)).length shouldBe 1
+            }
+    }
+
     behavior of "Wsk packages"
 
     it should "create, and delete a package" in {

-- 
To stop receiving notification emails like this one, please contact
"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>.