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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0c34a07  Bug fix: Use configured prototcol for API requests (#300)
0c34a07 is described below

commit 0c34a07f28d98f386a34f76ba56c07521192c38f
Author: David Grove <dgrove-...@users.noreply.github.com>
AuthorDate: Wed May 30 14:59:08 2018 -0400

    Bug fix: Use configured prototcol for API requests (#300)
    
    Add check to see if Client.Config.Host already specifies the protocol
    to use before prepending https:// in URL construction.
    Fixes a bug where if .wskprops specifies a APIHOST with a protocol,
    `wsk api create` generates an invalid backend URL 
(https://https://APIHOST/...).
    
    Also add unit test to check for this error condition.
    
    Fixes #125.
---
 commands/api.go                                    |  6 +++-
 .../whisk/core/cli/test/ApiGwCliBasicTests.scala   | 42 ++++++++++++++++++++--
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/commands/api.go b/commands/api.go
index 18fb6a9..c7b4157 100644
--- a/commands/api.go
+++ b/commands/api.go
@@ -913,7 +913,11 @@ func parseApi(cmd *cobra.Command, args []string) 
(*whisk.Api, *QualifiedName, er
        } else {
                urlActionPackage = "default"
        }
-       api.Action.BackendUrl = "https://"; + Client.Config.Host + 
"/api/v1/web/" + qName.GetNamespace() + "/" + urlActionPackage + "/" + 
qName.GetEntity() + ".http"
+       backendUrl := Client.Config.Host + "/api/v1/web/" + 
qName.GetNamespace() + "/" + urlActionPackage + "/" + qName.GetEntity() + 
".http"
+       if !strings.HasPrefix(backendUrl, "http") {
+               backendUrl = "https://"; + backendUrl
+       }
+       api.Action.BackendUrl = backendUrl
        api.Action.BackendMethod = api.GatewayMethod
        api.Action.Name = qName.GetEntityName()
        api.Action.Namespace = qName.GetNamespace()
diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala 
b/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
index 2c7e64e..abc682d 100644
--- a/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwCliBasicTests.scala
@@ -109,8 +109,9 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
     rr.stdout should include(testbasepath + testrelpath)
   }
 
-  def verifyApiGet(rr: RunResult): Unit = {
+  def verifyApiGet(rr: RunResult, apihost:String): Unit = {
     rr.stdout should include regex 
(s""""operationId":\\s+"getPathWithSub_pathsInIt"""")
+    rr.stdout should include regex (s""""target-url":\\s+"https://$apihost""";)
   }
 
   def verifyApiFullList(rr: RunResult,
@@ -447,7 +448,7 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
       rr = apiList(basepathOrApiName = Some(testbasepath), relpath = 
Some(testrelpath), operation = Some(testurlop))
       verifyApiFullList(rr, clinamespace, actionName, testurlop, testbasepath, 
testrelpath, testapiname)
       rr = apiGet(basepathOrApiName = Some(testbasepath))
-      verifyApiGet(rr)
+      verifyApiGet(rr, wskprops.apihost)
       val deleteresult = apiDelete(basepathOrApiName = testbasepath)
       verifyApiDeleted(deleteresult)
     } finally {
@@ -456,6 +457,43 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
     }
   }
 
+  it should "verify successful creation and deletion of a new API when apihost 
specifies the protocol" in {
+    val testName = "CLI_APIGWTEST2"
+    val testbasepath = "/" + testName + "_bp"
+    val testrelpath = "/path/with/sub_paths/in/it"
+    val testnewrelpath = "/path_new"
+    val testurlop = "get"
+    val testapiname = testName + " API Name"
+    val actionName = testName + "_action"
+    try {
+      println("cli namespace: " + clinamespace)
+
+      // Create the action for the API.  It must be a "web-action" action.
+      val file = TestUtils.getTestActionFilename(s"echo.js")
+      wsk.action.create(name = actionName, artifact = Some(file), 
expectedExitCode = createCode, web = Some("true"))
+
+      val explicitProtocol = if (wskprops.apihost.startsWith("http")) "" else 
"https://";
+      val wskpropsOverride = WskProps(apihost = explicitProtocol + 
wskprops.apihost)
+      var rr = apiCreate(
+        basepath = Some(testbasepath),
+        relpath = Some(testrelpath),
+        operation = Some(testurlop),
+        action = Some(actionName),
+        apiname = Some(testapiname))(wskpropsOverride)
+      verifyApiCreated(rr)
+      rr = apiList(basepathOrApiName = Some(testbasepath), relpath = 
Some(testrelpath), operation = Some(testurlop))
+      verifyApiFullList(rr, clinamespace, actionName, testurlop, testbasepath, 
testrelpath, testapiname)
+      rr = apiGet(basepathOrApiName = Some(testbasepath))
+      verifyApiGet(rr, wskprops.apihost)
+      val deleteresult = apiDelete(basepathOrApiName = testbasepath)
+      verifyApiDeleted(deleteresult)
+    } finally {
+      wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
+      apiDelete(basepathOrApiName = testbasepath, expectedExitCode = 
DONTCARE_EXIT)
+    }
+  }
+
+
   it should "verify get API name " in {
     val testName = "CLI_APIGWTEST3"
     val testbasepath = "/" + testName + "_bp"

-- 
To stop receiving notification emails like this one, please contact
dube...@apache.org.

Reply via email to