Merge pull request #715 from docker/fix_docker_login

Fix regression: let users login to local registry (no ‘.’ In registry name)
This commit is contained in:
Guillaume Tardif 2020-10-02 14:06:37 +02:00 committed by GitHub
commit 9a3d3a7f45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 20 deletions

View File

@ -19,14 +19,12 @@ package login
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"github.com/docker/compose-cli/cli/cmd/mobyflags"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client" "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/cli/mobycli"
"github.com/docker/compose-cli/errdefs" "github.com/docker/compose-cli/errdefs"
) )
@ -52,10 +50,6 @@ func Command() *cobra.Command {
} }
func runLogin(cmd *cobra.Command, args []string) error { 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()) mobycli.Exec(cmd.Root())
return nil return nil
} }

View File

@ -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) { t.Run("logout", func(t *testing.T) {
res := c.RunDockerCmd("logout", "someregistry.docker.io") 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) { 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) { func TestMissingExistingCLI(t *testing.T) {
t.Parallel() t.Parallel()
home, err := ioutil.TempDir("", "") home, err := ioutil.TempDir("", "")