Skip to content

Commit

Permalink
Merge pull request #1210 from hashicorp/b-task-dashes
Browse files Browse the repository at this point in the history
Validate that tasks don't contain slashes
  • Loading branch information
dadgar committed May 28, 2016
2 parents 47979c4 + e416624 commit e06aefb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,9 @@ func (t *Task) Validate() error {
if t.Name == "" {
mErr.Errors = append(mErr.Errors, errors.New("Missing task name"))
}
if strings.ContainsAny(t.Name, `/\`) {
mErr.Errors = append(mErr.Errors, errors.New("Task name can not include slashes"))
}
if t.Driver == "" {
mErr.Errors = append(mErr.Errors, errors.New("Missing task driver"))
}
Expand Down
7 changes: 7 additions & 0 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ func TestTask_Validate(t *testing.T) {
t.Fatalf("err: %s", err)
}

task = &Task{Name: "web/foo"}
err = task.Validate()
mErr = err.(*multierror.Error)
if !strings.Contains(mErr.Errors[0].Error(), "slashes") {
t.Fatalf("err: %s", err)
}

task = &Task{
Name: "web",
Driver: "docker",
Expand Down

0 comments on commit e06aefb

Please sign in to comment.