-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdn_test.go
More file actions
71 lines (67 loc) · 1.57 KB
/
Copy pathdn_test.go
File metadata and controls
71 lines (67 loc) · 1.57 KB
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
//go:build test
package main
import (
"strings"
"testing"
)
func TestDNNormalize(t *testing.T) {
testcases := []struct {
Value string
ExpectedNorm string
ExpectedOrig string
}{
{
"cn = te St , ou=People, DC=EXAMPLE, DC=COM",
"cn=te st,ou=people,dc=example,dc=com",
"cn=te St,ou=People,DC=EXAMPLE,DC=COM",
},
{
"ou=People,DC=example,DC=com",
"ou=people,dc=example,dc=com",
"ou=People,DC=example,DC=com",
},
{
"DC=example,DC=com",
"dc=example,dc=com",
"DC=example,DC=com",
},
{
"DC=com",
"dc=com",
"DC=com",
},
{
"DC=example,DC=org",
"dc=example,dc=org",
"DC=example,DC=org",
},
{
"",
"",
"",
},
}
server := NewServer(&ServerConfig{
Suffix: "dc=example,dc=com",
})
schemaMap := InitSchemaMap(server)
for i, tc := range testcases {
dn, err := NormalizeDN(schemaMap, tc.Value)
if err != nil {
t.Errorf("Unexpected error on %d:\n'%s' -> '%s' expected, got err: %+v\n", i, tc.Value, tc.ExpectedNorm, err)
continue
}
if dn.DNNormStr() != tc.ExpectedNorm {
t.Errorf("Unexpected error on %d:\nDNNorm:\n'%s' -> %s' expected, got '%s'\n", i, tc.Value, tc.ExpectedNorm, dn.DNNormStr())
continue
}
if dn.DNOrigStr() != tc.ExpectedOrig {
t.Errorf("Unexpected error on %d:\nDNOrig:\n'%s' expected, got '%s'\n", i, tc.ExpectedOrig, dn.DNOrigStr())
continue
}
if strings.HasSuffix(dn.DNOrigStr(), "dc=example,dc=com") {
t.Errorf("Unexpected error on %d:\nDNOrig:\n'%s' doesn't have %s as suffix' expected, but not\n", i, tc.Value, dn.DNOrigStr())
continue
}
}
}