mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
LDAP: Make LDAP attribute mapping case-insensitive (#58992)
* Make LDAP attribute mapping case-insensitive * Add test case with attribute name different from schema's * Add fix to getArrayAttribute also and add test with mismatched letter case. * Update pkg/services/ldap/helpers.go Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
This commit is contained in:
parent
4d8287b319
commit
91582ba03d
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user