Add check about filter name for containers
Fixes: #21202 We add valid check about filters like network, images, volumes did. Signed-off-by: Kai Qiang Wu(Kennan) <wkqwu@cn.ibm.com>
This commit is contained in:
parent
133b3cccb5
commit
8a90e8a19b
2 changed files with 24 additions and 0 deletions
|
@ -20,6 +20,19 @@ var acceptedVolumeFilterTags = map[string]bool{
|
|||
"dangling": true,
|
||||
}
|
||||
|
||||
var acceptedPsFilterTags = map[string]bool{
|
||||
"ancestor": true,
|
||||
"before": true,
|
||||
"exited": true,
|
||||
"id": true,
|
||||
"isolation": true,
|
||||
"label": true,
|
||||
"name": true,
|
||||
"status": true,
|
||||
"since": true,
|
||||
"volume": true,
|
||||
}
|
||||
|
||||
// iterationAction represents possible outcomes happening during the container iteration.
|
||||
type iterationAction int
|
||||
|
||||
|
@ -128,7 +141,12 @@ func (daemon *Daemon) reducePsContainer(container *container.Container, ctx *lis
|
|||
func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listContext, error) {
|
||||
psFilters := config.Filter
|
||||
|
||||
if err := psFilters.Validate(acceptedPsFilterTags); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var filtExited []int
|
||||
|
||||
err := psFilters.WalkValues("exited", func(value string) error {
|
||||
code, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
|
|
|
@ -213,6 +213,12 @@ func assertContainerList(out string, expected []string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersInvalidFilterName(c *check.C) {
|
||||
out, _, err := dockerCmdWithError("ps", "-f", "invalidFilter=test")
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(out, checker.Contains, "Invalid filter")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
||||
// Problematic on Windows as it doesn't report the size correctly @swernli
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
|
Loading…
Add table
Reference in a new issue