@@ -20,6 +20,7 @@ package vsphere
20
20
21
21
import (
22
22
"reflect"
23
+ "strings"
23
24
"testing"
24
25
25
26
corev1 "k8s.io/api/core/v1"
@@ -37,6 +38,7 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
37
38
testPassword = "password"
38
39
testServer = "0.0.0.0"
39
40
testServer2 = "0.0.1.1"
41
+ testServerFQIN = "ExAmple.com"
40
42
testUserServer2 = "user1"
41
43
testPasswordServer2 = "password1"
42
44
testIncorrectServer = "1.1.1.1"
@@ -89,6 +91,14 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
89
91
},
90
92
}
91
93
94
+ fqinSecret := & corev1.Secret {
95
+ ObjectMeta : metaObj ,
96
+ Data : map [string ][]byte {
97
+ testServerFQIN + "." + userKey : []byte (testUser ),
98
+ testServerFQIN + "." + passwordKey : []byte (testPassword ),
99
+ },
100
+ }
101
+
92
102
emptySecret := & corev1.Secret {
93
103
ObjectMeta : metaObj ,
94
104
Data : map [string ][]byte {},
@@ -183,6 +193,20 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
183
193
},
184
194
},
185
195
},
196
+ {
197
+ testName : "GetCredential for FQIN server name" ,
198
+ ops : []string {addSecretOp , getCredentialsOp },
199
+ expectedValues : []interface {}{
200
+ OpSecretTest {
201
+ fqinSecret ,
202
+ },
203
+ GetCredentialsTest {
204
+ username : testUser ,
205
+ password : testPassword ,
206
+ server : testServerFQIN ,
207
+ },
208
+ },
209
+ },
186
210
}
187
211
188
212
// TODO: replace 0 with NoResyncPeriodFunc() once it moved out pkg/controller/controller_utils.go in k/k.
@@ -254,9 +278,10 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
254
278
255
279
func TestParseSecretConfig (t * testing.T ) {
256
280
var (
257
- testUsername = "Admin"
258
- testPassword = "Password"
259
- testIP = "10.20.30.40"
281
+ testUsername = "Admin"
282
+ testPassword = "Password"
283
+ testIP = "10.20.30.40"
284
+ testServerFQIN = "ExAmple.com"
260
285
)
261
286
var testcases = []struct {
262
287
testName string
@@ -311,6 +336,20 @@ func TestParseSecretConfig(t *testing.T) {
311
336
},
312
337
expectedError : ErrCredentialMissing ,
313
338
},
339
+ {
340
+ testName : "FQIN stored as lowercase" ,
341
+ data : map [string ][]byte {
342
+ testServerFQIN + ".username" : []byte (testUsername ),
343
+ testServerFQIN + ".password" : []byte (testPassword ),
344
+ },
345
+ config : map [string ]* Credential {
346
+ strings .ToLower (testServerFQIN ): {
347
+ User : testUsername ,
348
+ Password : testPassword ,
349
+ },
350
+ },
351
+ expectedError : nil ,
352
+ },
314
353
{
315
354
testName : "IP with unknown key" ,
316
355
data : map [string ][]byte {
0 commit comments