-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldapurl_test.go
77 lines (62 loc) · 1.64 KB
/
ldapurl_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
package ldapurl
import (
"fmt"
"log"
"testing"
)
func TestParseValidURL(t *testing.T) {
ldapurl, err := Parse("ldap://ldap.jcu.edu.au:19389/dc=jcu,dc=edu,dc=au")
if err != nil {
log.Fatal(err)
t.Errorf("Error doing basic URL parse")
}
if ldapurl.Scheme != "ldap" {
t.Errorf("Scheme not parsed correctly")
}
if ldapurl.Host != "ldap.jcu.edu.au" {
t.Errorf("Host not parsed correctly")
}
if ldapurl.Port != 19389 {
t.Errorf("Port does not have correct value")
}
if ldapurl.IsTLS() {
t.Errorf("Not marked as not being a TLS URL")
}
}
func TestParseValidTLSURL(t *testing.T) {
ldapurl, err := Parse("ldaps://ldap.jcu.edu.au/dc=jcu,dc=edu,dc=au")
if err != nil {
log.Fatal(err)
t.Errorf("Error doing basic URL parse")
}
if ldapurl.Scheme != "ldaps" {
t.Errorf("Scheme not parsed correctly")
}
if ldapurl.Host != "ldap.jcu.edu.au" {
t.Errorf("Host not parsed correctly")
}
if ldapurl.Port != DefaultLdapsPort {
t.Errorf("Port does not have correct default value")
}
if !ldapurl.IsTLS() {
t.Errorf("Not marked as being a TLS URL")
}
}
func TestLdapURL_BuildHostnamePortString(t *testing.T) {
ldapurl, err := Parse("ldaps://ldap.jcu.edu.au/dc=jcu,dc=edu,dc=au")
if err != nil {
log.Fatal(err)
t.Errorf("Error doing basic URL parse")
}
if ldapurl.BuildHostnamePortString() != "ldap.jcu.edu.au:636" {
t.Errorf("Hostname port string not correct: %s", ldapurl.BuildHostnamePortString())
}
}
func TestParseFilterURL(t *testing.T) {
ldapurl, err := Parse("ldap:///dc=jcu,dc=edu,[email protected]")
if err != nil {
log.Fatal(err)
t.Errorf("Error doing basic URL parse")
}
fmt.Printf("%+v\n",ldapurl)
}