-
Notifications
You must be signed in to change notification settings - Fork 29
/
conn_test.go
79 lines (68 loc) · 3.09 KB
/
conn_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package auth
import (
"testing"
)
func TestConfigConnect(t *testing.T) {
if _, err := (&Config{Server: "127.0.0.1", Port: 1, Security: SecurityNone}).Connect(); err == nil {
t.Error("SecurityNone: Expected connect error but got nil")
}
if _, err := (&Config{Server: "127.0.0.1", Port: 1, Security: SecurityTLS}).Connect(); err == nil {
t.Error("SecurityTLS: Expected connect error but got nil")
}
if _, err := (&Config{Server: "127.0.0.1", Port: 1, Security: SecurityStartTLS}).Connect(); err == nil {
t.Error("SecurityStartTLS: Expected connect error but got nil")
}
if _, err := (&Config{Server: "127.0.0.1", Port: 1, Security: SecurityInsecureTLS}).Connect(); err == nil {
t.Error("SecurityInsecureTLS: Expected connect error but got nil")
}
if _, err := (&Config{Server: "127.0.0.1", Port: 1, Security: SecurityInsecureStartTLS}).Connect(); err == nil {
t.Error("SecurityInsecureStartTLS: Expected connect error but got nil")
}
if _, err := (&Config{Server: "127.0.0.1", Port: 1, Security: SecurityType(100)}).Connect(); err == nil {
t.Error("Invalid Security: Expected configuration error but got nil")
}
if testConfig.Server == "" {
t.Skip("ADTEST_SERVER not set")
return
}
if _, err := (&Config{Server: testConfig.Server, Port: testConfig.Port, Security: SecurityNone}).Connect(); err != nil {
t.Error("SecurityNone: Expected connect error to be nil but got:", err)
}
if _, err := (&Config{Server: testConfig.Server, Port: testConfig.TLSPort, Security: SecurityTLS}).Connect(); err != nil {
t.Error("SecurityTLS: Expected connect error to be nil but got:", err)
}
if _, err := (&Config{Server: testConfig.Server, Port: testConfig.Port, Security: SecurityStartTLS}).Connect(); err != nil {
t.Error("SecurityStartTLS: Expected connect error to be nil but got:", err)
}
if _, err := (&Config{Server: testConfig.Server, Port: testConfig.TLSPort, Security: SecurityInsecureTLS}).Connect(); err != nil {
t.Error("SecurityInsecureTLS: Expected connect error to be nil but got:", err)
}
if _, err := (&Config{Server: testConfig.Server, Port: testConfig.Port, Security: SecurityInsecureStartTLS}).Connect(); err != nil {
t.Error("SecurityInsecureStartTLS: Expected connect error to be nil but got:", err)
}
}
func TestConnBind(t *testing.T) {
if testConfig.Server == "" {
t.Skip("ADTEST_SERVER not set")
return
}
config := &Config{Server: testConfig.Server, Port: testConfig.Port, Security: testConfig.BindSecurity}
conn, err := config.Connect()
if err != nil {
t.Fatal("Error connecting to server:", err)
}
defer conn.Conn.Close()
if status, _ := conn.Bind("test", ""); status {
t.Error("Empty password: Expected authentication status to be false")
}
if status, _ := conn.Bind("go-ad-auth", "invalid_password"); status {
t.Error("Invalid credentials: Expected authentication status to be false")
}
if testConfig.BindUPN == "" || testConfig.BindPass == "" {
t.Skip("ADTEST_BIND_UPN or ADTEST_BIND_PASS not set")
return
}
if status, _ := conn.Bind(testConfig.BindUPN, testConfig.BindPass); !status {
t.Error("Valid credentials: Expected authentication status to be true")
}
}