docker_cli_login_test.go 920 B

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