forked from korylprince/go-ad-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
61 lines (58 loc) · 1.46 KB
/
config_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
package auth
import "testing"
func TestConfigDomain(t *testing.T) {
tests := []string{
"dc=example,dc=com",
"ou=test,dc=example,dc=com",
"dc=example, dc=com",
"DC=example,DC=com",
"OU=test,dc=example,DC=com",
}
for _, test := range tests {
if domain, err := (&Config{BaseDN: test}).Domain(); domain != "example.com" {
if err != nil {
t.Error("Failed Test:", test, "\n\tError:", err)
} else {
t.Error("Failed Test:", test, "\n\tOutput:", domain, "Expected: example.com")
}
}
}
errorTests := []string{
"",
"com",
"ou=test",
"OU=test",
}
for _, test := range errorTests {
if _, err := (&Config{BaseDN: test}).Domain(); err == nil {
t.Error("Failed Test:", test, "\n\tError: err not nil")
}
}
}
func TestConfigUPN(t *testing.T) {
dnTests := []string{
"dc=example,dc=com",
"ou=test,dc=example,dc=com",
"dc=example, dc=com",
"DC=example,DC=com",
"OU=test,dc=example,DC=com",
}
userTests := []string{
"example.user",
"example.user@example.com",
}
for _, dn := range dnTests {
for _, user := range userTests {
if upn, err := (&Config{BaseDN: dn}).UPN(user); upn != "example.user@example.com" {
if err != nil {
t.Error("Failed Test:", dn, user, "\n\tError:", err)
} else {
t.Error("Failed Test:", dn, user, "\n\tOutput:", upn, "Expected: example.user@example.com")
}
}
}
}
if _, err := (&Config{BaseDN: "Bad OU"}).UPN("Test"); err == nil {
t.Error("Expected configuration error but got nil")
}
}