Skip to content

Commit

Permalink
Merge pull request d2iq-archive#1203 from mesosphere/wip-1176-drexin
Browse files Browse the repository at this point in the history
fixes d2iq-archive#1176 - Don't allow / as id for AppDefinition or AppUpdate, but al...
  • Loading branch information
ConnorDoyle committed Feb 18, 2015
2 parents 8dc4961 + d378d6f commit e6cd021
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/mesosphere/marathon/api/v2/json/Formats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ trait Formats
}

implicit lazy val PathIdFormat: Format[PathId] = Format(
Reads.of[String](Reads.minLength[String](1)).map(PathId(_)).filterNot(_.isRoot),
Reads.of[String](Reads.minLength[String](1)).map(PathId(_)),
Writes[PathId] { id => JsString(id.toString) }
)

Expand Down Expand Up @@ -340,7 +340,7 @@ trait AppDefinitionFormats {
val executorPattern = "^(//cmd)|(/?[^/]+(/[^/]+)*)|$".r

(
(__ \ "id").read[PathId] ~
(__ \ "id").read[PathId].filterNot(_.isRoot) ~
(__ \ "cmd").readNullable[String] ~
(__ \ "args").readNullable[Seq[String]] ~
(__ \ "user").readNullable[String] ~
Expand Down Expand Up @@ -429,7 +429,7 @@ trait AppDefinitionFormats {
implicit lazy val AppUpdateReads: Reads[AppUpdate] = {

(
(__ \ "id").readNullable[PathId] ~
(__ \ "id").readNullable[PathId].filterNot(_.exists(_.isRoot)) ~
(__ \ "cmd").readNullable[String] ~
(__ \ "args").readNullable[Seq[String]] ~
(__ \ "user").readNullable[String] ~
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package mesosphere.marathon.api.v2.json

import mesosphere.marathon.MarathonSpec
import mesosphere.marathon.api.v2.AppUpdate
import play.api.libs.json.{ Json, JsResultException }

class AppUpdateFormatTest extends MarathonSpec {
import Formats._

// regression test for #1176
test("should fail if id is /") {
val json = """{"id": "/"}"""
intercept[JsResultException] {
Json.parse(json).as[AppUpdate]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mesosphere.marathon.api.v2.json

import mesosphere.marathon.MarathonSpec
import mesosphere.marathon.state.Group
import play.api.libs.json.Json

class GroupFormatTest extends MarathonSpec {
import Formats._

// regression test for #1176
test("allow / as id") {
val json = """{"id": "/"}"""

assert(Json.parse(json).as[Group].id.isRoot)
}
}

0 comments on commit e6cd021

Please sign in to comment.