Skip to content

Commit a327476

Browse files
committed
login: add e2e tests for oauth + escape hatch
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
1 parent 846ecf5 commit a327476

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

e2e/registry/login_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package registry
2+
3+
import (
4+
"io"
5+
"os/exec"
6+
"strings"
7+
"syscall"
8+
"testing"
9+
"time"
10+
11+
"github.com/creack/pty"
12+
"gotest.tools/v3/assert"
13+
)
14+
15+
func TestOauthLogin(t *testing.T) {
16+
t.Parallel()
17+
loginCmd := exec.Command("docker", "login")
18+
19+
p, err := pty.Start(loginCmd)
20+
assert.NilError(t, err)
21+
defer func() {
22+
_ = loginCmd.Wait()
23+
_ = p.Close()
24+
}()
25+
26+
time.Sleep(1 * time.Second)
27+
pid := loginCmd.Process.Pid
28+
t.Logf("terminating PID %d", pid)
29+
err = syscall.Kill(pid, syscall.SIGTERM)
30+
assert.NilError(t, err)
31+
32+
output, _ := io.ReadAll(p)
33+
assert.Check(t, strings.Contains(string(output), "USING WEB BASED LOGIN"), string(output))
34+
}
35+
36+
func TestLoginWithEscapeHatch(t *testing.T) {
37+
t.Parallel()
38+
loginCmd := exec.Command("docker", "login")
39+
loginCmd.Env = append(loginCmd.Env, "DOCKER_CLI_DISABLE_OAUTH_LOGIN=1")
40+
41+
p, err := pty.Start(loginCmd)
42+
assert.NilError(t, err)
43+
defer func() {
44+
_ = loginCmd.Wait()
45+
_ = p.Close()
46+
}()
47+
48+
time.Sleep(1 * time.Second)
49+
pid := loginCmd.Process.Pid
50+
t.Logf("terminating PID %d", pid)
51+
err = syscall.Kill(pid, syscall.SIGTERM)
52+
assert.NilError(t, err)
53+
54+
output, _ := io.ReadAll(p)
55+
assert.Check(t, strings.Contains(string(output), "Username:"), string(output))
56+
}

e2e/registry/main_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package registry
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/docker/cli/internal/test/environment"
9+
)
10+
11+
func TestMain(m *testing.M) {
12+
if err := environment.Setup(); err != nil {
13+
fmt.Println(err.Error())
14+
os.Exit(3)
15+
}
16+
os.Exit(m.Run())
17+
}

0 commit comments

Comments
 (0)