Provide system key per configuration
The Controller used to take the key used to invoke MetaAPI actions from the database, creating a hidden dependency. The subject's name and key are now provided per configuration.
Signed-off-by: Christian Bickel <cbickel@de.ibm.com>
diff --git a/tests/src/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala b/tests/src/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
index 0a5f0b8..49fd1ba 100644
--- a/tests/src/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
+++ b/tests/src/whisk/core/apigw/actions/test/ApiGwRoutemgmtActionTests.scala
@@ -19,8 +19,6 @@
import org.junit.runner.RunWith
import org.scalatest.BeforeAndAfterAll
import org.scalatest.junit.JUnitRunner
-import scala.concurrent.Await
-import scala.concurrent.duration._
import spray.json.DefaultJsonProtocol._
import spray.json._
@@ -35,12 +33,7 @@
import common.WskActorSystem
import common.WskProps
import common.WskTestHelpers
-import whisk.common.TransactionId
import whisk.core.WhiskConfig
-import whisk.core.entity.Subject
-import whisk.core.entity.WhiskEntityStore
-import whisk.core.entity.WhiskAuth
-import whisk.core.entity.WhiskAuthStore
case class ApiAction(
name: String,
@@ -75,30 +68,21 @@
val (cliuser, clinamespace) = WskAdmin.getUser(wskprops.authKey)
// Use the whisk.system authentication id and pwd for invoking whisk.system private actions
- val config = new WhiskConfig(WhiskAuthStore.requiredProperties ++ WhiskEntityStore.requiredProperties)
- val authstore = WhiskAuthStore.datastore(config)
- val whiskkey = Await.result(WhiskAuth.get(authstore, Subject("whisk.system"),false)(TransactionId.unknown), 5.seconds)
- val whisksystemAuthId = whiskkey.authkey.uuid.toString
- val whisksystemAuthPwd = whiskkey.authkey.key.toString
-
- override def afterAll() {
- println("Shutting down authstore connection")
- authstore.shutdown()
- super.afterAll()
- }
+ val config = new WhiskConfig(Map(WhiskConfig.systemKey -> null))
+ val systemKey = config.systemKey
def getApis(
- bpOrName: Option[String],
- relpath: Option[String] = None,
- operation: Option[String] = None,
- docid: Option[String] = None): Vector[JsValue] = {
- val parms = Map[String,JsValue]() ++
+ bpOrName: Option[String],
+ relpath: Option[String] = None,
+ operation: Option[String] = None,
+ docid: Option[String] = None): Vector[JsValue] = {
+ val parms = Map[String, JsValue]() ++
Map("__ow_meta_namespace" -> clinamespace.toJson) ++
- { bpOrName map { b => Map("basepath" -> b.toJson) } getOrElse Map[String,JsValue]() } ++
- { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String,JsValue]() } ++
- { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String,JsValue]() } ++
- { docid map { d => Map("docid" -> d.toJson) } getOrElse Map[String,JsValue]() }
- val wskprops = new WskProps(authKey = whisksystemAuthId+":"+whisksystemAuthPwd)
+ { bpOrName map { b => Map("basepath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
+ { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
+ { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
+ { docid map { d => Map("docid" -> d.toJson) } getOrElse Map[String, JsValue]() }
+ val wskprops = new WskProps(authKey = systemKey)
val rr = wsk.action.invoke(
name = "routemgmt/getApi",
parameters = parms,
@@ -110,30 +94,30 @@
var apisobj = rr.stdout.parseJson.asJsObject.fields("apis")
apisobj.convertTo[JsArray]
} catch {
- case e:Exception =>
+ case e: Exception =>
JsArray.empty
}
return apiJsArray.elements
}
def createApi(
- namespace: Option[String] = Some("_"),
- basepath: Option[String] = Some("/"),
- relpath: Option[String],
- operation: Option[String],
- apiname: Option[String],
- action: Option[ApiAction],
- swagger: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult ={
- val parms = Map[String,JsValue]() ++
- { namespace map { n => Map("namespace" -> n.toJson) } getOrElse Map[String,JsValue]() } ++
- { basepath map { b => Map("basepath" -> b.toJson) } getOrElse Map[String,JsValue]() } ++
- { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String,JsValue]() } ++
- { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String,JsValue]() } ++
- { apiname map { an => Map("apiname" -> an.toJson) } getOrElse Map[String,JsValue]() } ++
- { action map { a => Map("action" -> a.toJson) } getOrElse Map[String,JsValue]() } ++
- { swagger map { s => Map("swagger" -> s.toJson) } getOrElse Map[String,JsValue]() }
- val wskprops = new WskProps(authKey = whisksystemAuthId+":"+whisksystemAuthPwd)
+ namespace: Option[String] = Some("_"),
+ basepath: Option[String] = Some("/"),
+ relpath: Option[String],
+ operation: Option[String],
+ apiname: Option[String],
+ action: Option[ApiAction],
+ swagger: Option[String] = None,
+ expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
+ val parms = Map[String, JsValue]() ++
+ { namespace map { n => Map("namespace" -> n.toJson) } getOrElse Map[String, JsValue]() } ++
+ { basepath map { b => Map("basepath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
+ { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
+ { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
+ { apiname map { an => Map("apiname" -> an.toJson) } getOrElse Map[String, JsValue]() } ++
+ { action map { a => Map("action" -> a.toJson) } getOrElse Map[String, JsValue]() } ++
+ { swagger map { s => Map("swagger" -> s.toJson) } getOrElse Map[String, JsValue]() }
+ val wskprops = new WskProps(authKey = systemKey)
val rr = wsk.action.invoke(
name = "routemgmt/createApi",
parameters = parms,
@@ -144,25 +128,25 @@
}
def createRoute(
- namespace: Option[String] = Some("_"),
- basepath: Option[String] = Some("/"),
- relpath: Option[String],
- operation: Option[String],
- apiname: Option[String],
- action: Option[ApiAction],
- swagger: Option[String] = None,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult ={
- val parms = Map[String,JsValue]() ++
- { namespace map { n => Map("namespace" -> n.toJson) } getOrElse Map[String,JsValue]() } ++
- { basepath map { b => Map("gatewayBasePath" -> b.toJson) } getOrElse Map[String,JsValue]() } ++
- { relpath map { r => Map("gatewayPath" -> r.toJson) } getOrElse Map[String,JsValue]() } ++
- { operation map { o => Map("gatewayMethod" -> o.toJson) } getOrElse Map[String,JsValue]() } ++
- { apiname map { an => Map("apiName" -> an.toJson) } getOrElse Map[String,JsValue]() } ++
- { action map { a => Map("action" -> a.toJson) } getOrElse Map[String,JsValue]() } ++
- { swagger map { s => Map("swagger" -> s.toJson) } getOrElse Map[String,JsValue]() }
- val parm = Map[String,JsValue]("apidoc" -> JsObject(parms)) ++
- { namespace map { n => Map("__ow_meta_namespace" -> n.toJson) } getOrElse Map[String,JsValue]() }
- val wskprops = new WskProps(authKey = whisksystemAuthId+":"+whisksystemAuthPwd)
+ namespace: Option[String] = Some("_"),
+ basepath: Option[String] = Some("/"),
+ relpath: Option[String],
+ operation: Option[String],
+ apiname: Option[String],
+ action: Option[ApiAction],
+ swagger: Option[String] = None,
+ expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
+ val parms = Map[String, JsValue]() ++
+ { namespace map { n => Map("namespace" -> n.toJson) } getOrElse Map[String, JsValue]() } ++
+ { basepath map { b => Map("gatewayBasePath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
+ { relpath map { r => Map("gatewayPath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
+ { operation map { o => Map("gatewayMethod" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
+ { apiname map { an => Map("apiName" -> an.toJson) } getOrElse Map[String, JsValue]() } ++
+ { action map { a => Map("action" -> a.toJson) } getOrElse Map[String, JsValue]() } ++
+ { swagger map { s => Map("swagger" -> s.toJson) } getOrElse Map[String, JsValue]() }
+ val parm = Map[String, JsValue]("apidoc" -> JsObject(parms)) ++
+ { namespace map { n => Map("__ow_meta_namespace" -> n.toJson) } getOrElse Map[String, JsValue]() }
+ val wskprops = new WskProps(authKey = systemKey)
val rr = wsk.action.invoke(
name = "routemgmt/createRoute",
parameters = parm,
@@ -173,21 +157,21 @@
}
def deleteApi(
- namespace: Option[String] = Some("_"),
- basepath: Option[String] = Some("/"),
- relpath: Option[String] = None,
- operation: Option[String] = None,
- apiname: Option[String] = None,
- force: Boolean = true,
- expectedExitCode: Int = SUCCESS_EXIT): RunResult ={
- val parms = Map[String,JsValue]() ++
- Map("force" -> force.toJson) ++
- { namespace map { n => Map("__ow_meta_namespace" -> n.toJson) } getOrElse Map[String,JsValue]() } ++
- { basepath map { b => Map("basepath" -> b.toJson) } getOrElse Map[String,JsValue]() } ++
- { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String,JsValue]() } ++
- { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String,JsValue]() } ++
- { apiname map { an => Map("apiname" -> an.toJson) } getOrElse Map[String,JsValue]() }
- val wskprops = new WskProps(authKey = whisksystemAuthId+":"+whisksystemAuthPwd)
+ namespace: Option[String] = Some("_"),
+ basepath: Option[String] = Some("/"),
+ relpath: Option[String] = None,
+ operation: Option[String] = None,
+ apiname: Option[String] = None,
+ force: Boolean = true,
+ expectedExitCode: Int = SUCCESS_EXIT): RunResult = {
+ val parms = Map[String, JsValue]() ++
+ Map("force" -> force.toJson) ++
+ { namespace map { n => Map("__ow_meta_namespace" -> n.toJson) } getOrElse Map[String, JsValue]() } ++
+ { basepath map { b => Map("basepath" -> b.toJson) } getOrElse Map[String, JsValue]() } ++
+ { relpath map { r => Map("relpath" -> r.toJson) } getOrElse Map[String, JsValue]() } ++
+ { operation map { o => Map("operation" -> o.toJson) } getOrElse Map[String, JsValue]() } ++
+ { apiname map { an => Map("apiname" -> an.toJson) } getOrElse Map[String, JsValue]() }
+ val wskprops = new WskProps(authKey = systemKey)
val rr = wsk.action.invoke(
name = "routemgmt/deleteApi",
parameters = parms,
@@ -198,13 +182,12 @@
}
def apiMatch(
- apiarr: Vector[JsValue],
- basepath: String = "/",
- relpath: String = "",
- operation: String = "",
- apiname: String = "",
- action: ApiAction = null
- ): Boolean = {
+ apiarr: Vector[JsValue],
+ basepath: String = "/",
+ relpath: String = "",
+ operation: String = "",
+ apiname: String = "",
+ action: ApiAction = null): Boolean = {
var matches: Boolean = false
for (api <- apiarr) {
val basepathExists = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "basePath")
@@ -212,16 +195,16 @@
System.out.println("basePath exists")
val basepathMatches = (JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "basePath").get.convertTo[String] == basepath)
if (basepathMatches) {
- System.out.println("basePath matches: "+basepath)
+ System.out.println("basePath matches: " + basepath)
val apinameExists = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "info", "title")
if (apinameExists) {
System.out.println("api name exists")
val apinameMatches = (JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "info", "title").get.convertTo[String] == apiname)
if (apinameMatches) {
- System.out.println("api name matches: "+apiname)
+ System.out.println("api name matches: " + apiname)
val endpointMatches = JsObjectHelper(api.asJsObject).fieldPathExists("value", "apidoc", "paths", relpath, operation)
if (endpointMatches) {
- System.out.println("endpoint exists/matches : "+relpath+" "+operation)
+ System.out.println("endpoint exists/matches : " + relpath + " " + operation)
val actionConfig = JsObjectHelper(api.asJsObject).getFieldPath("value", "apidoc", "paths", relpath, operation, "x-ibm-op-ext").get.asJsObject
val actionMatches = actionMatch(actionConfig, action)
if (actionMatches) {
@@ -238,13 +221,12 @@
}
def actionMatch(
- jsAction: JsObject,
- action: ApiAction
- ): Boolean = {
+ jsAction: JsObject,
+ action: ApiAction): Boolean = {
val matches = jsAction.fields("backendMethod").convertTo[String] == action.backendMethod &&
- jsAction.fields("backendUrl").convertTo[String] == action.backendUrl &&
- jsAction.fields("actionNamespace").convertTo[String] == action.namespace &&
- jsAction.fields("actionName").convertTo[String] == action.name
+ jsAction.fields("backendUrl").convertTo[String] == action.backendUrl &&
+ jsAction.fields("actionNamespace").convertTo[String] == action.namespace &&
+ jsAction.fields("actionName").convertTo[String] == action.name
return matches
}
@@ -252,17 +234,16 @@
it should "verify successful creation of a new API" in {
val testName = "APIGWTEST1"
- val testbasepath = "/"+testName+"_bp"
+ val testbasepath = "/" + testName + "_bp"
val testrelpath = "/path"
val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
+ val testapiname = testName + " API Name"
+ val actionName = testName + "_action"
val actionNamespace = clinamespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/"+actionNamespace+"/actions/"+actionName
- val actionAuthKey = testName+"_authkey"
+ val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
-
try {
val createResult = createRoute(namespace = Some(clinamespace), basepath = Some(testbasepath), relpath = Some(testrelpath),
operation = Some(testurlop), apiname = Some(testapiname), action = Some(testaction))
@@ -270,22 +251,21 @@
val apiVector = getApis(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
apiVector.size should be > 0
apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
- }
- finally {
+ } finally {
val deleteResult = deleteApi(namespace = Some(clinamespace), basepath = Some(testbasepath), force = true, expectedExitCode = DONTCARE_EXIT)
}
}
it should "verify successful API deletion using basepath" in {
val testName = "APIGWTEST2"
- val testbasepath = "/"+testName+"_bp"
+ val testbasepath = "/" + testName + "_bp"
val testrelpath = "/path"
val testurlop = "get"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
+ val testapiname = testName + " API Name"
+ val actionName = testName + "_action"
val actionNamespace = clinamespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/"+actionNamespace+"/actions/"+actionName
- val actionAuthKey = testName+"_authkey"
+ val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
try {
@@ -298,24 +278,23 @@
val deleteResult = deleteApi(namespace = Some(clinamespace), basepath = Some(testbasepath), force = true)
apiVector = getApis(bpOrName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(false)
- }
- finally {
+ } finally {
val deleteResult = deleteApi(namespace = Some(clinamespace), basepath = Some(testbasepath), force = true, expectedExitCode = DONTCARE_EXIT)
}
}
it should "verify successful addition of new relative path to existing API" in {
val testName = "APIGWTEST3"
- val testbasepath = "/"+testName+"_bp"
+ val testbasepath = "/" + testName + "_bp"
val testrelpath = "/path"
val testnewrelpath = "/path_new"
val testurlop = "get"
val testnewurlop = "delete"
- val testapiname = testName+" API Name"
- val actionName = testName+"_action"
+ val testapiname = testName + " API Name"
+ val actionName = testName + "_action"
val actionNamespace = clinamespace
- val actionUrl = "http://some.whisk.host/api/v1/namespaces/"+actionNamespace+"/actions/"+actionName
- val actionAuthKey = testName+"_authkey"
+ val actionUrl = "http://some.whisk.host/api/v1/namespaces/" + actionNamespace + "/actions/" + actionName
+ val actionAuthKey = testName + "_authkey"
val testaction = ApiAction(name = actionName, namespace = actionNamespace, backendUrl = actionUrl, authkey = actionAuthKey)
try {
@@ -328,8 +307,7 @@
apiVector.size should be > 0
apiMatch(apiVector, testbasepath, testrelpath, testurlop, testapiname, testaction) should be(true)
apiMatch(apiVector, testbasepath, testnewrelpath, testnewurlop, testapiname, testaction) should be(true)
- }
- finally {
+ } finally {
val deleteResult = deleteApi(namespace = Some(clinamespace), basepath = Some(testbasepath), force = true, expectedExitCode = DONTCARE_EXIT)
}
}
@@ -343,7 +321,7 @@
("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "namespace is required", Seq("-p", "basepath", "/ApiGwRoutemgmtActionTests_bp")),
("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "basepath is required", Seq("-p", "__ow_meta_namespace", "_")),
("/whisk.system/routemgmt/deleteApi", ANY_ERROR_EXIT, "When specifying an operation, the relpath is required",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp", "-p", "operation", "get")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp", "-p", "operation", "get")),
//deactivateApi
("/whisk.system/routemgmt/deactivateApi", ANY_ERROR_EXIT, "namespace is required", Seq("-p", "basepath", "/ApiGwRoutemgmtActionTests_bp")),
@@ -354,118 +332,118 @@
//createApi
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "namespace is required",
- Seq(
- //"-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get",
- "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
+ Seq(
+ //"-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get",
+ "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "basepath is required when swagger is not specified",
- Seq(
- "-p", "namespace", "_",
- //"-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get",
- "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
+ Seq(
+ "-p", "namespace", "_",
+ //"-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get",
+ "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "relpath is required when swagger is not specified",
- Seq(
- "-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- //"-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get",
- "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
+ Seq(
+ "-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ //"-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get",
+ "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "operation is required when swagger is not specified",
- Seq(
- "-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- //"-p", "operation", "get",
- "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
+ Seq(
+ "-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ //"-p", "operation", "get",
+ "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is required when swagger is not specified",
- Seq(
- "-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get"
- //"-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}"""
- )),
+ Seq(
+ "-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get"
+ //"-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}"""
+ )),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the backendUrl field",
- Seq(
- "-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get",
- "-p", "action", """{"backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
+ Seq(
+ "-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get",
+ "-p", "action", """{"backendMethod":"get","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the backendMethod field",
- Seq(
- "-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get",
- "-p", "action", """{"backendUrl":"URL","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
+ Seq(
+ "-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get",
+ "-p", "action", """{"backendUrl":"URL","namespace":"_","name":"myaction","authkey":"XXXXX"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the namespace field",
- Seq(
- "-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get",
- "-p", "action", """{"backendUrl":"URL","backendMethod":"get","name":"myaction","authkey":"XXXXX"}""")),
+ Seq(
+ "-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get",
+ "-p", "action", """{"backendUrl":"URL","backendMethod":"get","name":"myaction","authkey":"XXXXX"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the name field",
- Seq(
- "-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get",
- "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","authkey":"XXXXX"}""")),
+ Seq(
+ "-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get",
+ "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","authkey":"XXXXX"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "action is missing the authkey field",
- Seq(
- "-p", "namespace", "_",
- "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
- "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
- "-p", "operation", "get",
- "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction"}""")),
+ Seq(
+ "-p", "namespace", "_",
+ "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp",
+ "-p", "relpath", "/ApiGwRoutemgmtActionTests_rp",
+ "-p", "operation", "get",
+ "-p", "action", """{"backendUrl":"URL","backendMethod":"get","namespace":"_","name":"myaction"}""")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "swagger field cannot be parsed. Ensure it is valid JSON",
- Seq("-p", "namespace", "_", "-p", "swagger", "{1:[}}}")),
+ Seq("-p", "namespace", "_", "-p", "swagger", "{1:[}}}")),
("/whisk.system/routemgmt/createApi", ANY_ERROR_EXIT, "swagger and basepath are mutually exclusive and cannot be specified together",
- Seq("-p", "namespace", "_", "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp", "-p", "swagger", "{}")),
+ Seq("-p", "namespace", "_", "-p", "basepath", "/ApiGwRoutemgmtActionTests_bp", "-p", "swagger", "{}")),
//createRoute
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "apidoc is required", Seq("-p", "__ow_meta_namespace", "_")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "apidoc is missing the namespace field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", "{}")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", "{}")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "apidoc is missing the gatewayBasePath field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_"}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_"}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "apidoc is missing the gatewayPath field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp"}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp"}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "apidoc is missing the gatewayMethod field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp"}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp"}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "apidoc is missing the action field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get"}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get"}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "action is missing the backendMethod field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{}}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{}}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "action is missing the backendUrl field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post"}}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post"}}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "action is missing the namespace field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL"}}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL"}}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "action is missing the name field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_"}}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_"}}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "action is missing the authkey field",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_","name":"N"}}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_","name":"N"}}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "swagger and gatewayBasePath are mutually exclusive and cannot be specified together",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_","name":"N","authkey":"XXXX"},"swagger":{}}""")),
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", """{"namespace":"_","gatewayBasePath":"/ApiGwRoutemgmtActionTests_bp","gatewayPath":"ApiGwRoutemgmtActionTests_rp","gatewayMethod":"get","action":{"backendMethod":"post","backendUrl":"URL","namespace":"_","name":"N","authkey":"XXXX"},"swagger":{}}""")),
("/whisk.system/routemgmt/createRoute", ANY_ERROR_EXIT, "apidoc field cannot be parsed. Ensure it is valid JSON",
- Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", "{1:[}}}"))
+ Seq("-p", "__ow_meta_namespace", "_", "-p", "apidoc", "{1:[}}}"))
)
invalidArgs foreach {
- case (action:String, exitcode:Int, errmsg:String, params:Seq[String]) =>
+ case (action: String, exitcode: Int, errmsg: String, params: Seq[String]) =>
var cmd: Seq[String] = Seq("action",
"invoke",
action,
"-i", "-b", "-r",
"--apihost", wskprops.apihost,
- "--auth", whisksystemAuthId+":"+whisksystemAuthPwd
+ "--auth", systemKey
) ++ params
val rr = wsk.cli(cmd, expectedExitCode = exitcode)
rr.stderr should include regex (errmsg)
diff --git a/tests/src/whisk/core/controller/test/MetaApiTests.scala b/tests/src/whisk/core/controller/test/MetaApiTests.scala
index f2d6b8e..63b77ef 100644
--- a/tests/src/whisk/core/controller/test/MetaApiTests.scala
+++ b/tests/src/whisk/core/controller/test/MetaApiTests.scala
@@ -39,6 +39,8 @@
import whisk.core.entity._
import whisk.http.ErrorResponse
import whisk.http.Messages
+import scala.concurrent.Await
+import whisk.core.entitlement.Privilege
/**
* Tests Meta API.
@@ -58,9 +60,9 @@
override val apipath = "api"
override val apiversion = "v1"
- val subject = Subject()
- override val systemId = subject.asString
- override lazy val systemKey = Future.successful(WhiskAuth(subject, AuthKey()).toIdentity)
+ val systemId = Subject()
+ override lazy val systemKey = AuthKey()
+ override lazy val systemIdentity = Future.successful(Identity(systemId, EntityName(systemId.asString), systemKey, Privilege.ALL))
/** Meta API tests */
behavior of "Meta API"
@@ -71,41 +73,41 @@
val packages = Seq(
WhiskPackage(
- EntityPath(systemId),
+ EntityPath(systemId.asString),
EntityName("notmeta"),
annotations = Parameters("meta", JsBoolean(false))),
WhiskPackage(
- EntityPath(systemId),
+ EntityPath(systemId.asString),
EntityName("badmeta"),
annotations = Parameters("meta", JsBoolean(true))),
WhiskPackage(
- EntityPath(systemId),
+ EntityPath(systemId.asString),
EntityName("heavymeta"),
annotations = Parameters("meta", JsBoolean(true)) ++
Parameters("get", JsString("getApi")) ++
Parameters("post", JsString("createRoute")) ++
Parameters("delete", JsString("deleteApi"))),
WhiskPackage(
- EntityPath(systemId),
+ EntityPath(systemId.asString),
EntityName("partialmeta"),
annotations = Parameters("meta", JsBoolean(true)) ++
Parameters("get", JsString("getApi"))),
WhiskPackage(
- EntityPath(systemId),
+ EntityPath(systemId.asString),
EntityName("packagemeta"),
parameters = Parameters("x", JsString("X")) ++ Parameters("z", JsString("z")),
annotations = Parameters("meta", JsBoolean(true)) ++
Parameters("get", JsString("getApi"))),
WhiskPackage(
- EntityPath(systemId),
+ EntityPath(systemId.asString),
EntityName("publicmeta"),
publish = true,
annotations = Parameters("meta", JsBoolean(true)) ++
Parameters("get", JsString("getApi"))),
WhiskPackage(
- EntityPath(systemId),
+ EntityPath(systemId.asString),
EntityName("bindingmeta"),
- Some(Binding(EntityName(systemId), EntityName("heavymeta"))),
+ Some(Binding(EntityName(systemId.asString), EntityName("heavymeta"))),
annotations = Parameters("meta", JsBoolean(true))))
override protected[controller] def invokeAction(user: Identity, action: WhiskAction, payload: Option[JsObject], blocking: Boolean, waitOverride: Boolean = false)(
@@ -131,7 +133,8 @@
// check that action parameters were merged with package
// all actions have default parameters (see actionLookup stub)
- pkgLookup(resolvePackageName(action.namespace.last)) foreach { pkg =>
+ val packageName = Await.result(resolvePackageName(action.namespace.last), dbOpTimeout)
+ pkgLookup(packageName) foreach { pkg =>
action.parameters shouldBe (pkg.parameters ++ defaultActionParameters)
action.parameters.get("z") shouldBe defaultActionParameters.get("z")
}
@@ -193,7 +196,8 @@
}
it should "resolve a meta package into the systemId namespace" in {
- resolvePackageName(EntityName("foo")).fullPath.asString shouldBe s"$systemId/foo"
+ val packageName = Await.result(resolvePackageName(EntityName("foo")), dbOpTimeout)
+ packageName.fullPath.asString shouldBe s"$systemId/foo"
}
it should "reject unsupported http verbs" in {