Skip to content

Commit 44379b8

Browse files
authored
This is to make sure activations for a shared action run in an invocation namespace. (#5296)
1 parent f29981a commit 44379b8

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

tests/src/test/scala/common/WskTestHelpers.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ object ActivationResponse extends DefaultJsonProtocol {
9595
* @param annotations a list of JSON objects to save the annotations of the activation
9696
*/
9797
case class ActivationResult(activationId: String,
98+
namespace: String,
9899
logs: Option[List[String]],
99100
response: ActivationResponse,
100101
start: Instant,
@@ -123,14 +124,14 @@ object ActivationResult extends DefaultJsonProtocol {
123124
}
124125

125126
implicit val serdes = new RootJsonFormat[ActivationResult] {
126-
private val format = jsonFormat8(ActivationResult.apply)
127+
private val format = jsonFormat9(ActivationResult.apply)
127128

128129
def write(result: ActivationResult) = format.write(result)
129130

130131
def read(value: JsValue) = {
131132
val obj = value.asJsObject
132-
obj.getFields("activationId", "response", "start") match {
133-
case Seq(JsString(activationId), response, start) =>
133+
obj.getFields("activationId", "namespace", "response", "start") match {
134+
case Seq(JsString(activationId), JsString(namespace), response, start) =>
134135
Try {
135136
val logs = obj.fields.get("logs").map(_.convertTo[List[String]])
136137
val end = obj.fields.get("end").map(_.convertTo[Instant]).getOrElse(Instant.EPOCH)
@@ -139,6 +140,7 @@ object ActivationResult extends DefaultJsonProtocol {
139140
val annotations = obj.fields.get("annotations").map(_.convertTo[List[JsObject]])
140141
new ActivationResult(
141142
activationId,
143+
namespace,
142144
logs,
143145
response.convertTo[ActivationResponse],
144146
start.convertTo[Instant],

tests/src/test/scala/system/basic/WskActivationTests.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,32 @@ class WskActivationTests extends TestHelpers with WskTestHelpers with WskActorSy
5151
resultWithoutSize shouldBe expectedResult
5252
}
5353
}
54+
55+
it should "invoke a shared action under a different invocation namespace" in withAssetCleaner(wskprops) {
56+
(wp, assetHelper) =>
57+
val packageName = "shared-package"
58+
val actionName = "echo"
59+
var invocationNamesapce = if (wskprops.namespace == "_") "guest" else wskprops.namespace
60+
val packageActionName = s"/${invocationNamesapce}/${packageName}/${actionName}"
61+
62+
assetHelper.withCleaner(wsk.pkg, packageName) { (pkg, _) =>
63+
pkg.create(packageName, shared = Some(true))(wp)
64+
}
65+
66+
assetHelper.withCleaner(wsk.action, packageActionName) { (action, _) =>
67+
action.create(packageActionName, Some(TestUtils.getTestActionFilename("echo.js")))(wp)
68+
}
69+
70+
withActivation(wsk.activation, wsk.action.invoke(packageActionName)(wp)) { activation =>
71+
activation.namespace shouldBe invocationNamesapce
72+
}(wp)
73+
74+
val systemId = "whisk.system"
75+
val wskprops2 = WskProps(authKey = WskAdmin.listKeys(systemId)(0)._1, namespace = systemId)
76+
invocationNamesapce = if (wskprops2.namespace == "_") "guest" else wskprops2.namespace
77+
78+
withActivation(wsk.activation, wsk.action.invoke(packageActionName)(wskprops2)) { activation =>
79+
activation.namespace shouldBe invocationNamesapce
80+
}(wskprops2)
81+
}
5482
}

0 commit comments

Comments
 (0)