You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/11/15 20:31:00 UTC
[GitHub] dubeejw closed pull request #2964: Reject requests to create packages having the name 'default'
dubeejw closed pull request #2964: Reject requests to create packages having the name 'default'
URL: https://github.com/apache/incubator-openwhisk/pull/2964
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/common/scala/src/main/scala/whisk/http/ErrorResponse.scala b/common/scala/src/main/scala/whisk/http/ErrorResponse.scala
index 51305789ce..f8d948df60 100644
--- a/common/scala/src/main/scala/whisk/http/ErrorResponse.scala
+++ b/common/scala/src/main/scala/whisk/http/ErrorResponse.scala
@@ -106,6 +106,9 @@ object Messages {
val bindingCannotReferenceBinding = "Cannot bind to another package binding."
val requestedBindingIsNotValid = "Cannot bind to a resource that is not a package."
val notAllowedOnBinding = "Operation not permitted on package binding."
+ def packageNameIsReserved(name: String) = {
+ s"Package name '$name' is reserved."
+ }
/** Error messages for sequence activations. */
def sequenceRetrieveActivationTimeout(id: ActivationId) =
diff --git a/core/controller/src/main/scala/whisk/core/controller/Packages.scala b/core/controller/src/main/scala/whisk/core/controller/Packages.scala
index 4ea7657ab6..e97f31628c 100644
--- a/core/controller/src/main/scala/whisk/core/controller/Packages.scala
+++ b/core/controller/src/main/scala/whisk/core/controller/Packages.scala
@@ -43,6 +43,8 @@ trait WhiskPackagesApi extends WhiskCollectionAPI with ReferencedEntities {
protected override val collection = Collection(Collection.PACKAGES)
+ protected[core] val RESERVED_NAMES = Array("default")
+
/** Database service to CRUD packages. */
protected val entityStore: EntityStore
@@ -76,25 +78,29 @@ trait WhiskPackagesApi extends WhiskCollectionAPI with ReferencedEntities {
*/
override def create(user: Identity, entityName: FullyQualifiedEntityName)(implicit transid: TransactionId) = {
parameter('overwrite ? false) { overwrite =>
- entity(as[WhiskPackagePut]) { content =>
- val request = content.resolve(entityName.namespace)
+ if (!overwrite && (RESERVED_NAMES contains entityName.name.asString)) {
+ terminate(BadRequest, Messages.packageNameIsReserved(entityName.name.asString))
+ } else {
+ entity(as[WhiskPackagePut]) { content =>
+ val request = content.resolve(entityName.namespace)
- request.binding.map { b =>
- logging.info(this, "checking if package is accessible")
- }
- val referencedentities = referencedEntities(request)
+ request.binding.map { b =>
+ logging.info(this, "checking if package is accessible")
+ }
+ val referencedentities = referencedEntities(request)
- onComplete(entitlementProvider.check(user, Privilege.READ, referencedentities)) {
- case Success(_) =>
- putEntity(
- WhiskPackage,
- entityStore,
- entityName.toDocId,
- overwrite,
- update(request) _,
- () => create(request, entityName))
- case Failure(f) =>
- rewriteEntitlementFailure(f)
+ onComplete(entitlementProvider.check(user, Privilege.READ, referencedentities)) {
+ case Success(_) =>
+ putEntity(
+ WhiskPackage,
+ entityStore,
+ entityName.toDocId,
+ overwrite,
+ update(request) _,
+ () => create(request, entityName))
+ case Failure(f) =>
+ rewriteEntitlementFailure(f)
+ }
}
}
}
diff --git a/tests/src/test/scala/whisk/core/controller/test/PackagesApiTests.scala b/tests/src/test/scala/whisk/core/controller/test/PackagesApiTests.scala
index 54e20e75b6..aad482d850 100644
--- a/tests/src/test/scala/whisk/core/controller/test/PackagesApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/PackagesApiTests.scala
@@ -41,7 +41,6 @@ import whisk.http.Messages
* These tests exercise a fresh instance of the service object in memory -- these
* tests do NOT communication with a whisk deployment.
*
- *
* @Idioglossia
* "using Specification DSL to write unit tests, as in should, must, not, be"
* "using Specs2RouteTest DSL to chain HTTP requests for unit testing, as in ~>"
@@ -370,6 +369,34 @@ class PackagesApiTests extends ControllerTestCommon with WhiskPackagesApi {
}
}
+ it should "reject create package when package name is a reserved name" in {
+ implicit val tid = transid()
+ RESERVED_NAMES foreach { reservedName =>
+ val provider = WhiskPackage(namespace, EntityName(s"$reservedName"), None)
+ val content = WhiskPackagePut()
+ Put(s"$collectionPath/${provider.name}", content) ~> Route.seal(routes(creds)) ~> check {
+ status should be(BadRequest)
+ val response = responseAs[String]
+ response should include {
+ Messages.packageNameIsReserved(reservedName)
+ }
+ }
+ }
+ }
+
+ it should "allow package update even when package name a reserved name" in {
+ implicit val tid = transid()
+ RESERVED_NAMES foreach { reservedName =>
+ val provider = WhiskPackage(namespace, EntityName(s"$reservedName"), None)
+ val content = WhiskPackagePut()
+ Put(s"$collectionPath/${provider.name}?overwrite=true", content) ~> Route.seal(routes(creds)) ~> check {
+ status should be(OK)
+ val response = responseAs[WhiskPackage]
+ response should be(provider)
+ }
+ }
+ }
+
it should "create package reference with explicit namespace" in {
implicit val tid = transid()
val provider = WhiskPackage(namespace, aname())
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services