docker_cli_login_test.go 1.2 KB

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