github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/integration-cli/docker_cli_login_test.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "context" 6 "os/exec" 7 "strings" 8 "testing" 9 10 "github.com/Prakhar-Agarwal-byte/moby/integration-cli/cli" 11 "gotest.tools/v3/assert" 12 ) 13 14 type DockerCLILoginSuite struct { 15 ds *DockerSuite 16 } 17 18 func (s *DockerCLILoginSuite) TearDownTest(ctx context.Context, c *testing.T) { 19 s.ds.TearDownTest(ctx, c) 20 } 21 22 func (s *DockerCLILoginSuite) OnTimeout(c *testing.T) { 23 s.ds.OnTimeout(c) 24 } 25 26 func (s *DockerCLILoginSuite) TestLoginWithoutTTY(c *testing.T) { 27 cmd := exec.Command(dockerBinary, "login") 28 29 // Send to stdin so the process does not get the TTY 30 cmd.Stdin = bytes.NewBufferString("buffer test string \n") 31 32 // run the command and block until it's done 33 err := cmd.Run() 34 assert.ErrorContains(c, err, "") // "Expected non nil err when logging in & TTY not available" 35 } 36 37 func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistry(c *testing.T) { 38 // wrong credentials 39 out, _, err := dockerCmdWithError("login", "-u", s.reg.Username(), "-p", "WRONGPASSWORD", privateRegistryURL) 40 assert.ErrorContains(c, err, "", out) 41 assert.Assert(c, strings.Contains(out, "401 Unauthorized")) 42 43 // now it's fine 44 cli.DockerCmd(c, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL) 45 }