Skip to content

Commit

Permalink
Merge pull request #1652 from sEpt0r/fix-azkv-keys-space
Browse files Browse the repository at this point in the history
fix(azkv): handle whitespace in Azure Key Vault URLs
  • Loading branch information
felixfontein authored Oct 22, 2024
2 parents 8b1a1d6 + cdfc7d6 commit e0c970a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions azkv/keysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func NewMasterKey(vaultURL string, keyName string, keyVersion string) *MasterKey
// NewMasterKeyFromURL takes an Azure Key Vault key URL, and returns a new
// MasterKey. The URL format is {vaultUrl}/keys/{keyName}/{keyVersion}.
func NewMasterKeyFromURL(url string) (*MasterKey, error) {
url = strings.TrimSpace(url)
re := regexp.MustCompile("^(https://[^/]+)/keys/([^/]+)/([^/]+)$")
parts := re.FindStringSubmatch(url)
if parts == nil || len(parts) < 3 {
Expand Down
17 changes: 17 additions & 0 deletions azkv/keysource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ func TestMasterKeysFromURLs(t *testing.T) {
},
},
},
{
name: "multiple URLs with leading and trailing spaces",
urls: " https://test.vault.azure.net/keys/test-key/a2a690a4fcc04166b739da342a912c90 , https://test2.vault.azure.net/keys/another-test-key/cf0021e8b743453bae758e7fbf71b60e ",
expectKeyCount: 2,
expectKeys: []MasterKey{
{
VaultURL: "https://test.vault.azure.net",
Name: "test-key",
Version: "a2a690a4fcc04166b739da342a912c90",
},
{
VaultURL: "https://test2.vault.azure.net",
Name: "another-test-key",
Version: "cf0021e8b743453bae758e7fbf71b60e",
},
},
},
{
name: "multiple URLs, one malformed",
urls: "https://test.vault.azure.net/keys/test-key/a2a690a4fcc04166b739da342a912c90,https://test.vault.azure.net/no-keys-here/test-key/a2a690a4fcc04166b739da342a912c90",
Expand Down

0 comments on commit e0c970a

Please sign in to comment.