Browse code

Fixed a bug - no panic anymore when logining in without TTY

Fixes #8956

Signed-off-by: Marianna <mtesselh@gmail.com>

Marianna authored on 2014/11/18 12:25:06
Showing 2 changed files
... ...
@@ -289,7 +289,10 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
289 289
 	// the password or email from the config file, so prompt them
290 290
 	if username != authconfig.Username {
291 291
 		if password == "" {
292
-			oldState, _ := term.SaveState(cli.inFd)
292
+			oldState, err := term.SaveState(cli.inFd)
293
+			if err != nil {
294
+				return err
295
+			}
293 296
 			fmt.Fprintf(cli.out, "Password: ")
294 297
 			term.DisableEcho(cli.inFd, oldState)
295 298
 
296 299
new file mode 100644
... ...
@@ -0,0 +1,35 @@
0
+package main
1
+
2
+import (
3
+	"bytes"
4
+	"io"
5
+	"os"
6
+	"os/exec"
7
+	"testing"
8
+)
9
+
10
+func TestLoginWithoutTTY(t *testing.T) {
11
+	cmd := exec.Command(dockerBinary, "login")
12
+	// setup STDOUT and STDERR so that we see any output and errors in our console
13
+	cmd.Stdout = os.Stdout
14
+	cmd.Stderr = os.Stderr
15
+
16
+	// create a buffer with text then a new line as a return
17
+	buf := bytes.NewBuffer([]byte("buffer test string \n"))
18
+
19
+	// use a pipe for stdin and manually copy the data so that
20
+	// the process does not get the TTY
21
+	in, err := cmd.StdinPipe()
22
+	if err != nil {
23
+		t.Fatal(err)
24
+	}
25
+	// copy the bytes into the commands stdin along with a new line
26
+	go io.Copy(in, buf)
27
+
28
+	// run the command and block until it's done
29
+	if err := cmd.Run(); err == nil {
30
+		t.Fatal("Expected non nil err when loginning in & TTY not available")
31
+	}
32
+
33
+	logDone("login - login without TTY")
34
+}