diff --git a/e2e/registry/login_test.go b/e2e/registry/login_test.go new file mode 100644 index 0000000000..523e00d065 --- /dev/null +++ b/e2e/registry/login_test.go @@ -0,0 +1,56 @@ +package registry + +import ( + "io" + "os/exec" + "strings" + "syscall" + "testing" + "time" + + "github.com/creack/pty" + "gotest.tools/v3/assert" +) + +func TestOauthLogin(t *testing.T) { + t.Parallel() + loginCmd := exec.Command("docker", "login") + + p, err := pty.Start(loginCmd) + assert.NilError(t, err) + defer func() { + _ = loginCmd.Wait() + _ = p.Close() + }() + + time.Sleep(1 * time.Second) + pid := loginCmd.Process.Pid + t.Logf("terminating PID %d", pid) + err = syscall.Kill(pid, syscall.SIGTERM) + assert.NilError(t, err) + + output, _ := io.ReadAll(p) + assert.Check(t, strings.Contains(string(output), "USING WEB BASED LOGIN"), string(output)) +} + +func TestLoginWithEscapeHatch(t *testing.T) { + t.Parallel() + loginCmd := exec.Command("docker", "login") + loginCmd.Env = append(loginCmd.Env, "DOCKER_CLI_DISABLE_OAUTH_LOGIN=1") + + p, err := pty.Start(loginCmd) + assert.NilError(t, err) + defer func() { + _ = loginCmd.Wait() + _ = p.Close() + }() + + time.Sleep(1 * time.Second) + pid := loginCmd.Process.Pid + t.Logf("terminating PID %d", pid) + err = syscall.Kill(pid, syscall.SIGTERM) + assert.NilError(t, err) + + output, _ := io.ReadAll(p) + assert.Check(t, strings.Contains(string(output), "Username:"), string(output)) +} diff --git a/e2e/registry/main_test.go b/e2e/registry/main_test.go new file mode 100644 index 0000000000..9174715188 --- /dev/null +++ b/e2e/registry/main_test.go @@ -0,0 +1,17 @@ +package registry + +import ( + "fmt" + "os" + "testing" + + "github.com/docker/cli/internal/test/environment" +) + +func TestMain(m *testing.M) { + if err := environment.Setup(); err != nil { + fmt.Println(err.Error()) + os.Exit(3) + } + os.Exit(m.Run()) +}