1234567891011121314151617181920212223242526272829303132333435363738 |
- package ldap
- import (
- "github.com/astaxie/beego/logs"
- "log"
- "nginx-ui/server/models"
- "testing"
- )
- func TestCreate(t *testing.T) {
- server := models.LdapServer{
- Url: "ldap://192.168.1.95:389",
- BaseDN: "ou=users,dc=tonyandmoney,dc=cn",
- Key: "Test",
- }
- client, err := GetActiveClient(&server)
- if err != nil {
- log.Panic(err)
- }
- if client.Connected == false {
- log.Panic("connect fail")
- }
- err = client.Bind("cn=admin,dc=tonyandmoney,dc=cn", "TQ1312@kmlsx", true)
- if err != nil {
- logs.Error("Test error:", err)
- return
- }
- logs.Info("Test: ok")
- // tuonian
- users, err := client.Search("(&(objectClass=*)(uid=tuonian))")
- if err != nil {
- log.Panic(err)
- }
- for _, user := range users {
- logs.Info(user)
- }
- client.Close()
- }
|