Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Handle case sensitive id check (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
aramase authored and kkmsft committed Jul 2, 2019
1 parent 3db3fe4 commit f453ce0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/cloudprovider/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cloudprovider

import (
"errors"
"strings"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
)
Expand Down Expand Up @@ -65,7 +66,7 @@ func filter(ls *[]string, filter string) {
}

for i, v := range *ls {
if v == filter {
if strings.EqualFold(v, filter) {
copy((*ls)[i:], (*ls)[i+1:])
*ls = (*ls)[:len(*ls)-1]
return
Expand Down Expand Up @@ -94,7 +95,7 @@ func appendUserIdentity(idType *compute.ResourceIdentityType, idList *[]string,

func checkIfIDInList(idList []string, desiredID string) bool {
for _, id := range idList {
if id == desiredID {
if strings.EqualFold(id, desiredID) {
return true
}
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/cloudprovider/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@ func TestAppendUserIdentity(t *testing.T) {
if idType != compute.ResourceIdentityTypeUserAssigned {
t.Fatalf("expected type %s, got: %s", compute.ResourceIdentityTypeUserAssigned, idType)
}

// test case sensitivity
idList = []string{}
expect = []string{"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/devcluster/providers/Microsoft.ManagedIdentity/userAssignedIdentities/keyvault-identity"}
append = appendUserIdentity(&idType, &idList, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/devcluster/providers/Microsoft.ManagedIdentity/userAssignedIdentities/keyvault-identity")
if !append {
t.Fatalf("Expecting the id to be not present. But present returned by Append.")
}
checkIDList(t, expect, idList)
if idType != compute.ResourceIdentityTypeUserAssigned {
t.Fatalf("expected type %s, got: %s", compute.ResourceIdentityTypeUserAssigned, idType)
}
// append same id with non camel case resourcegroups
append = appendUserIdentity(&idType, &idList, "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/devcluster/providers/Microsoft.ManagedIdentity/userAssignedIdentities/keyvault-identity")
if append {
t.Fatalf("Expecting the id to be present. But not present returned by Append.")
}
checkIDList(t, expect, idList)
if idType != compute.ResourceIdentityTypeUserAssigned {
t.Fatalf("expected type %s, got: %s", compute.ResourceIdentityTypeUserAssigned, idType)
}
}

func checkIDList(t *testing.T, expect, actual []string) {
Expand Down

0 comments on commit f453ce0

Please sign in to comment.