You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by du...@apache.org on 2018/08/02 15:05:10 UTC

[incubator-openwhisk] branch master updated: Fix for exception being thrown during api creation (#3907)

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.git


The following commit(s) were added to refs/heads/master by this push:
     new 7072350  Fix for exception being thrown during api creation (#3907)
7072350 is described below

commit 707235023ac5bd59b498aa11765967d4da8e295b
Author: Mark Deuser <md...@us.ibm.com>
AuthorDate: Thu Aug 2 11:05:05 2018 -0400

    Fix for exception being thrown during api creation (#3907)
    
    * before accessing the target-url field, ensure the entire path to that field exists
    
    * update tests to cover this fix
---
 core/routemgmt/common/apigw-utils.js               |  2 +-
 tests/dat/apigw/testswaggerdoc1                    | 78 ++++++++++++++++++++++
 .../whisk/core/cli/test/ApiGwRestBasicTests.scala  |  5 +-
 3 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/core/routemgmt/common/apigw-utils.js b/core/routemgmt/common/apigw-utils.js
index 84d4104..8187633 100644
--- a/core/routemgmt/common/apigw-utils.js
+++ b/core/routemgmt/common/apigw-utils.js
@@ -41,7 +41,7 @@ function generateTargetUrlMap(ibmConfig) {
         var execs = element['execute'];
         //each nth element of execs and operations go together, so lets add those to the map.
         for (var i = 0; i < operations.length ; ++i) {
-          if(i < execs.length && execs[i] && execs[i]['invoke']['target-url']) {
+          if(i < execs.length && execs[i] && execs[i]['invoke'] && execs[i]['invoke']['target-url']) {
             targetUrls[operations[i]] = execs[i]['invoke']['target-url'];
           }
         }
diff --git a/tests/dat/apigw/testswaggerdoc1 b/tests/dat/apigw/testswaggerdoc1
index 623ae43..c515477 100644
--- a/tests/dat/apigw/testswaggerdoc1
+++ b/tests/dat/apigw/testswaggerdoc1
@@ -21,6 +21,38 @@
                     "url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http"
                 }
             }
+        },
+        "/pathSecure1": {
+            "get": {
+                "operationId": "get_/pathSecure1",
+                "responses": {
+                    "default": {
+                        "description": "Default response"
+                    }
+                },
+                "x-openwhisk": {
+                    "action": "CLI_APIGWTEST7_action",
+                    "namespace": "whisk.system",
+                    "package": "",
+                    "url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http"
+                }
+            }
+        },
+        "/pathSecure2": {
+            "get": {
+                "operationId": "get_/pathSecure2",
+                "responses": {
+                    "default": {
+                        "description": "Default response"
+                    }
+                },
+                "x-openwhisk": {
+                    "action": "CLI_APIGWTEST7_action",
+                    "namespace": "whisk.system",
+                    "package": "",
+                    "url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http"
+                }
+            }
         }
     },
     "x-ibm-configuration": {
@@ -51,6 +83,52 @@
                                 "operations": [
                                     "get_/path"
                                 ]
+                            },
+                            {
+                                "execute": [
+                                    {
+                                        "invoke": {
+                                            "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http",
+                                            "verb": "keep"
+                                        }
+                                    },
+                                    {
+                                        "set-variable": {
+                                            "actions": [
+                                                {
+                                                    "set": "message.headers.X-Require-Whisk-Auth",
+                                                    "value": "my-secret"
+                                                }
+                                            ]
+                                        }
+                                    }
+                                ],
+                                "operations": [
+                                    "get_/pathSecure1"
+                                ]
+                            },
+                            {
+                                "execute": [
+                                    {
+                                        "set-variable": {
+                                            "actions": [
+                                                {
+                                                    "set": "message.headers.X-Require-Whisk-Auth",
+                                                    "value": "my-secret"
+                                                }
+                                            ]
+                                        }
+                                    },
+                                    {
+                                        "invoke": {
+                                            "target-url": "https://172.17.0.1/api/v1/web/whisk.system/default/CLI_APIGWTEST7_action.http",
+                                            "verb": "keep"
+                                        }
+                                    }
+                                ],
+                                "operations": [
+                                    "get_/pathSecure2"
+                                ]
                             }
                         ]
                     }
diff --git a/tests/src/test/scala/whisk/core/cli/test/ApiGwRestBasicTests.scala b/tests/src/test/scala/whisk/core/cli/test/ApiGwRestBasicTests.scala
index 97b903a..0947225 100644
--- a/tests/src/test/scala/whisk/core/cli/test/ApiGwRestBasicTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/ApiGwRestBasicTests.scala
@@ -521,6 +521,8 @@ abstract class ApiGwRestBasicTests extends BaseApiGwTests {
     val testName = "CLI_APIGWTEST7"
     val testbasepath = "/" + testName + "_bp"
     val testrelpath = "/path"
+    val testrelpath1 = "/pathSecure1"
+    val testrelpath2 = "/pathSecure2"
     val testurlop = "get"
     val testapiname = testName + " API Name"
     val actionName = testName + "_action"
@@ -530,7 +532,8 @@ abstract class ApiGwRestBasicTests extends BaseApiGwTests {
       verifyApiCreated(rr)
       rr = apiList(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
       verifyApiFullList(rr, "", actionName, testurlop, testbasepath, testrelpath, testapiname)
-
+      verifyApiFullList(rr, "", actionName, testurlop, testbasepath, testrelpath1, testapiname)
+      verifyApiFullList(rr, "", actionName, testurlop, testbasepath, testrelpath2, testapiname)
     } finally {
       apiDelete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
     }