Limit entity names.
diff --git a/tests/src/whisk/core/controller/test/ActionsApiTests.scala b/tests/src/whisk/core/controller/test/ActionsApiTests.scala
index d423b2e..fbb2208 100644
--- a/tests/src/whisk/core/controller/test/ActionsApiTests.scala
+++ b/tests/src/whisk/core/controller/test/ActionsApiTests.scala
@@ -169,6 +169,32 @@
}
}
+ it should "reject long entity names" in {
+ implicit val tid = transid()
+ val longName = "a" * (EntityName.ENTITY_NAME_MAX_LENGTH + 1)
+ Get(s"/$longName/${collection.path}/$longName") ~> sealRoute(routes(creds)) ~> check {
+ status should be(BadRequest)
+ responseAs[String] shouldBe {
+ Messages.entityNameTooLong(
+ SizeError(namespaceDescriptionForSizeError, longName.length.B, EntityName.ENTITY_NAME_MAX_LENGTH.B))
+ }
+ }
+
+ Seq(s"/$namespace/${collection.path}/$longName",
+ s"/$namespace/${collection.path}/pkg/$longName",
+ s"/$namespace/${collection.path}/$longName/a",
+ s"/$namespace/${collection.path}/$longName/$longName").
+ foreach { p =>
+ Get(p) ~> sealRoute(routes(creds)) ~> check {
+ status should be(BadRequest)
+ responseAs[String] shouldBe {
+ Messages.entityNameTooLong(
+ SizeError(segmentDescriptionForSizeError, longName.length.B, EntityName.ENTITY_NAME_MAX_LENGTH.B))
+ }
+ }
+ }
+ }
+
//// DEL /actions/name
it should "delete action by name" in {
implicit val tid = transid()
diff --git a/tests/src/whisk/core/controller/test/ActivationsApiTests.scala b/tests/src/whisk/core/controller/test/ActivationsApiTests.scala
index da02c1f..ccfbb0b 100644
--- a/tests/src/whisk/core/controller/test/ActivationsApiTests.scala
+++ b/tests/src/whisk/core/controller/test/ActivationsApiTests.scala
@@ -28,6 +28,7 @@
import spray.json.DefaultJsonProtocol._
import whisk.core.controller.WhiskActivationsApi
import whisk.core.entity._
+import whisk.core.entity.size._
import whisk.http.ErrorResponse
import whisk.http.Messages
@@ -302,12 +303,12 @@
Get(s"$collectionPath/$tooshort") ~> sealRoute(routes(creds)) ~> check {
status should be(BadRequest)
- responseAs[String] should include("too short")
+ responseAs[String] shouldBe Messages.activationIdLengthError(SizeError("Activation id", tooshort.length.B, 32.B))
}
Get(s"$collectionPath/$toolong") ~> sealRoute(routes(creds)) ~> check {
status should be(BadRequest)
- responseAs[String] should include("too long")
+ responseAs[String] shouldBe Messages.activationIdLengthError(SizeError("Activation id", toolong.length.B, 32.B))
}
Get(s"$collectionPath/$malformed") ~> sealRoute(routes(creds)) ~> check {
diff --git a/tests/src/whisk/core/entity/test/SchemaTests.scala b/tests/src/whisk/core/entity/test/SchemaTests.scala
index 958675e..86f9f84 100644
--- a/tests/src/whisk/core/entity/test/SchemaTests.scala
+++ b/tests/src/whisk/core/entity/test/SchemaTests.scala
@@ -23,6 +23,7 @@
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps
import scala.language.reflectiveCalls
+import scala.util.Failure
import scala.util.Try
import org.junit.runner.RunWith
@@ -36,6 +37,7 @@
import whisk.core.entitlement.Privilege
import whisk.core.entity._
import whisk.core.entity.size.SizeInt
+import whisk.http.Messages
import whisk.utils.JsHelpers
@RunWith(classOf[JUnitRunner])
@@ -159,14 +161,14 @@
behavior of "EntityName"
it should "accept well formed names" in {
- val paths = Seq("a", "a b", "a@b.c", "_a", "_", "_ _", "a0", "a 0", "a.0", "a@@", "0", "0.0", "0.0.0", "0a", "0.a")
+ val paths = Seq("a", "a b", "a@b.c", "_a", "_", "_ _", "a0", "a 0", "a.0", "a@@", "0", "0.0", "0.0.0", "0a", "0.a", "a"*EntityName.ENTITY_NAME_MAX_LENGTH)
paths.foreach { n =>
assert(EntityName(n).toString == n)
}
}
it should "reject malformed names" in {
- val paths = Seq(null, "", " ", " xxx", "xxx ", "/", " /", "/ ", "0 ", "_ ", "a ", "a \t", "a\n")
+ val paths = Seq(null, "", " ", " xxx", "xxx ", "/", " /", "/ ", "0 ", "_ ", "a ", "a \t", "a\n", "a"*(EntityName.ENTITY_NAME_MAX_LENGTH+1))
paths.foreach {
p => an[IllegalArgumentException] should be thrownBy EntityName(p)
}
@@ -541,19 +543,25 @@
it should "not parse invalid activation id" in {
val id = "213174381920559471141441e111111z"
assert(ActivationId.unapply(id).isEmpty)
- assert(Try { ActivationId.serdes.read(JsString(id)) }.failed.get.getMessage.contains("malformed"))
+ Try(ActivationId.serdes.read(JsString(id))) shouldBe Failure {
+ DeserializationException(Messages.activationIdIllegal)
+ }
}
it should "not parse activation id if longer than uuid" in {
val id = "213174381920559471141441e1111111abc"
assert(ActivationId.unapply(id).isEmpty)
- assert(Try { ActivationId.serdes.read(JsString(id)) }.failed.get.getMessage.contains("too long"))
+ Try(ActivationId.serdes.read(JsString(id))) shouldBe Failure {
+ DeserializationException(Messages.activationIdLengthError(SizeError("Activation id", id.length.B, 32.B)))
+ }
}
it should "not parse activation id if shorter than uuid" in {
val id = "213174381920559471141441e1"
- assert(ActivationId.unapply(id).isEmpty)
- assert(Try { ActivationId.serdes.read(JsString(id)) }.failed.get.getMessage.contains("too short"))
+ ActivationId.unapply(id) shouldBe empty
+ Try(ActivationId.serdes.read(JsString(id))) shouldBe Failure {
+ DeserializationException(Messages.activationIdLengthError(SizeError("Activation id", id.length.B, 32.B)))
+ }
}
behavior of "Js Helpers"