diff options
Diffstat (limited to 'server_modify_test.go')
| -rw-r--r-- | server_modify_test.go | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/server_modify_test.go b/server_modify_test.go index 7050a32..6705343 100644 --- a/server_modify_test.go +++ b/server_modify_test.go @@ -13,20 +13,21 @@ func TestAdd(t *testing.T) { done := make(chan bool) s := NewServer() defer s.Close() + ln, addr := mustListen() go func() { s.BindFunc("", modifyTestHandler{}) s.AddFunc("", modifyTestHandler{}) - if err := s.ListenAndServe(listenString); err != nil { - t.Errorf("s.ListenAndServe failed: %s", err.Error()) + if err := s.Serve(ln); err != nil { + t.Errorf("s.Serve failed: %s", err.Error()) } }() go func() { - cmd := exec.Command("ldapadd", "-v", "-H", ldapURL, "-x", "-f", "tests/add.ldif") + cmd := exec.Command("ldapadd", "-v", "-H", "ldap://"+addr, "-x", "-f", "tests/add.ldif") out, _ := cmd.CombinedOutput() if !strings.Contains(string(out), "modify complete") { t.Errorf("ldapadd failed: %v", string(out)) } - cmd = exec.Command("ldapadd", "-v", "-H", ldapURL, "-x", "-f", "tests/add2.ldif") + cmd = exec.Command("ldapadd", "-v", "-H", "ldap://"+addr, "-x", "-f", "tests/add2.ldif") out, _ = cmd.CombinedOutput() if !strings.Contains(string(out), "ldap_add: Insufficient access") { t.Errorf("ldapadd should have failed: %v", string(out)) @@ -48,20 +49,21 @@ func TestDelete(t *testing.T) { done := make(chan bool) s := NewServer() defer s.Close() + ln, addr := mustListen() go func() { s.BindFunc("", modifyTestHandler{}) s.DeleteFunc("", modifyTestHandler{}) - if err := s.ListenAndServe(listenString); err != nil { - t.Errorf("s.ListenAndServe failed: %s", err.Error()) + if err := s.Serve(ln); err != nil { + t.Errorf("s.Serve failed: %s", err.Error()) } }() go func() { - cmd := exec.Command("ldapdelete", "-v", "-H", ldapURL, "-x", "cn=Delete Me,dc=example,dc=com") + cmd := exec.Command("ldapdelete", "-v", "-H", "ldap://"+addr, "-x", "cn=Delete Me,dc=example,dc=com") out, _ := cmd.CombinedOutput() if !strings.Contains(string(out), "Delete Result: Success (0)") || !strings.Contains(string(out), "Additional info: Success") { t.Errorf("ldapdelete failed: %v", string(out)) } - cmd = exec.Command("ldapdelete", "-v", "-H", ldapURL, "-x", "cn=Bob,dc=example,dc=com") + cmd = exec.Command("ldapdelete", "-v", "-H", "ldap://"+addr, "-x", "cn=Bob,dc=example,dc=com") out, _ = cmd.CombinedOutput() if strings.Contains(string(out), "Success") || !strings.Contains(string(out), "ldap_delete: Insufficient access") { t.Errorf("ldapdelete should have failed: %v", string(out)) @@ -79,20 +81,21 @@ func TestModify(t *testing.T) { done := make(chan bool) s := NewServer() defer s.Close() + ln, addr := mustListen() go func() { s.BindFunc("", modifyTestHandler{}) s.ModifyFunc("", modifyTestHandler{}) - if err := s.ListenAndServe(listenString); err != nil { - t.Errorf("s.ListenAndServe failed: %s", err.Error()) + if err := s.Serve(ln); err != nil { + t.Errorf("s.Serve failed: %s", err.Error()) } }() go func() { - cmd := exec.Command("ldapmodify", "-v", "-H", ldapURL, "-x", "-f", "tests/modify.ldif") + cmd := exec.Command("ldapmodify", "-v", "-H", "ldap://"+addr, "-x", "-f", "tests/modify.ldif") out, _ := cmd.CombinedOutput() if !strings.Contains(string(out), "modify complete") { t.Errorf("ldapmodify failed: %v", string(out)) } - cmd = exec.Command("ldapmodify", "-v", "-H", ldapURL, "-x", "-f", "tests/modify2.ldif") + cmd = exec.Command("ldapmodify", "-v", "-H", "ldap://"+addr, "-x", "-f", "tests/modify2.ldif") out, _ = cmd.CombinedOutput() if !strings.Contains(string(out), "ldap_modify: Insufficient access") || strings.Contains(string(out), "modify complete") { t.Errorf("ldapmodify should have failed: %v", string(out)) |
