From 707d5ae3899947fae6668a119d7bc31cb9f14fc2 Mon Sep 17 00:00:00 2001 From: Hanno Hecker Date: Thu, 4 May 2017 11:55:43 +0200 Subject: [PATCH] make Get(Raw)AttributeValues compare case insensitive This is the same way an LDAP server compares during a search request. Fixes #109 --- search.go | 6 ++++-- search_test.go | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/search.go b/search.go index 2a99894c..83ef6a37 100644 --- a/search.go +++ b/search.go @@ -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 } } @@ -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 } } diff --git a/search_test.go b/search_test.go index efb8147d..c03f23a2 100644 --- a/search_test.go +++ b/search_test.go @@ -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") + } +}