69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func hasLdapProfile() (bool, *LdapHandler) {
|
|
for _, profile := range fakeserver.authProfiles {
|
|
if p, ok := profile.(AuthProfileLdap); ok {
|
|
return true, p.ldap
|
|
}
|
|
}
|
|
return false, nil
|
|
}
|
|
|
|
func TestLdapAuth(t *testing.T) {
|
|
if ok, _ := hasLdapProfile(); !ok {
|
|
return
|
|
}
|
|
// optionnal test, need a ldap configuration in localtest.conf
|
|
v := fakeserver.getProfiles("xavier@example.org")
|
|
if len(v) != 1 {
|
|
t.Errorf("cannot valid test profile")
|
|
}
|
|
}
|
|
|
|
func TestLdapPool(t *testing.T) {
|
|
conns := []LdapClient{}
|
|
|
|
ok, l := hasLdapProfile()
|
|
if !ok {
|
|
return
|
|
}
|
|
cap := l.Cap()
|
|
|
|
// use all connexions in the pool, with one bonus
|
|
for i := 0; i < cap+1; i++ {
|
|
conn, err := l.GetConn()
|
|
if err != nil {
|
|
t.Errorf("Get error: %s", err)
|
|
}
|
|
conns = append(conns, conn)
|
|
}
|
|
// return the originally pooled connexions to the pool
|
|
for i := 0; i < cap; i++ {
|
|
if err := l.BackToPool(conns[i]); err != nil {
|
|
t.Errorf("BackToPool error: %s", err)
|
|
}
|
|
if nbConn := l.Len(); nbConn != i+1 {
|
|
t.Errorf("Pool didn't return used conn %d", nbConn)
|
|
}
|
|
// even if is was returned, it's still there
|
|
if !ldapIsAlive(conns[i]) {
|
|
t.Errorf("This connextion should not be closed")
|
|
}
|
|
}
|
|
// return the last one
|
|
if err := l.BackToPool(conns[cap]); err != nil {
|
|
t.Errorf("BackToPool error: %s", err)
|
|
}
|
|
if nbConn := l.Len(); nbConn != cap {
|
|
t.Errorf("The pool should be full")
|
|
}
|
|
// check it was closed
|
|
if ldapIsAlive(conns[cap]) {
|
|
t.Errorf("This connexion should be closed")
|
|
}
|
|
}
|