@@ -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+
99122func TestAuthAndOtherFields (t * testing.T ) {
100123 t .Parallel ()
101124 auth := base64 .StdEncoding .EncodeToString ([]byte ("user:pass" ))
0 commit comments