aboutsummaryrefslogtreecommitdiff
path: root/server_search_test.go
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2019-02-13 07:20:14 +0200
committerMarin Ivanov <[email protected]>2019-02-13 07:26:13 +0200
commita1a0a3aae7ef762250b9295985be1eee41d7a49e (patch)
tree39accaebbd5c1fad072fc7ecb2360c0db6b21bef /server_search_test.go
parentcb4f041b8be79b49eb046466ceb1bea9cfcaeb87 (diff)
Revert the simplification of Searcher and Binder interfaces
* Revert "Simplify sever search functions" commit 9402a7d580c2dd929c68cf8b3038a1e6496f607f. * Revert "Simplify server bind functions" commit 82a8f44a2f4cf0686635d2a23ebb41a8f445194e. * Fix tests
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())
}