mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Validate status= filter to docker ps
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
a453da2114
commit
7bf26d44b0
3 changed files with 20 additions and 0 deletions
|
@ -53,6 +53,9 @@ func (daemon *Daemon) Containers(config *ContainersConfig) ([]*types.Container,
|
||||||
|
|
||||||
if i, ok := psFilters["status"]; ok {
|
if i, ok := psFilters["status"]; ok {
|
||||||
for _, value := range i {
|
for _, value := range i {
|
||||||
|
if !isValidStateString(value) {
|
||||||
|
return nil, errors.New("Unrecognised filter value for status")
|
||||||
|
}
|
||||||
if value == "exited" || value == "created" {
|
if value == "exited" || value == "created" {
|
||||||
all = true
|
all = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,18 @@ func (s *State) StateString() string {
|
||||||
return "exited"
|
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 {
|
func wait(waitChan <-chan struct{}, timeout time.Duration) error {
|
||||||
if timeout < 0 {
|
if timeout < 0 {
|
||||||
<-waitChan
|
<-waitChan
|
||||||
|
|
|
@ -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)
|
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) {
|
func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
|
||||||
|
|
Loading…
Reference in a new issue