Skip to content

Commit e0c970a

Browse files
authored
Merge pull request #1652 from sEpt0r/fix-azkv-keys-space
fix(azkv): handle whitespace in Azure Key Vault URLs
2 parents 8b1a1d6 + cdfc7d6 commit e0c970a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

azkv/keysource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func NewMasterKey(vaultURL string, keyName string, keyVersion string) *MasterKey
7676
// NewMasterKeyFromURL takes an Azure Key Vault key URL, and returns a new
7777
// MasterKey. The URL format is {vaultUrl}/keys/{keyName}/{keyVersion}.
7878
func NewMasterKeyFromURL(url string) (*MasterKey, error) {
79+
url = strings.TrimSpace(url)
7980
re := regexp.MustCompile("^(https://[^/]+)/keys/([^/]+)/([^/]+)$")
8081
parts := re.FindStringSubmatch(url)
8182
if parts == nil || len(parts) < 3 {

azkv/keysource_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ func TestMasterKeysFromURLs(t *testing.T) {
8888
},
8989
},
9090
},
91+
{
92+
name: "multiple URLs with leading and trailing spaces",
93+
urls: " https://test.vault.azure.net/keys/test-key/a2a690a4fcc04166b739da342a912c90 , https://test2.vault.azure.net/keys/another-test-key/cf0021e8b743453bae758e7fbf71b60e ",
94+
expectKeyCount: 2,
95+
expectKeys: []MasterKey{
96+
{
97+
VaultURL: "https://test.vault.azure.net",
98+
Name: "test-key",
99+
Version: "a2a690a4fcc04166b739da342a912c90",
100+
},
101+
{
102+
VaultURL: "https://test2.vault.azure.net",
103+
Name: "another-test-key",
104+
Version: "cf0021e8b743453bae758e7fbf71b60e",
105+
},
106+
},
107+
},
91108
{
92109
name: "multiple URLs, one malformed",
93110
urls: "https://test.vault.azure.net/keys/test-key/a2a690a4fcc04166b739da342a912c90,https://test.vault.azure.net/no-keys-here/test-key/a2a690a4fcc04166b739da342a912c90",

0 commit comments

Comments
 (0)