From 6d0f7f399f04625c2429278db97c98981bd90191 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 2 Oct 2020 11:56:11 +0200 Subject: [PATCH] Fix regression: let users login to local registry (no '.' In registry name) Signed-off-by: Guillaume Tardif --- cli/cmd/login/login.go | 8 +------- tests/e2e/e2e_test.go | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cli/cmd/login/login.go b/cli/cmd/login/login.go index 0b2ae2e94..78cc0a995 100644 --- a/cli/cmd/login/login.go +++ b/cli/cmd/login/login.go @@ -19,14 +19,12 @@ package login import ( "context" "fmt" - "strings" - - "github.com/docker/compose-cli/cli/cmd/mobyflags" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/docker/compose-cli/api/client" + "github.com/docker/compose-cli/cli/cmd/mobyflags" "github.com/docker/compose-cli/cli/mobycli" "github.com/docker/compose-cli/errdefs" ) @@ -52,10 +50,6 @@ func Command() *cobra.Command { } func runLogin(cmd *cobra.Command, args []string) error { - if len(args) == 1 && !strings.Contains(args[0], ".") { - backend := args[0] - return errors.New("unknown backend type for cloud login: " + backend) - } mobycli.Exec(cmd.Root()) return nil } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 4b33c8e89..f72566661 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -205,9 +205,30 @@ func TestLoginCommandDelegation(t *testing.T) { }) }) + t.Run("localhost registry interactive", func(t *testing.T) { + res := c.RunDockerOrExitError("login", "localhost:443") + res.Assert(t, icmd.Expected{ + ExitCode: 1, + Err: "Cannot perform an interactive login from a non TTY device", + }) + }) + + t.Run("localhost registry", func(t *testing.T) { + res := c.RunDockerOrExitError("login", "localhost", "-u", "user", "-p", "password") + res.Assert(t, icmd.Expected{ + ExitCode: 1, + Err: "http://localhost/v2/", + }) + }) + t.Run("logout", func(t *testing.T) { res := c.RunDockerCmd("logout", "someregistry.docker.io") - res.Assert(t, icmd.Expected{Out: "someregistry.docker.io"}) + res.Assert(t, icmd.Expected{Out: "Removing login credentials for someregistry.docker.io"}) + }) + + t.Run("logout", func(t *testing.T) { + res := c.RunDockerCmd("logout", "localhost:443") + res.Assert(t, icmd.Expected{Out: "Removing login credentials for localhost:443"}) }) t.Run("existing context", func(t *testing.T) { @@ -221,18 +242,6 @@ func TestLoginCommandDelegation(t *testing.T) { }) } -func TestCloudLogin(t *testing.T) { - c := NewParallelE2eCLI(t, binDir) - - t.Run("unknown backend", func(t *testing.T) { - res := c.RunDockerOrExitError("login", "mycloudbackend") - res.Assert(t, icmd.Expected{ - ExitCode: 1, - Err: "unknown backend type for cloud login: mycloudbackend", - }) - }) -} - func TestMissingExistingCLI(t *testing.T) { t.Parallel() home, err := ioutil.TempDir("", "")