From 7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 21 Jul 2021 00:27:43 +0800 Subject: strings in LDAP are case-insensitive (#8) Thank you @wxiaoguang ! * strings in LDAP are case-insensitive * optmize routeFunc (faster, case-insensitive) * small optimiztion to routeFunc * request the directory server to return operational attributes by adding + (the plus sign) in your ldapsearch command. * request the directory server to return operational attributes by adding + (the plus sign) in your ldapsearch command. * request the directory server to return operational attributes by adding + (the plus sign) in your ldapsearch command. * remove operational attributes --- server_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'server_test.go') diff --git a/server_test.go b/server_test.go index 88c47bf..233f7ea 100644 --- a/server_test.go +++ b/server_test.go @@ -329,6 +329,17 @@ func (b bindPanic) Bind(bindDN, bindSimplePw string, conn net.Conn) (LDAPResultC return LDAPResultInvalidCredentials, nil } +type bindCaseInsensitive struct { +} + +func (b bindCaseInsensitive) Bind(bindDN, bindSimplePw string, conn net.Conn) (LDAPResultCode, error) { + if strings.ToLower(bindDN) == "cn=case,o=testers,c=test" && bindSimplePw == "iLike2test" { + return LDAPResultSuccess, nil + } + return LDAPResultInvalidCredentials, nil +} + + type searchSimple struct { } @@ -408,3 +419,41 @@ func (s searchControls) Search(boundDN string, searchReq SearchRequest, conn net } return ServerSearchResult{entries, []string{}, []Control{}, LDAPResultSuccess}, nil } + + +type searchCaseInsensitive struct { +} + +func (s searchCaseInsensitive) Search(boundDN string, searchReq SearchRequest, conn net.Conn) (ServerSearchResult, error) { + entries := []*Entry{ + &Entry{"cn=CASE,o=testers,c=test", []*EntryAttribute{ + &EntryAttribute{"cn", []string{"CaSe"}}, + &EntryAttribute{"o", []string{"ate"}}, + &EntryAttribute{"uidNumber", []string{"5005"}}, + &EntryAttribute{"accountstatus", []string{"active"}}, + &EntryAttribute{"uid", []string{"trent"}}, + &EntryAttribute{"description", []string{"trent via sa"}}, + &EntryAttribute{"objectclass", []string{"posixaccount"}}, + }}, + } + return ServerSearchResult{entries, []string{}, []Control{}, LDAPResultSuccess}, nil +} + + +func TestRouteFunc(t *testing.T) { + if routeFunc("", []string{"a", "xyz", "tt"}) != "" { + t.Error("routeFunc failed") + } + if routeFunc("a=b", []string{"a=b", "x=y,a=b", "tt"}) != "a=b" { + t.Error("routeFunc failed") + } + if routeFunc("x=y,a=b", []string{"a=b", "x=y,a=b", "tt"}) != "x=y,a=b" { + t.Error("routeFunc failed") + } + if routeFunc("x=y,a=b", []string{"x=y,a=b", "a=b", "tt"}) != "x=y,a=b" { + t.Error("routeFunc failed") + } + if routeFunc("nosuch", []string{"x=y,a=b", "a=b", "tt"}) != "" { + t.Error("routeFunc failed") + } +} -- cgit v1.2.3