github.com/adityamillind98/moby@v23.0.0-rc.4+incompatible/integration-cli/docker_cli_login_test.go (about)

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