client_test.go 750 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package ldap
  2. import (
  3. "github.com/astaxie/beego/logs"
  4. "log"
  5. "nginx-ui/server/models"
  6. "testing"
  7. )
  8. func TestCreate(t *testing.T) {
  9. server := models.LdapServer{
  10. Url: "ldap://192.168.1.95:389",
  11. BaseDN: "ou=users,dc=tonyandmoney,dc=cn",
  12. Key: "Test",
  13. }
  14. client, err := GetActiveClient(&server)
  15. if err != nil {
  16. log.Panic(err)
  17. }
  18. if client.Connected == false {
  19. log.Panic("connect fail")
  20. }
  21. err = client.Bind("cn=admin,dc=tonyandmoney,dc=cn", "TQ1312@kmlsx", true)
  22. if err != nil {
  23. logs.Error("Test error:", err)
  24. return
  25. }
  26. logs.Info("Test: ok")
  27. // tuonian
  28. users, err := client.Search("(&(objectClass=*)(uid=tuonian))")
  29. if err != nil {
  30. log.Panic(err)
  31. }
  32. for _, user := range users {
  33. logs.Info(user)
  34. }
  35. client.Close()
  36. }