Added check for empty strings in resource id parsing logic.

This commit is contained in:
Jay Wang 2017-04-18 17:17:14 -07:00
parent 8ea5bb33fb
commit c42b2381c6
2 changed files with 17 additions and 0 deletions

View File

@ -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 == "" {

View File

@ -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,