-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathldap_test.go
42 lines (38 loc) · 893 Bytes
/
ldap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ldap
import (
"crypto/tls"
"testing"
"gopkg.in/stretchr/testify.v1/assert"
)
func TestDialAndBind(t *testing.T) {
var tlsConfig = tls.Config{
InsecureSkipVerify: true,
}
var tests = []struct {
addr string
fn func(string) (Conn, error)
}{
{"localhost:389", Dial},
{"localhost:636", func(addr string) (Conn, error) {
return DialSSL(addr, &tlsConfig)
}},
{"localhost:389", func(addr string) (Conn, error) {
return DialTLS(addr, &tlsConfig)
}},
}
for _, test := range tests {
func() {
conn, err := test.fn(test.addr)
if !assert.NoError(t, err, "error connecting to %v", test.addr) {
return
}
defer conn.Close()
err = conn.Bind("cn=Alice Lastname,ou=users,dc=example,dc=org", "password")
if !assert.NoError(t, err, "error binding") {
return
}
err = conn.Unbind()
assert.NoError(t, err, "error unbinding")
}()
}
}