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

Handle case sensitive id check #271

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to note - before the identity was never removed if it was manually created and the resourceID format was different in azure identity. With this change it'll be deleted even if the case is different in resourceID.

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