Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #715 from docker/fix_docker_login
Browse files Browse the repository at this point in the history
Fix regression: let users login to local registry (no ‘.’ In registry name)
  • Loading branch information
gtardif authored Oct 2, 2020
2 parents abd6af6 + 6d0f7f3 commit 9a3d3a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
8 changes: 1 addition & 7 deletions cli/cmd/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
Expand Down
35 changes: 22 additions & 13 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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("", "")
Expand Down

0 comments on commit 9a3d3a7

Please sign in to comment.