Skip to content

Commit baaca7f

Browse files
committed
auth: skip empty config.auth entries
Closes #677.
1 parent fac48ff commit baaca7f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

auth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ func authConfigs(confs map[string]dockerConfig) (*AuthConfigurations, error) {
129129
Configs: make(map[string]AuthConfiguration),
130130
}
131131
for reg, conf := range confs {
132+
if conf.Auth == "" {
133+
continue
134+
}
132135
data, err := base64.StdEncoding.DecodeString(conf.Auth)
133136
if err != nil {
134137
return nil, err

auth_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestAuthConfigurationsFromFile(t *testing.T) {
4343
}
4444
defer os.RemoveAll(tmpDir)
4545
authString := base64.StdEncoding.EncodeToString([]byte("user:pass"))
46-
content := fmt.Sprintf("{\"auths\":{\"foo\": {\"auth\": \"%s\"}}}", authString)
46+
content := fmt.Sprintf(`{"auths":{"foo": {"auth": "%s"}}}`, authString)
4747
configFile := path.Join(tmpDir, "docker_config")
4848
if err = ioutil.WriteFile(configFile, []byte(content), 0600); err != nil {
4949
t.Errorf("Error writing auth config for TestAuthConfigurationsFromFile: %s", err)
@@ -96,6 +96,29 @@ func TestAuthBadConfig(t *testing.T) {
9696
}
9797
}
9898

99+
func TestAuthMixedWithKeyChain(t *testing.T) {
100+
t.Parallel()
101+
auth := base64.StdEncoding.EncodeToString([]byte("user:pass"))
102+
read := strings.NewReader(fmt.Sprintf(`{"auths":{"docker.io":{},"localhost:5000":{"auth":"%s"}},"credsStore":"osxkeychain"}`, auth))
103+
ac, err := NewAuthConfigurations(read)
104+
if err != nil {
105+
t.Fatal(err)
106+
}
107+
c, ok := ac.Configs["localhost:5000"]
108+
if !ok {
109+
t.Error("NewAuthConfigurations: Expected Configs to contain localhost:5000")
110+
}
111+
if got, want := c.Username, "user"; got != want {
112+
t.Errorf(`AuthConfigurations.Configs["docker.io"].Username: wrong result. Want %q. Got %q`, want, got)
113+
}
114+
if got, want := c.Password, "pass"; got != want {
115+
t.Errorf(`AuthConfigurations.Configs["docker.io"].Password: wrong result. Want %q. Got %q`, want, got)
116+
}
117+
if got, want := c.ServerAddress, "localhost:5000"; got != want {
118+
t.Errorf(`AuthConfigurations.Configs["localhost:5000"].ServerAddress: wrong result. Want %q. Got %q`, want, got)
119+
}
120+
}
121+
99122
func TestAuthAndOtherFields(t *testing.T) {
100123
t.Parallel()
101124
auth := base64.StdEncoding.EncodeToString([]byte("user:pass"))

0 commit comments

Comments
 (0)