Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 16acc36

Browse files
authored
Merge pull request #356 from docker/fix-non-interactive
Add check on exec looking for arguments
2 parents de4ba33 + 35cbb62 commit 16acc36

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

azure/backend.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func getGroupAndContainerName(containerID string) (groupName string, containerNa
193193
}
194194

195195
func (cs *aciContainerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
196+
err := verifyExecCommand(command)
197+
if err != nil {
198+
return err
199+
}
196200
groupName, containerAciName := getGroupAndContainerName(name)
197201
containerExecResponse, err := execACIContainer(ctx, cs.ctx, command, groupName, containerAciName)
198202
if err != nil {
@@ -208,6 +212,15 @@ func (cs *aciContainerService) Exec(ctx context.Context, name string, command st
208212
)
209213
}
210214

215+
func verifyExecCommand(command string) error {
216+
tokens := strings.Split(command, " ")
217+
if len(tokens) > 1 {
218+
return errors.New("ACI exec command does not accept arguments to the command. " +
219+
"Only the binary should be specified")
220+
}
221+
return nil
222+
}
223+
211224
func (cs *aciContainerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error {
212225
groupName, containerAciName := getGroupAndContainerName(containerName)
213226
var tail *int32

azure/backend_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ func (suite *BackendSuiteTest) TestErrorMessageRunSingleContainerNameWithCompose
6161
Expect(err.Error()).To(Equal("invalid container name. ACI container name cannot include \"_\""))
6262
}
6363

64+
func (suite *BackendSuiteTest) TestVerifyCommand() {
65+
err := verifyExecCommand("command") // Command without an argument
66+
Expect(err).To(BeNil())
67+
err = verifyExecCommand("command argument") // Command with argument
68+
Expect(err).NotTo(BeNil())
69+
Expect(err.Error()).To(Equal("ACI exec command does not accept arguments to the command. " +
70+
"Only the binary should be specified"))
71+
}
72+
6473
func TestBackendSuite(t *testing.T) {
6574
RegisterTestingT(t)
6675
suite.Run(t, new(BackendSuiteTest))

tests/aci-e2e/e2e-aci_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ func (s *E2eACISuite) TestACIBackend() {
150150
Expect(output).To(ContainSubstring("GET"))
151151
})
152152

153+
s.T().Run("exec command", func(t *testing.T) {
154+
output := s.NewDockerCommand("exec", testContainerName, "pwd").ExecOrDie()
155+
Expect(output).To(ContainSubstring("/"))
156+
157+
output = s.NewDockerCommand("exec", testContainerName, "echo", "fail_with_argument").ExecOrDie()
158+
Expect(output).To(ContainSubstring("ACI exec command does not accept arguments to the command. " +
159+
"Only the binary should be specified"))
160+
})
161+
153162
s.T().Run("follow logs from nginx", func(t *testing.T) {
154163
timeChan := make(chan time.Time)
155164

0 commit comments

Comments
 (0)