From e6fd57b90bcdd3b0105fa5c7d17a64332f829ded Mon Sep 17 00:00:00 2001 From: Marianna Date: Mon, 17 Nov 2014 19:25:06 -0800 Subject: [PATCH] Fixed a bug - no panic anymore when logining in without TTY Fixes #8956 Signed-off-by: Marianna --- api/client/commands.go | 5 +++- integration-cli/docker_cli_login_test.go | 35 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 integration-cli/docker_cli_login_test.go diff --git a/api/client/commands.go b/api/client/commands.go index 6b9c4d4d8f..dfc07835c9 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -289,7 +289,10 @@ func (cli *DockerCli) CmdLogin(args ...string) error { // the password or email from the config file, so prompt them if username != authconfig.Username { if password == "" { - oldState, _ := term.SaveState(cli.inFd) + oldState, err := term.SaveState(cli.inFd) + if err != nil { + return err + } fmt.Fprintf(cli.out, "Password: ") term.DisableEcho(cli.inFd, oldState) diff --git a/integration-cli/docker_cli_login_test.go b/integration-cli/docker_cli_login_test.go new file mode 100644 index 0000000000..cf134e4c9b --- /dev/null +++ b/integration-cli/docker_cli_login_test.go @@ -0,0 +1,35 @@ +package main + +import ( + "bytes" + "io" + "os" + "os/exec" + "testing" +) + +func TestLoginWithoutTTY(t *testing.T) { + cmd := exec.Command(dockerBinary, "login") + // setup STDOUT and STDERR so that we see any output and errors in our console + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + // create a buffer with text then a new line as a return + buf := bytes.NewBuffer([]byte("buffer test string \n")) + + // use a pipe for stdin and manually copy the data so that + // the process does not get the TTY + in, err := cmd.StdinPipe() + if err != nil { + t.Fatal(err) + } + // copy the bytes into the commands stdin along with a new line + go io.Copy(in, buf) + + // run the command and block until it's done + if err := cmd.Run(); err == nil { + t.Fatal("Expected non nil err when loginning in & TTY not available") + } + + logDone("login - login without TTY") +}