-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate stack-names for empty values
Add validation for stack names to prevent an empty name resulting in _all_ stacks to be returned after filtering, which can result in removal of services for all stacks if `--prune`, or `docker stack rm` is used. Before this change; docker stack deploy -c docker-compose.yml one docker stack deploy -c docker-compose.yml two docker stack deploy -c docker-compose.yml three docker stack deploy -c docker-compose.yml --prune '' Removing service one_web Removing service two_web Removing service three_web After this change: docker stack deploy -c docker-compose.yml one docker stack deploy -c docker-compose.yml two docker stack deploy -c docker-compose.yml three docker stack deploy -c docker-compose.yml --prune '' invalid stack name: "" Other stack commands were updated as well: Before this change; docker stack deploy -c docker-compose.yml '' Creating network _default failed to create network _default: Error response from daemon: rpc error: code = InvalidArgument desc = name must be valid as a DNS name component docker stack ps '' nothing found in stack: docker stack rm '' Removing service one_web Removing service three_web Removing service two_web After this change: docker stack deploy -c docker-compose.yml '' invalid stack name: "" docker stack ps '' invalid stack name: "" docker stack rm '' invalid stack name: "" Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Loading branch information
Showing
11 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package swarm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/docker/cli/cli/command/stack/options" | ||
"github.com/docker/cli/internal/test" | ||
"github.com/gotestyourself/gotestyourself/assert" | ||
is "github.com/gotestyourself/gotestyourself/assert/cmp" | ||
) | ||
|
||
func TestRunPSWithEmptyName(t *testing.T) { | ||
client := &fakeClient{} | ||
dockerCli := test.NewFakeCli(client) | ||
|
||
err := RunPS(dockerCli, options.PS{Namespace: "' '"}) | ||
assert.Check(t, is.Error(err, `invalid stack name: "' '"`)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package swarm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/docker/cli/cli/command/stack/options" | ||
"github.com/docker/cli/internal/test" | ||
"github.com/gotestyourself/gotestyourself/assert" | ||
is "github.com/gotestyourself/gotestyourself/assert/cmp" | ||
) | ||
|
||
func TestRunRemoveWithEmptyName(t *testing.T) { | ||
client := &fakeClient{} | ||
dockerCli := test.NewFakeCli(client) | ||
|
||
err := RunRemove(dockerCli, options.Remove{Namespaces: []string{"good", "' '", "alsogood"}}) | ||
assert.Check(t, is.Error(err, `invalid stack name: "' '"`)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package swarm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/docker/cli/cli/command/stack/options" | ||
"github.com/docker/cli/internal/test" | ||
"github.com/gotestyourself/gotestyourself/assert" | ||
is "github.com/gotestyourself/gotestyourself/assert/cmp" | ||
) | ||
|
||
func TestRunServicesWithEmptyName(t *testing.T) { | ||
client := &fakeClient{} | ||
dockerCli := test.NewFakeCli(client) | ||
|
||
err := RunServices(dockerCli, options.Services{Namespace: "' '"}) | ||
assert.Check(t, is.Error(err, `invalid stack name: "' '"`)) | ||
} |