docker_cli_login_test.go 1.1 KB

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