docker_cli_login_test.go 1.1 KB

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