Skip to content

Commit

Permalink
bugfix: can't allow run cmd attach ttyMode container from a non-tty c…
Browse files Browse the repository at this point in the history
…lient

Signed-off-by: zhangyue <[email protected]>
  • Loading branch information
zhangyue authored and fuweid committed Oct 24, 2018
1 parent 4106b91 commit ee5caee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (rc *RunCommand) runRun(args []string) error {

wait := make(chan struct{})

if err := checkTty(rc.stdin, rc.tty, os.Stdout.Fd()); err != nil {
return err
}

if rc.attach || rc.stdin {
if rc.tty {
in, out, err := setRawMode(rc.stdin, false)
Expand Down
11 changes: 11 additions & 0 deletions test/cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
"github.com/stretchr/testify/assert"
)

// PouchRunSuite is the test suite for run CLI.
Expand Down Expand Up @@ -443,3 +444,13 @@ func (suite *PouchRunSuite) TestRunWithEnv(c *check.C) {
res.Assert(c, icmd.Success)
c.Assert(strings.TrimSpace(res.Stdout()), check.Equals, "a,b,c-b1")
}

// TestRunWithTty tests running container with -tty flag and attach stdin in a non-tty client.
func (suite *PouchRunSuite) TestRunWithTty(c *check.C) {
name := "TestRunWithTty"
res := command.PouchRun("run", "-i", "-t", "--name", name, busyboxImage, "sleep", "100000")
defer DelContainerForceMultyTime(c, name)

errString := res.Stderr()
assert.Equal(c, errString, "Error: the input device is not a TTY\n")
}

0 comments on commit ee5caee

Please sign in to comment.