@@ -6,11 +6,10 @@ import (
6
6
"reflect"
7
7
"testing"
8
8
9
+ _ "github.com/openshift/origin/pkg/api/install"
9
10
"k8s.io/apimachinery/pkg/runtime"
10
11
kapi "k8s.io/kubernetes/pkg/api"
11
12
"k8s.io/kubernetes/pkg/credentialprovider"
12
-
13
- _ "github.com/openshift/origin/pkg/api/install"
14
13
)
15
14
16
15
func TestCredentialsForSecrets (t * testing.T ) {
@@ -59,3 +58,53 @@ func TestBasicCredentials(t *testing.T) {
59
58
t .Fatalf ("unexpected response: %s %s" , u , p )
60
59
}
61
60
}
61
+
62
+ func Test_basicCredentialsFromKeyring (t * testing.T ) {
63
+ fn := func (host string , entry credentialprovider.DockerConfigEntry ) credentialprovider.DockerKeyring {
64
+ k := & credentialprovider.BasicDockerKeyring {}
65
+ k .Add (map [string ]credentialprovider.DockerConfigEntry {host : entry })
66
+ return k
67
+ }
68
+ def := credentialprovider.DockerConfigEntry {
69
+ Username : "local_user" ,
70
+ Password : "local_pass" ,
71
+ }
72
+ type args struct {
73
+ keyring credentialprovider.DockerKeyring
74
+ target * url.URL
75
+ }
76
+ tests := []struct {
77
+ name string
78
+ args args
79
+ user string
80
+ password string
81
+ }{
82
+ {name : "exact" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Host : "localhost" }}, user : def .Username , password : def .Password },
83
+ {name : "https scheme" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost" }}, user : def .Username , password : def .Password },
84
+ {name : "canonical https" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost:443" }}, user : def .Username , password : def .Password },
85
+ {name : "only https" , args : args {keyring : fn ("https://localhost" , def ), target : & url.URL {Host : "localhost" }}, user : def .Username , password : def .Password },
86
+ {name : "only https scheme" , args : args {keyring : fn ("https://localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost" }}, user : def .Username , password : def .Password },
87
+ {name : "mismatched scheme - http" , args : args {keyring : fn ("http://localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost" }}, user : def .Username , password : def .Password },
88
+
89
+ // this is not allowed by the credential keyring, possibly because of insufficient testing
90
+ {name : "exact http" , args : args {keyring : fn ("http://localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost:80" }}, user : "" , password : "" },
91
+
92
+ // these should not be allowed
93
+ {name : "canonical http" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost:80" }}, user : "" , password : "" },
94
+ {name : "http scheme" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost" }}, user : "" , password : "" },
95
+ {name : "https not canonical" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "https" , Host : "localhost:80" }}, user : "" , password : "" },
96
+ {name : "http not canonical" , args : args {keyring : fn ("localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost:443" }}, user : "" , password : "" },
97
+ {name : "mismatched scheme" , args : args {keyring : fn ("https://localhost" , def ), target : & url.URL {Scheme : "http" , Host : "localhost" }}, user : "" , password : "" },
98
+ }
99
+ for _ , tt := range tests {
100
+ t .Run (tt .name , func (t * testing.T ) {
101
+ user , password := basicCredentialsFromKeyring (tt .args .keyring , tt .args .target )
102
+ if user != tt .user {
103
+ t .Errorf ("basicCredentialsFromKeyring() user = %v, user = %v" , user , tt .user )
104
+ }
105
+ if password != tt .password {
106
+ t .Errorf ("basicCredentialsFromKeyring() password = %v, password = %v" , password , tt .password )
107
+ }
108
+ })
109
+ }
110
+ }
0 commit comments