mirror of https://github.com/docker/cli.git
login: add e2e tests for oauth + escape hatch
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
parent
846ecf59ff
commit
a327476f7f
|
@ -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))
|
||||
}
|
|
@ -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())
|
||||
}
|
Loading…
Reference in New Issue