-
Notifications
You must be signed in to change notification settings - Fork 0
/
dn_test.go
71 lines (65 loc) · 1.99 KB
/
dn_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
package dirsyn
import (
"testing"
)
func TestDistinguishedName(t *testing.T) {
var r RFC4514
for _, dn := range []string{
`uid=jesse,ou=People,o=example\, co`,
`uid=jesse+uidNumber=5042,ou=People,o=example\, co`,
`cn=example`,
`l=z`,
`l=xy`,
`l=abc`,
`UID=jsmith,DC=example,DC=net`,
`OU=Sales+CN=J. Smith,DC=example,DC=net`,
`CN=John Smith\, III,DC=example,DC=net`,
`CN=Before\0dAfter,DC=example,DC=net`,
`1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com`,
`CN=Lu\C4\8Di\C4\87`,
} {
dn, err := r.DistinguishedName(dn)
if err != nil {
t.Errorf("%s failed [%s]: %v", t.Name(), dn, err)
}
}
dN(`OU=Sales+CN=J. Smith,DC=example,DC=net`)
dn, _ := marshalDistinguishedName(`OU=Sales+CN=J. Smith,DC=example,DC=net`)
_ = dn.RDNs[0].Attributes[0].String()
dn.RDNs[0].Attributes[0].Equal(dn.RDNs[0].Attributes[0])
dn.RDNs[0].Attributes[0].EqualFold(dn.RDNs[0].Attributes[0])
_ = dn.RDNs[0].String()
dn.RDNs[0].Equal(dn.RDNs[0])
dn.RDNs[0].EqualFold(dn.RDNs[0])
_ = dn.String()
distinguishedNameMatch(dn, `uid=jesse`)
dn.Equal(dn)
dn.EqualFold(dn)
dn.AncestorOf(dn)
}
func TestNameAndOptionalUID(t *testing.T) {
var r RFC4517
for idx, noptuid := range []string{
`uid=jesse,ou=People,o=example\, co#'10100011'B`,
`uid=jesse,ou=People,o=example\, co`,
} {
if nou, err := r.NameAndOptionalUID(noptuid); err != nil {
t.Errorf("%s[%d] failed: %v", t.Name(), idx, err)
} else {
marshalNameAndOptionalUID(nou)
marshalNameAndOptionalUID(nou.DN)
uniqueMemberMatch(nou, nou)
distinguishedNameMatch(nou.DN, nil)
}
}
nameAndOptionalUID(`uid=jesse,ou=People,o=example\, co#'10100011'B`)
marshalNameAndOptionalUID(`uid=jesse,ou=People,o=example\, co#'10100011'B`)
marshalDistinguishedName(``)
marshalDistinguishedName(`A`)
dn, _ := marshalDistinguishedName([]byte(`uid=jesse,dc=example,dc=com`))
dn2, _ := marshalDistinguishedName([]byte(`uid=jesse,o=example`))
uniqueMemberMatch(nil, dn)
uniqueMemberMatch(dn, nil)
uniqueMemberMatch(dn, dn)
uniqueMemberMatch(dn, dn2)
}