From 35cbb621fb9d0a079c267f45bd62ad635d18bfbd Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Mon, 6 Jul 2020 03:29:48 +0200 Subject: [PATCH] Add check on exec looking for arguments In the case where the command has arguments it fails because ACI implementation does not support commands with arguments Signed-off-by: Ulysses Souza --- azure/backend.go | 13 +++++++++++++ azure/backend_test.go | 9 +++++++++ go.sum | 2 -- tests/aci-e2e/e2e-aci_test.go | 9 +++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/azure/backend.go b/azure/backend.go index c4fc75699..caee20902 100644 --- a/azure/backend.go +++ b/azure/backend.go @@ -223,6 +223,10 @@ func getGroupAndContainerName(containerID string) (groupName string, containerNa } func (cs *aciContainerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error { + err := verifyExecCommand(command) + if err != nil { + return err + } groupName, containerAciName := getGroupAndContainerName(name) containerExecResponse, err := execACIContainer(ctx, cs.ctx, command, groupName, containerAciName) if err != nil { @@ -238,6 +242,15 @@ func (cs *aciContainerService) Exec(ctx context.Context, name string, command st ) } +func verifyExecCommand(command string) error { + tokens := strings.Split(command, " ") + if len(tokens) > 1 { + return errors.New("ACI exec command does not accept arguments to the command. " + + "Only the binary should be specified") + } + return nil +} + func (cs *aciContainerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error { groupName, containerAciName := getGroupAndContainerName(containerName) var tail *int32 diff --git a/azure/backend_test.go b/azure/backend_test.go index 9e4bc2ef6..8092c8c52 100644 --- a/azure/backend_test.go +++ b/azure/backend_test.go @@ -61,6 +61,15 @@ func (suite *BackendSuiteTest) TestErrorMessageRunSingleContainerNameWithCompose Expect(err.Error()).To(Equal("invalid container name. ACI container name cannot include \"_\"")) } +func (suite *BackendSuiteTest) TestVerifyCommand() { + err := verifyExecCommand("command") // Command without an argument + Expect(err).To(BeNil()) + err = verifyExecCommand("command argument") // Command with argument + Expect(err).NotTo(BeNil()) + Expect(err.Error()).To(Equal("ACI exec command does not accept arguments to the command. " + + "Only the binary should be specified")) +} + func TestBackendSuite(t *testing.T) { RegisterTestingT(t) suite.Run(t, new(BackendSuiteTest)) diff --git a/go.sum b/go.sum index 3af941bd1..9b7bbd9df 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,6 @@ github.com/Azure/azure-pipeline-go v0.2.1 h1:OLBdZJ3yvOn2MezlWvbrBMTEUQC72zAftRZ github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-sdk-for-go v43.3.0+incompatible h1:o0G4JAsOzeVJEwU0Ud9bh+lUHPUc0GkFENJ02dk51Uo= github.com/Azure/azure-sdk-for-go v43.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-storage-file-go v0.7.0 h1:yWoV0MYwzmoSgWACcVkdPolvAULFPNamcQLpIvS/Et4= -github.com/Azure/azure-storage-file-go v0.7.0/go.mod h1:3w3mufGcMjcOJ3w+4Gs+5wsSgkT7xDwWWqMMIrXtW4c= github.com/Azure/azure-storage-file-go v0.8.0 h1:OX8DGsleWLUE6Mw4R/OeWEZMvsTIpwN94J59zqKQnTI= github.com/Azure/azure-storage-file-go v0.8.0/go.mod h1:3w3mufGcMjcOJ3w+4Gs+5wsSgkT7xDwWWqMMIrXtW4c= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index 41687fbb6..27d9d1d0f 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -150,6 +150,15 @@ func (s *E2eACISuite) TestACIBackend() { Expect(output).To(ContainSubstring("GET")) }) + s.T().Run("exec command", func(t *testing.T) { + output := s.NewDockerCommand("exec", testContainerName, "pwd").ExecOrDie() + Expect(output).To(ContainSubstring("/")) + + output = s.NewDockerCommand("exec", testContainerName, "echo", "fail_with_argument").ExecOrDie() + Expect(output).To(ContainSubstring("ACI exec command does not accept arguments to the command. " + + "Only the binary should be specified")) + }) + s.T().Run("follow logs from nginx", func(t *testing.T) { timeChan := make(chan time.Time)