aboutsummaryrefslogtreecommitdiff
path: root/server_search_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'server_search_test.go')
-rw-r--r--server_search_test.go75
1 files changed, 60 insertions, 15 deletions
diff --git a/server_search_test.go b/server_search_test.go
index 4cf2089..86c5297 100644
--- a/server_search_test.go
+++ b/server_search_test.go
@@ -14,8 +14,8 @@ func TestSearchSimpleOK(t *testing.T) {
defer s.Close()
ln, addr := mustListen()
go func() {
- s.Search = SearchSimple
- s.Bind = BindSimple
+ s.SearchFunc("", searchSimple{})
+ s.BindFunc("", bindSimple{})
if err := s.Serve(ln); err != nil {
t.Errorf("s.Serve failed: %s", err.Error())
}
@@ -56,8 +56,8 @@ func TestSearchSizelimit(t *testing.T) {
ln, addr := mustListen()
go func() {
s.EnforceLDAP = true
- s.Search = SearchSimple
- s.Bind = BindSimple
+ s.SearchFunc("", searchSimple{})
+ s.BindFunc("", bindSimple{})
if err := s.Serve(ln); err != nil {
t.Errorf("s.Serve failed: %s", err.Error())
}
@@ -144,14 +144,59 @@ func TestSearchSizelimit(t *testing.T) {
}
/////////////////////////
+func TestBindSearchMulti(t *testing.T) {
+ done := make(chan bool)
+ s := NewServer()
+ defer s.Close()
+ ln, addr := mustListen()
+ go func() {
+ s.BindFunc("", bindSimple{})
+ s.BindFunc("c=testz", bindSimple2{})
+ s.SearchFunc("", searchSimple{})
+ s.SearchFunc("c=testz", searchSimple2{})
+ if err := s.Serve(ln); err != nil {
+ t.Errorf("s.Serve failed: %s", err.Error())
+ }
+ }()
+
+ go func() {
+ cmd := exec.Command("ldapsearch", "-H", "ldap://"+addr, "-x", "-b", "o=testers,c=test",
+ "-D", "cn=testy,o=testers,c=test", "-w", "iLike2test", "cn=ned")
+ out, _ := cmd.CombinedOutput()
+ if !strings.Contains(string(out), "result: 0 Success") {
+ t.Errorf("error routing default bind/search functions: %v", string(out))
+ }
+ if !strings.Contains(string(out), "dn: cn=ned,o=testers,c=test") {
+ t.Errorf("search default routing failed: %v", string(out))
+ }
+ cmd = exec.Command("ldapsearch", "-H", "ldap://"+addr, "-x", "-b", "o=testers,c=testz",
+ "-D", "cn=testy,o=testers,c=testz", "-w", "ZLike2test", "cn=hamburger")
+ out, _ = cmd.CombinedOutput()
+ if !strings.Contains(string(out), "result: 0 Success") {
+ t.Errorf("error routing custom bind/search functions: %v", string(out))
+ }
+ if !strings.Contains(string(out), "dn: cn=hamburger,o=testers,c=testz") {
+ t.Errorf("search custom routing failed: %v", string(out))
+ }
+ done <- true
+ }()
+
+ select {
+ case <-done:
+ case <-time.After(timeout):
+ t.Errorf("ldapsearch command timed out")
+ }
+}
+
+/////////////////////////
func TestSearchPanic(t *testing.T) {
done := make(chan bool)
s := NewServer()
defer s.Close()
ln, addr := mustListen()
go func() {
- s.Search = SearchPanic
- s.Bind = BindAnonOK
+ s.SearchFunc("", searchPanic{})
+ s.BindFunc("", bindAnonOK{})
if err := s.Serve(ln); err != nil {
t.Errorf("s.Serve failed: %s", err.Error())
}
@@ -216,8 +261,8 @@ func TestSearchFiltering(t *testing.T) {
ln, addr := mustListen()
go func() {
s.EnforceLDAP = true
- s.Search = SearchSimple
- s.Bind = BindSimple
+ s.SearchFunc("", searchSimple{})
+ s.BindFunc("", bindSimple{})
if err := s.Serve(ln); err != nil {
t.Errorf("s.Serve failed: %s", err.Error())
}
@@ -252,8 +297,8 @@ func TestSearchAttributes(t *testing.T) {
ln, addr := mustListen()
go func() {
s.EnforceLDAP = true
- s.Search = SearchSimple
- s.Bind = BindSimple
+ s.SearchFunc("", searchSimple{})
+ s.BindFunc("", bindSimple{})
if err := s.Serve(ln); err != nil {
t.Errorf("s.Serve failed: %s", err.Error())
}
@@ -295,8 +340,8 @@ func TestSearchScope(t *testing.T) {
ln, addr := mustListen()
go func() {
s.EnforceLDAP = true
- s.Search = SearchSimple
- s.Bind = BindSimple
+ s.SearchFunc("", searchSimple{})
+ s.BindFunc("", bindSimple{})
if err := s.Serve(ln); err != nil {
t.Errorf("s.Serve failed: %s", err.Error())
}
@@ -341,7 +386,7 @@ func TestSearchScope(t *testing.T) {
select {
case <-done:
- case <-time.After(2 * timeout):
+ case <-time.After(2*timeout):
t.Errorf("ldapsearch command timed out")
}
}
@@ -352,8 +397,8 @@ func TestSearchControls(t *testing.T) {
defer s.Close()
ln, addr := mustListen()
go func() {
- s.Search = SearchControls
- s.Bind = BindSimple
+ s.SearchFunc("", searchControls{})
+ s.BindFunc("", bindSimple{})
if err := s.Serve(ln); err != nil {
t.Errorf("s.Serve failed: %s", err.Error())
}