mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #90796 from Danil-Grigorev/get-credential-lowercase
Ensure the server FQIN is stored and searched in lowercase (vsphere)
This commit is contained in:
commit
657fdedb17
@ -77,6 +77,8 @@ func (secretCredentialManager *SecretCredentialManager) GetCredential(server str
|
|||||||
klog.Warningf("secret %q not found in namespace %q", secretCredentialManager.SecretName, secretCredentialManager.SecretNamespace)
|
klog.Warningf("secret %q not found in namespace %q", secretCredentialManager.SecretName, secretCredentialManager.SecretNamespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converting server FQIN to lowercase to consolidate with config parsing approach
|
||||||
|
server = strings.ToLower(server)
|
||||||
credential, found := secretCredentialManager.Cache.GetCredential(server)
|
credential, found := secretCredentialManager.Cache.GetCredential(server)
|
||||||
if !found {
|
if !found {
|
||||||
klog.Errorf("credentials not found for server %q", server)
|
klog.Errorf("credentials not found for server %q", server)
|
||||||
|
@ -20,6 +20,7 @@ package vsphere
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@ -37,6 +38,7 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
|
|||||||
testPassword = "password"
|
testPassword = "password"
|
||||||
testServer = "0.0.0.0"
|
testServer = "0.0.0.0"
|
||||||
testServer2 = "0.0.1.1"
|
testServer2 = "0.0.1.1"
|
||||||
|
testServerFQIN = "ExAmple.com"
|
||||||
testUserServer2 = "user1"
|
testUserServer2 = "user1"
|
||||||
testPasswordServer2 = "password1"
|
testPasswordServer2 = "password1"
|
||||||
testIncorrectServer = "1.1.1.1"
|
testIncorrectServer = "1.1.1.1"
|
||||||
@ -89,6 +91,14 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fqinSecret := &corev1.Secret{
|
||||||
|
ObjectMeta: metaObj,
|
||||||
|
Data: map[string][]byte{
|
||||||
|
testServerFQIN + "." + userKey: []byte(testUser),
|
||||||
|
testServerFQIN + "." + passwordKey: []byte(testPassword),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
emptySecret := &corev1.Secret{
|
emptySecret := &corev1.Secret{
|
||||||
ObjectMeta: metaObj,
|
ObjectMeta: metaObj,
|
||||||
Data: map[string][]byte{},
|
Data: map[string][]byte{},
|
||||||
@ -183,6 +193,20 @@ func TestSecretCredentialManager_GetCredential(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "GetCredential for FQIN server name",
|
||||||
|
ops: []string{addSecretOp, getCredentialsOp},
|
||||||
|
expectedValues: []interface{}{
|
||||||
|
OpSecretTest{
|
||||||
|
fqinSecret,
|
||||||
|
},
|
||||||
|
GetCredentialsTest{
|
||||||
|
username: testUser,
|
||||||
|
password: testPassword,
|
||||||
|
server: testServerFQIN,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace 0 with NoResyncPeriodFunc() once it moved out pkg/controller/controller_utils.go in k/k.
|
// 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) {
|
|||||||
|
|
||||||
func TestParseSecretConfig(t *testing.T) {
|
func TestParseSecretConfig(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
testUsername = "Admin"
|
testUsername = "Admin"
|
||||||
testPassword = "Password"
|
testPassword = "Password"
|
||||||
testIP = "10.20.30.40"
|
testIP = "10.20.30.40"
|
||||||
|
testServerFQIN = "ExAmple.com"
|
||||||
)
|
)
|
||||||
var testcases = []struct {
|
var testcases = []struct {
|
||||||
testName string
|
testName string
|
||||||
@ -311,6 +336,20 @@ func TestParseSecretConfig(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectedError: ErrCredentialMissing,
|
expectedError: ErrCredentialMissing,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "FQIN stored as lowercase",
|
||||||
|
data: map[string][]byte{
|
||||||
|
testServerFQIN + ".username": []byte(testUsername),
|
||||||
|
testServerFQIN + ".password": []byte(testPassword),
|
||||||
|
},
|
||||||
|
config: map[string]*Credential{
|
||||||
|
strings.ToLower(testServerFQIN): {
|
||||||
|
User: testUsername,
|
||||||
|
Password: testPassword,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedError: nil,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
testName: "IP with unknown key",
|
testName: "IP with unknown key",
|
||||||
data: map[string][]byte{
|
data: map[string][]byte{
|
||||||
|
Loading…
Reference in New Issue
Block a user