@@ -43,7 +43,7 @@ func TestAuthConfigurationsFromFile(t *testing.T) {
43
43
}
44
44
defer os .RemoveAll (tmpDir )
45
45
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 )
47
47
configFile := path .Join (tmpDir , "docker_config" )
48
48
if err = ioutil .WriteFile (configFile , []byte (content ), 0600 ); err != nil {
49
49
t .Errorf ("Error writing auth config for TestAuthConfigurationsFromFile: %s" , err )
@@ -96,6 +96,29 @@ func TestAuthBadConfig(t *testing.T) {
96
96
}
97
97
}
98
98
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
+
99
122
func TestAuthAndOtherFields (t * testing.T ) {
100
123
t .Parallel ()
101
124
auth := base64 .StdEncoding .EncodeToString ([]byte ("user:pass" ))
0 commit comments