Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Fixes #1446 - Disallow empty strings for app.cmd
Browse files Browse the repository at this point in the history
Also treat no app.args as None instead of Some(Seq.empty)
  • Loading branch information
Peter Kolloch committed May 21, 2015
1 parent d8f6223 commit 51c270e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"type": "integer"
},
"cmd": {
"type": "string"
"type": "string",
"minLength": 1
},
"constraints": {},
"container": {
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/mesosphere/marathon/api/v2/json/Formats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ trait AppDefinitionFormats {

(
(__ \ "id").read[PathId].filterNot(_.isRoot) ~
(__ \ "cmd").readNullable[String] ~
(__ \ "cmd").readNullable[String](Reads.minLength(1)) ~
(__ \ "args").readNullable[Seq[String]] ~
(__ \ "user").readNullable[String] ~
(__ \ "env").readNullable[Map[String, String]].withDefault(DefaultEnv) ~
Expand Down Expand Up @@ -442,7 +442,7 @@ trait AppDefinitionFormats {

(
(__ \ "id").readNullable[PathId].filterNot(_.exists(_.isRoot)) ~
(__ \ "cmd").readNullable[String] ~
(__ \ "cmd").readNullable[String](Reads.minLength(1)) ~
(__ \ "args").readNullable[Seq[String]] ~
(__ \ "user").readNullable[String] ~
(__ \ "env").readNullable[Map[String, String]] ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ case class AppDefinition(
else None

val argsOption =
if (commandOption.isEmpty)
if (commandOption.isEmpty && proto.getCmd.getArgumentsCount != 0)
Some(proto.getCmd.getArgumentsList.asScala.to[Seq])
else None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ class AppDefinitionTest extends MarathonSpec with Matchers {
validateJsonSchema(app2, false) // no id
}

test("Validation: empty cmd should fail") {
val app1 = AppDefinition(
id = "play".toPath,
cmd = Some("")
)
validateJsonSchema(app1, valid = false)
}

test("Validation") {
val validator = Validation.buildDefaultValidatorFactory().getValidator

Expand Down

0 comments on commit 51c270e

Please sign in to comment.