Browse Source

Fix regression: let users login to local registry (no '.' In registry name)

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 5 years ago
parent
commit
6d0f7f399f
2 changed files with 23 additions and 20 deletions
  1. 1 7
      cli/cmd/login/login.go
  2. 22 13
      tests/e2e/e2e_test.go

+ 1 - 7
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
 }

+ 22 - 13
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("", "")