-
Notifications
You must be signed in to change notification settings - Fork 15
/
changes_test.go
91 lines (82 loc) · 2.8 KB
/
changes_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
80
81
82
83
84
85
86
87
88
89
90
91
package ldif_test
import (
"testing"
"github.com/go-ldap/ldif"
)
var ldifRFC2849Example6 = `version: 1
# Add a new entry
dn: cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com
changetype: add
objectclass: top
objectclass: person
objectclass: organizationalPerson
cn: Fiona Jensen
sn: Jensen
uid: fiona
telephonenumber: +1 408 555 1212
# jpegphoto:< file:///usr/local/directory/photos/fiona.jpg
# Delete an existing entry
dn: cn=Robert Jensen, ou=Marketing, dc=airius, dc=com
changetype: delete
# Modify an entry's relative distinguished name
#dn: cn=Paul Jensen, ou=Product Development, dc=airius, dc=com
#changetype: modrdn
#newrdn: cn=Paula Jensen
#deleteoldrdn: 1
# Rename an entry and move all of its children to a new location in
# the directory tree (only implemented by LDAPv3 servers).
#dn: ou=PD Accountants, ou=Product Development, dc=airius, dc=com
#changetype: modrdn
#newrdn: ou=Product Development Accountants
#deleteoldrdn: 0
#newsuperior: ou=Accounting, dc=airius, dc=com
# Modify an entry: add an additional value to the postaladdress
# attribute, completely delete the description attribute, replace
# the telephonenumber attribute with two values, and delete a specific
# value from the facsimiletelephonenumber attribute
dn: cn=Paula Jensen, ou=Product Development, dc=airius, dc=com
changetype: modify
add: postaladdress
postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086
-
# the example in the RFC has an empty line here, I don't think that's allowed...
delete: description
-
replace: telephonenumber
telephonenumber: +1 408 555 1234
telephonenumber: +1 408 555 5678
-
delete: facsimiletelephonenumber
facsimiletelephonenumber: +1 408 555 9876
-
# Modify an entry: replace the postaladdress attribute with an empty
# set of values (which will cause the attribute to be removed), and
# delete the entire description attribute. Note that the first will
# always succeed, while the second will only succeed if at least
# one value for the description attribute is present.
dn: cn=Ingrid Jensen, ou=Product Support, dc=airius, dc=com
changetype: modify
replace: postaladdress
-
delete: description
-
`
func TestLDIFParseRFC2849Example6(t *testing.T) {
l, err := ldif.Parse(ldifRFC2849Example6)
if err != nil {
t.Errorf("Failed to parse RFC 2849 example #6: %s", err)
}
if len(l.Entries) != 4 { // != 6
t.Errorf("invalid number of entries parsed: %d", len(l.Entries))
}
if l.Entries[3].Modify == nil {
t.Errorf("last entry not a modify request")
}
if l.Entries[3].Modify.Changes[1].Modification.Type != "description" {
t.Errorf("RFC 2849 example 6: no deletion of description in last entry")
}
if l.Entries[2].Modify.Changes[2].Modification.Type != "telephonenumber" &&
l.Entries[2].Modify.Changes[2].Modification.Vals[1] != "+1 408 555 5678" {
t.Errorf("RFC 2849 example 6: no replacing of telephonenumber")
}
}