@@ -11,7 +11,6 @@ import (
11
11
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
12
12
"k8s.io/kubernetes/pkg/credentialprovider"
13
13
14
- "github.com/golang/glog"
15
14
_ "github.com/openshift/origin/pkg/api/install"
16
15
)
17
16
@@ -29,7 +28,7 @@ func TestCredentialsForSecrets(t *testing.T) {
29
28
for i , secret := range secrets .Items {
30
29
err := kapiv1 .Convert_api_Secret_To_v1_Secret (& secret , & secretsv1 [i ], nil )
31
30
if err != nil {
32
- glog . V ( 2 ). Infof ("Unable to make the Docker keyring for %s/%s secret: %v" , secret .Name , secret .Namespace , err )
31
+ t . Logf ("Unable to make the Docker keyring for %s/%s secret: %v" , secret .Name , secret .Namespace , err )
33
32
continue
34
33
}
35
34
}
@@ -70,3 +69,57 @@ func TestBasicCredentials(t *testing.T) {
70
69
t .Fatalf ("unexpected response: %s %s" , u , p )
71
70
}
72
71
}
72
+
73
+ func Test_basicCredentialsFromKeyring (t * testing.T ) {
74
+ fn := func (host string , entry credentialprovider.DockerConfigEntry ) credentialprovider.DockerKeyring {
75
+ k := & credentialprovider.BasicDockerKeyring {}
76
+ k .Add (map [string ]credentialprovider.DockerConfigEntry {host : entry })
77
+ return k
78
+ }
79
+ def := credentialprovider.DockerConfigEntry {
80
+ Username : "local_user" ,
81
+ Password : "local_pass" ,
82
+ }
83
+ type args struct {
84
+ keyring credentialprovider.DockerKeyring
85
+ target * url.URL
86
+ }
87
+ tests := []struct {
88
+ name string
89
+ args args
90
+ user string
91
+ password string
92
+ }{
93
+ {name : "exact" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Host : "localhost" }}, user : def .Username , password : def .Password },
94
+ {name : "https scheme" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost" }}, user : def .Username , password : def .Password },
95
+ {name : "canonical https" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost:443" }}, user : def .Username , password : def .Password },
96
+ {name : "only https" , args : args {keyring : fn ("https://localhost" , def ), target : & url.URL {Host : "localhost" }}, user : def .Username , password : def .Password },
97
+ {name : "only https scheme" , args : args {keyring : fn ("https://localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost" }}, user : def .Username , password : def .Password },
98
+ {name : "mismatched scheme - http" , args : args {keyring : fn ("http://localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost" }}, user : def .Username , password : def .Password },
99
+
100
+ // this is not allowed by the credential keyring, but should be
101
+ {name : "exact http" , args : args {keyring : fn ("http://localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost:80" }}, user : "" , password : "" },
102
+ {name : "keyring canonical https" , args : args {keyring : fn ("localhost:443" , def ), target : & url.URL {Scheme : "https" , Host : "localhost" }}, user : "" , password : "" },
103
+
104
+ // these should not be allowed
105
+ {name : "host is for port 80 only" , args : args {keyring : fn ("localhost:80" , def ), target : & url.URL {Host : "localhost" }}, user : "" , password : "" },
106
+ {name : "host is for port 443 only" , args : args {keyring : fn ("localhost:443" , def ), target : & url.URL {Host : "localhost" }}, user : "" , password : "" },
107
+ {name : "don't assume port 80 in keyring is https" , args : args {keyring : fn ("localhost:80" , def ), target : & url.URL {Scheme : "http" , Host : "localhost" }}, user : "" , password : "" },
108
+ {name : "canonical http" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost:80" }}, user : "" , password : "" },
109
+ {name : "http scheme" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost" }}, user : "" , password : "" },
110
+ {name : "https not canonical" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost:80" }}, user : "" , password : "" },
111
+ {name : "http not canonical" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost:443" }}, user : "" , password : "" },
112
+ {name : "mismatched scheme" , args : args {keyring : fn ("https://localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost" }}, user : "" , password : "" },
113
+ }
114
+ for _ , tt := range tests {
115
+ t .Run (tt .name , func (t * testing.T ) {
116
+ user , password := basicCredentialsFromKeyring (tt .args .keyring , tt .args .target )
117
+ if user != tt .user {
118
+ t .Errorf ("basicCredentialsFromKeyring() user = %v, actual = %v" , user , tt .user )
119
+ }
120
+ if password != tt .password {
121
+ t .Errorf ("basicCredentialsFromKeyring() password = %v, actual = %v" , password , tt .password )
122
+ }
123
+ })
124
+ }
125
+ }
0 commit comments