Skip to content

Commit

Permalink
Validate status= filter to docker ps
Browse files Browse the repository at this point in the history
Signed-off-by: John Howard <[email protected]>
  • Loading branch information
John Howard committed Jul 2, 2015
1 parent a453da2 commit 7bf26d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions daemon/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container,

if i, ok := psFilters["status"]; ok {
for _, value := range i {
if !isValidStateString(value) {
return nil, errors.New("Unrecognised filter value for status")
}
if value == "exited" || value == "created" {
all = true
}
Expand Down
12 changes: 12 additions & 0 deletions daemon/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ func (s *State) StateString() string {
return "exited"
}

func isValidStateString(s string) bool {
if s != "paused" &&
s != "restarting" &&
s != "running" &&
s != "dead" &&
s != "created" &&
s != "exited" {
return false
}
return true
}

func wait(waitChan <-chan struct{}, timeout time.Duration) error {
if timeout < 0 {
<-waitChan
Expand Down
5 changes: 5 additions & 0 deletions integration-cli/docker_cli_ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
c.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out)
}

out, _, _ = dockerCmdWithTimeout(time.Second*60, "ps", "-a", "-q", "--filter=status=rubbish")
if !strings.Contains(out, "Unrecognised filter value for status") {
c.Fatalf("Expected error response due to invalid status filter output: %q", out)
}

}

func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
Expand Down

0 comments on commit 7bf26d4

Please sign in to comment.