diff --git a/auth.go b/auth.go index 03d192b7..c58de867 100644 --- a/auth.go +++ b/auth.go @@ -129,6 +129,9 @@ func authConfigs(confs map[string]dockerConfig) (*AuthConfigurations, error) { Configs: make(map[string]AuthConfiguration), } for reg, conf := range confs { + if conf.Auth == "" { + continue + } data, err := base64.StdEncoding.DecodeString(conf.Auth) if err != nil { return nil, err diff --git a/auth_test.go b/auth_test.go index ba846f65..2f57aa1a 100644 --- a/auth_test.go +++ b/auth_test.go @@ -43,7 +43,7 @@ func TestAuthConfigurationsFromFile(t *testing.T) { } defer os.RemoveAll(tmpDir) authString := base64.StdEncoding.EncodeToString([]byte("user:pass")) - content := fmt.Sprintf("{\"auths\":{\"foo\": {\"auth\": \"%s\"}}}", authString) + content := fmt.Sprintf(`{"auths":{"foo": {"auth": "%s"}}}`, authString) configFile := path.Join(tmpDir, "docker_config") if err = ioutil.WriteFile(configFile, []byte(content), 0600); err != nil { t.Errorf("Error writing auth config for TestAuthConfigurationsFromFile: %s", err) @@ -96,6 +96,29 @@ func TestAuthBadConfig(t *testing.T) { } } +func TestAuthMixedWithKeyChain(t *testing.T) { + t.Parallel() + auth := base64.StdEncoding.EncodeToString([]byte("user:pass")) + read := strings.NewReader(fmt.Sprintf(`{"auths":{"docker.io":{},"localhost:5000":{"auth":"%s"}},"credsStore":"osxkeychain"}`, auth)) + ac, err := NewAuthConfigurations(read) + if err != nil { + t.Fatal(err) + } + c, ok := ac.Configs["localhost:5000"] + if !ok { + t.Error("NewAuthConfigurations: Expected Configs to contain localhost:5000") + } + if got, want := c.Username, "user"; got != want { + t.Errorf(`AuthConfigurations.Configs["docker.io"].Username: wrong result. Want %q. Got %q`, want, got) + } + if got, want := c.Password, "pass"; got != want { + t.Errorf(`AuthConfigurations.Configs["docker.io"].Password: wrong result. Want %q. Got %q`, want, got) + } + if got, want := c.ServerAddress, "localhost:5000"; got != want { + t.Errorf(`AuthConfigurations.Configs["localhost:5000"].ServerAddress: wrong result. Want %q. Got %q`, want, got) + } +} + func TestAuthAndOtherFields(t *testing.T) { t.Parallel() auth := base64.StdEncoding.EncodeToString([]byte("user:pass"))