Skip to content

Commit

Permalink
auth: skip empty config.auth entries
Browse files Browse the repository at this point in the history
Closes #677.
  • Loading branch information
fsouza committed Jan 26, 2018
1 parent fac48ff commit baaca7f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions auth.go
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion auth_test.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit baaca7f

Please sign in to comment.