Added check for empty strings in resource id parsing logic.
This commit is contained in:
parent
8ea5bb33fb
commit
c42b2381c6
|
@ -53,6 +53,11 @@ func parseAzureResourceID(id string) (*ResourceID, error) {
|
|||
key := components[current]
|
||||
value := components[current+1]
|
||||
|
||||
// Check key/value for empty strings.
|
||||
if key == "" || value == "" {
|
||||
return nil, fmt.Errorf("Key/Value cannot be empty strings. Key: '%s', Value: '%s'", key, value)
|
||||
}
|
||||
|
||||
// Catch the subscriptionID before it can be overwritten by another "subscriptions"
|
||||
// value in the ID which is the case for the Service Bus subscription resource
|
||||
if key == "subscriptions" && subscriptionID == "" {
|
||||
|
|
|
@ -11,6 +11,18 @@ func TestParseAzureResourceID(t *testing.T) {
|
|||
expectedResourceID *ResourceID
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
// Missing "resourceGroups".
|
||||
"/subscriptions/00000000-0000-0000-0000-000000000000//myResourceGroup/",
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
// Empty resource group ID.
|
||||
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//",
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"random",
|
||||
nil,
|
||||
|
|
Loading…
Reference in New Issue