diff --git a/e2e/auth_test.go b/e2e/auth_test.go new file mode 100644 index 000000000000..c6034b2bc8f6 --- /dev/null +++ b/e2e/auth_test.go @@ -0,0 +1,37 @@ +package e2e + +import ( + "testing" + + "github.com/docker/cli/e2e/internal/registry" + "github.com/docker/cli/internal/test/command" +) + +func runDockerCommand(t *testing.T, args ...string) { + cmd := command.NewDockerCommand(t, args...) + cmd.Assert() +} + +func TestAuthorizedPullPush(t *testing.T) { + const ( + username = "testuser" + password = "testpassword" + ) + reg, err := registry.NewV2( + registry.WithAuth(username, password), + ) + if err != nil { + t.Fatalf("Failed to start registry: %v", err) + } + defer reg.Stop() + + repo := reg.RepoName("private/alpine") + + // docker login + runDockerCommand(t, "login", reg.Host(), "-u", username, "-p", password) + runDockerCommand(t, "pull", "alpine") + runDockerCommand(t, "tag", "alpine", repo) + runDockerCommand(t, "push", repo) + runDockerCommand(t, "rmi", repo) + runDockerCommand(t, "pull", repo) +}