Merge pull request #356 from docker/fix-non-interactive

Add check on exec looking for arguments
This commit is contained in:
Guillaume Tardif 2020-07-07 12:41:44 +02:00 коммит произвёл GitHub
Родитель de4ba33c60 35cbb621fb
Коммит 16acc36033
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -193,6 +193,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 {
@ -208,6 +212,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

Просмотреть файл

@ -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))

Просмотреть файл

@ -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)