diff --git a/pkg/services/ldap/helpers.go b/pkg/services/ldap/helpers.go index 851725f2d19..384f2adb7c4 100644 --- a/pkg/services/ldap/helpers.go +++ b/pkg/services/ldap/helpers.go @@ -34,7 +34,7 @@ func getAttribute(name string, entry *ldap.Entry) string { } for _, attr := range entry.Attributes { - if attr.Name == name { + if strings.EqualFold(attr.Name, name) { if len(attr.Values) > 0 { return attr.Values[0] } @@ -49,7 +49,7 @@ func getArrayAttribute(name string, entry *ldap.Entry) []string { } for _, attr := range entry.Attributes { - if attr.Name == name && len(attr.Values) > 0 { + if strings.EqualFold(attr.Name, name) && len(attr.Values) > 0 { return attr.Values } } diff --git a/pkg/services/ldap/ldap_helpers_test.go b/pkg/services/ldap/ldap_helpers_test.go index 887a2a0a5df..bf45cb0b0a3 100644 --- a/pkg/services/ldap/ldap_helpers_test.go +++ b/pkg/services/ldap/ldap_helpers_test.go @@ -83,6 +83,20 @@ func TestGetAttribute(t *testing.T) { assert.Equal(t, value, result) }) + t.Run("letter case mismatch", func(t *testing.T) { + value := "roelgerrits" + entry := &ldap.Entry{ + Attributes: []*ldap.EntryAttribute{ + { + Name: "sAMAccountName", Values: []string{value}, + }, + }, + } + + result := getAttribute("samaccountname", entry) + assert.Equal(t, value, result) + }) + t.Run("no result", func(t *testing.T) { value := []string{"roelgerrits"} entry := &ldap.Entry{ @@ -124,6 +138,21 @@ func TestGetArrayAttribute(t *testing.T) { assert.EqualValues(t, value, result) }) + t.Run("letter case mismatch", func(t *testing.T) { + value := []string{"CN=Administrators,CN=Builtin,DC=grafana,DC=org"} + entry := &ldap.Entry{ + Attributes: []*ldap.EntryAttribute{ + { + Name: "memberOf", Values: value, + }, + }, + } + + result := getArrayAttribute("memberof", entry) + + assert.EqualValues(t, value, result) + }) + t.Run("no result", func(t *testing.T) { value := []string{"roelgerrits"} entry := &ldap.Entry{