Repository navigation
Expand file tree
/
Copy pathchanges_test.go
More file actions
131 lines (121 loc) · 3.96 KB
/
Copy pathchanges_test.go
File metadata and controls
131 lines (121 loc) · 3.96 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package ldif_test
import (
"fmt"
"testing"
"github.com/go-ldap/ldap/v3"
"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
-
`
// A control made of an OID and an optional criticality flag but no
// controlValue (e.g. "control: <oid>" or "control: <oid> true") must parse: the
// "true"/"false" token must be read as the criticality, not as a controlValue.
func TestParseControlCriticality(t *testing.T) {
const tmpl = `version: 1
dn: ou=x,dc=example,dc=com
control: 2.16.840.1.113730.3.4.2%s
changetype: delete
`
cases := map[string]struct {
suffix string
wantCriticality bool
}{
"absent": {"", false},
"true": {" true", true},
"false": {" false", false},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
l, err := ldif.ParseWithControls(fmt.Sprintf(tmpl, tc.suffix))
if err != nil {
t.Fatalf("failed to parse control: %s", err)
}
ctrls := l.Entries[0].Del.Controls
if len(ctrls) != 1 {
t.Fatalf("expected 1 control, got %d", len(ctrls))
}
c, ok := ctrls[0].(*ldap.ControlManageDsaIT)
if !ok {
t.Fatalf("expected *ldap.ControlManageDsaIT, got %T", ctrls[0])
}
if c.Criticality != tc.wantCriticality {
t.Errorf("criticality = %v, want %v", c.Criticality, tc.wantCriticality)
}
})
}
}
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")
}
}