Merge pull request #14306 from Microsoft/validatepsfilter

Validate status= filter to docker ps
This commit is contained in:
Brian Goff 2015-07-10 15:43:01 -04:00
commit 20ac0e6164
3 changed files with 20 additions and 0 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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) {