@@ -109,6 +109,90 @@ func TestAuthenticationDetection(t *testing.T) {
109
109
},
110
110
expected : rest.Config {BearerToken : "first" },
111
111
},
112
+ {
113
+ name : "exact match with default https port" ,
114
+ serverName : "one.two.three.com:443" ,
115
+ kubeconfig : clientcmdapi.Config {
116
+ AuthInfos : map [string ]* clientcmdapi.AuthInfo {
117
+ "one.two.three.com:443" : {Token : "exact" },
118
+ "*.two.three.com" : {Token : "first" },
119
+ "*.three.com" : {Token : "second" },
120
+ "*.com" : {Token : "third" },
121
+ "*" : {Token : "fallback" },
122
+ },
123
+ },
124
+ expected : rest.Config {BearerToken : "exact" },
125
+ },
126
+ {
127
+ name : "wildcard match with default https port" ,
128
+ serverName : "one.two.three.com:443" ,
129
+ kubeconfig : clientcmdapi.Config {
130
+ AuthInfos : map [string ]* clientcmdapi.AuthInfo {
131
+ "*.two.three.com:443" : {Token : "first-with-port" },
132
+ "*.two.three.com" : {Token : "first" },
133
+ "*.three.com" : {Token : "second" },
134
+ "*.com" : {Token : "third" },
135
+ "*" : {Token : "fallback" },
136
+ },
137
+ },
138
+ expected : rest.Config {BearerToken : "first-with-port" },
139
+ },
140
+ {
141
+ name : "wildcard match without default https port" ,
142
+ serverName : "one.two.three.com:443" ,
143
+ kubeconfig : clientcmdapi.Config {
144
+ AuthInfos : map [string ]* clientcmdapi.AuthInfo {
145
+ "*.two.three.com" : {Token : "first" },
146
+ "*.three.com" : {Token : "second" },
147
+ "*.com" : {Token : "third" },
148
+ "*" : {Token : "fallback" },
149
+ },
150
+ },
151
+ expected : rest.Config {BearerToken : "first" },
152
+ },
153
+ {
154
+ name : "exact match with non-default https port" ,
155
+ serverName : "one.two.three.com:8443" ,
156
+ kubeconfig : clientcmdapi.Config {
157
+ AuthInfos : map [string ]* clientcmdapi.AuthInfo {
158
+ "one.two.three.com:8443" : {Token : "exact" },
159
+ "*.two.three.com" : {Token : "first" },
160
+ "*.three.com" : {Token : "second" },
161
+ "*.com" : {Token : "third" },
162
+ "*" : {Token : "fallback" },
163
+ },
164
+ },
165
+ expected : rest.Config {BearerToken : "exact" },
166
+ },
167
+ {
168
+ name : "wildcard match with non-default https port" ,
169
+ serverName : "one.two.three.com:8443" ,
170
+ kubeconfig : clientcmdapi.Config {
171
+ AuthInfos : map [string ]* clientcmdapi.AuthInfo {
172
+ "*.two.three.com:8443" : {Token : "first-with-port" },
173
+ "one.two.three.com" : {Token : "first-without-port" },
174
+ "*.two.three.com" : {Token : "first" },
175
+ "*.three.com" : {Token : "second" },
176
+ "*.com" : {Token : "third" },
177
+ "*" : {Token : "fallback" },
178
+ },
179
+ },
180
+ expected : rest.Config {BearerToken : "first-with-port" },
181
+ },
182
+ {
183
+ name : "wildcard match without non-default https port" ,
184
+ serverName : "one.two.three.com:8443" ,
185
+ kubeconfig : clientcmdapi.Config {
186
+ AuthInfos : map [string ]* clientcmdapi.AuthInfo {
187
+ "one.two.three.com" : {Token : "first-without-port" },
188
+ "*.two.three.com" : {Token : "first" },
189
+ "*.three.com" : {Token : "second" },
190
+ "*.com" : {Token : "third" },
191
+ "*" : {Token : "fallback" },
192
+ },
193
+ },
194
+ expected : rest.Config {BearerToken : "fallback" },
195
+ },
112
196
}
113
197
114
198
for _ , tc := range tests {
0 commit comments