github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/moby/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  func (s *DockerSuite) TestLoginWithoutTTY(c *testing.T) {
    13  	cmd := exec.Command(dockerBinary, "login")
    14  
    15  	// Send to stdin so the process does not get the TTY
    16  	cmd.Stdin = bytes.NewBufferString("buffer test string \n")
    17  
    18  	// run the command and block until it's done
    19  	err := cmd.Run()
    20  	assert.ErrorContains(c, err, "") //"Expected non nil err when logging in & TTY not available"
    21  }
    22  
    23  func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistry(c *testing.T) {
    24  	// wrong credentials
    25  	out, _, err := dockerCmdWithError("login", "-u", s.reg.Username(), "-p", "WRONGPASSWORD", privateRegistryURL)
    26  	assert.ErrorContains(c, err, "", out)
    27  	assert.Assert(c, strings.Contains(out, "401 Unauthorized"))
    28  
    29  	// now it's fine
    30  	dockerCmd(c, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
    31  }