Skip to content

Commit

Permalink
make Get(Raw)AttributeValues compare case insensitive
Browse files Browse the repository at this point in the history
This is the same way an LDAP server compares during a search request.

Fixes go-ldap#109
  • Loading branch information
vetinari committed May 4, 2017
1 parent 13cedcf commit 707d5ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ type Entry struct {

// GetAttributeValues returns the values for the named attribute, or an empty list
func (e *Entry) GetAttributeValues(attribute string) []string {
attribute = strings.ToLower(attribute)
for _, attr := range e.Attributes {
if attr.Name == attribute {
if strings.ToLower(attr.Name) == attribute {
return attr.Values
}
}
Expand All @@ -138,8 +139,9 @@ func (e *Entry) GetAttributeValues(attribute string) []string {

// GetRawAttributeValues returns the byte values for the named attribute, or an empty list
func (e *Entry) GetRawAttributeValues(attribute string) [][]byte {
attribute = strings.ToLower(attribute)
for _, attr := range e.Attributes {
if attr.Name == attribute {
if strings.ToLower(attr.Name) == attribute {
return attr.ByteValues
}
}
Expand Down
18 changes: 18 additions & 0 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ func TestNewEntry(t *testing.T) {
iteration = iteration + 1
}
}

func TestGetAttributeValue(t *testing.T) {
dn := "testDN"
attributes := map[string][]string{
"Alpha": {"value"},
"bEta": {"value"},
"gaMma": {"value"},
"delTa": {"value"},
"epsiLon": {"value"},
}
entry := NewEntry(dn, attributes)
if entry.GetAttributeValue("Alpha") != "value" {
t.Errorf("failed to get attribute in original case")
}
if entry.GetAttributeValue("alpha") != "value" {
t.Errorf("failed to get attribute in changed case")
}
}

0 comments on commit 707d5ae

Please sign in to comment.