Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 192 lines (156 sloc) 4.567 kb
455ad0f @gbarr Initial revision
gbarr authored
1 #!perl
2
3 BEGIN {
4 require "t/common.pl";
5 }
6
7
e79c9ea @gbarr RT#44110 Fix Net::LDAP::LDIF->current_lines
gbarr authored
8 print "1..16\n";
455ad0f @gbarr Initial revision
gbarr authored
9
10 use Net::LDAP::LDIF;
11
ccae27f @gbarr Some testcase tweaks
gbarr authored
12 my $infile = "data/00-in.ldif";
13 my $outfile1 = "$TEMPDIR/00-out1.ldif";
14 my $outfile2 = "$TEMPDIR/00-out2.ldif";
15 my $cmpfile1 = "data/00-cmp.ldif";
16 my $cmpfile2 = $infile;
455ad0f @gbarr Initial revision
gbarr authored
17
ccae27f @gbarr Some testcase tweaks
gbarr authored
18 my $ldif = Net::LDAP::LDIF->new($infile,"r");
455ad0f @gbarr Initial revision
gbarr authored
19
e79c9ea @gbarr RT#44110 Fix Net::LDAP::LDIF->current_lines
gbarr authored
20 my $entry0_ldif = <<'LDIF';
895e0a1 @gbarr Add ldif method to Net::LDAP::Entry
gbarr authored
21 dn: o=University of Michigan, c=US
22 objectclass: top
23 objectclass: organization
24 objectclass: domainRelatedObject
25 objectclass: quipuObject
26 objectclass: quipuNonLeafObject
27 l: Ann Arbor, Michigan
28 st: Michigan
29 streetaddress: 535 West William St.
30 o: University of Michigan
31 o: UMICH
32 o: UM
33 o: U-M
34 o: U of M
35 description: The University of Michigan at Ann Arbor
36 postaladdress: University of Michigan $ 535 W. William St. $ Ann Arbor, MI 481
37 09 $ USpostalcode: 48109
38 telephonenumber: +1 313 764-1817
39 lastmodifiedtime: 930106182800Z
40 lastmodifiedby: cn=manager, o=university of michigan, c=US
41 associateddomain: umich.edu
42 LDIF
43
e79c9ea @gbarr RT#44110 Fix Net::LDAP::LDIF->current_lines
gbarr authored
44 my $e = $ldif->read_entry;
45 my @lines = $ldif->current_lines;
46 is(join("",@lines),$entry0_ldif,"ldif lines");
47
48 my @entry = ($e, $ldif->read);
49
50 ok($ldif->version == 1, "version == 1");
51
52 Net::LDAP::LDIF->new($outfile1,"w")->write(@entry);
53 Net::LDAP::LDIF->new($outfile2,"w", version => 1)->write(@entry);
54
55 ok(!compare($cmpfile1,$outfile1), $cmpfile1);
56
57 ok(!compare($cmpfile2,$outfile2), $cmpfile2);
58
59
60 is($e->ldif, "\n$entry0_ldif", "ldif method");
61
62
895e0a1 @gbarr Add ldif method to Net::LDAP::Entry
gbarr authored
63 is($e->ldif(change => 1), <<'LDIF', "ldif method");
64
65 dn: o=University of Michigan, c=US
66 changetype: add
67 objectclass: top
68 objectclass: organization
69 objectclass: domainRelatedObject
70 objectclass: quipuObject
71 objectclass: quipuNonLeafObject
72 l: Ann Arbor, Michigan
73 st: Michigan
74 streetaddress: 535 West William St.
75 o: University of Michigan
76 o: UMICH
77 o: UM
78 o: U-M
79 o: U of M
80 description: The University of Michigan at Ann Arbor
81 postaladdress: University of Michigan $ 535 W. William St. $ Ann Arbor, MI 481
82 09 $ USpostalcode: 48109
83 telephonenumber: +1 313 764-1817
84 lastmodifiedtime: 930106182800Z
85 lastmodifiedby: cn=manager, o=university of michigan, c=US
86 associateddomain: umich.edu
87 LDIF
88
89
455ad0f @gbarr Initial revision
gbarr authored
90 $e->changetype('modify');
91 $e->delete('objectclass');
92 $e->delete('o',['UM']);
93 $e->add('counting',[qw(one two three)]);
35da62e @gbarr Ensure dashes are only output between parts of an LDAP update entry
gbarr authored
94 $e->add('first',[qw(1 2 3)], 'second',[qw(a b c)]);
455ad0f @gbarr Initial revision
gbarr authored
95 $e->replace('telephonenumber' => ['911']);
96
895e0a1 @gbarr Add ldif method to Net::LDAP::Entry
gbarr authored
97 is($e->ldif, <<'LDIF',"changes ldif");
98
99 dn: o=University of Michigan, c=US
100 changetype: modify
101 delete: objectclass
102 -
103 delete: o
104 o: UM
105 -
106 add: counting
107 counting: one
108 counting: two
109 counting: three
110 -
111 add: first
112 first: 1
113 first: 2
114 first: 3
115 -
116 add: second
117 second: a
118 second: b
119 second: c
120 -
121 replace: telephonenumber
122 telephonenumber: 911
123 LDIF
124
125 is($e->ldif(change => 0), <<'LDIF',"changes ldif");
126
127 dn: o=University of Michigan, c=US
128 l: Ann Arbor, Michigan
129 st: Michigan
130 streetaddress: 535 West William St.
131 o: University of Michigan
132 o: UMICH
133 o: U-M
134 o: U of M
135 description: The University of Michigan at Ann Arbor
136 postaladdress: University of Michigan $ 535 W. William St. $ Ann Arbor, MI 481
137 09 $ USpostalcode: 48109
138 telephonenumber: 911
139 lastmodifiedtime: 930106182800Z
140 lastmodifiedby: cn=manager, o=university of michigan, c=US
141 associateddomain: umich.edu
142 counting: one
143 counting: two
144 counting: three
145 first: 1
146 first: 2
147 first: 3
148 second: a
149 second: b
150 second: c
151 LDIF
152
f92737d @gbarr Prepare 0.33
gbarr authored
153 $outfile = "$TEMPDIR/00-out3.ldif";
455ad0f @gbarr Initial revision
gbarr authored
154 $cmpfile = "data/00-cmp2.ldif";
155
156 $ldif = Net::LDAP::LDIF->new($outfile,"w");
157 $ldif->write($e);
158 $ldif->write_cmd($e);
159 $ldif->done;
ccae27f @gbarr Some testcase tweaks
gbarr authored
160 ok(!compare($cmpfile,$outfile), $cmpfile);
d35350c @gbarr *** empty log message ***
gbarr authored
161
162 $e->add('name' => 'Graham Barr');
163 $e->add('name;en-us' => 'Bob');
164
ccae27f @gbarr Some testcase tweaks
gbarr authored
165 print "not " unless
166 ok(
167 join(":",sort $e->attributes)
168 eq
169 "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:name;en-us:o:postaladdress:second:st:streetaddress:telephonenumber",
170 "attributes");
d35350c @gbarr *** empty log message ***
gbarr authored
171
ccae27f @gbarr Some testcase tweaks
gbarr authored
172 print "not " unless
173 ok(
174 join(":",sort $e->attributes(nooptions => 1))
175 eq
176 "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:o:postaladdress:second:st:streetaddress:telephonenumber",
177 "attributes - nooptions");
d35350c @gbarr *** empty log message ***
gbarr authored
178
d041411 @gbarr *** empty log message ***
gbarr authored
179 $r = $e->get_value('name', asref => 1);
ccae27f @gbarr Some testcase tweaks
gbarr authored
180 ok(($r and @$r == 1 and $r->[0] eq 'Graham Barr'), "name eq Graham Barr");
d35350c @gbarr *** empty log message ***
gbarr authored
181
d041411 @gbarr *** empty log message ***
gbarr authored
182 $r = $e->get_value('name;en-us', asref => 1);
ccae27f @gbarr Some testcase tweaks
gbarr authored
183 ok(($r and @$r == 1 and $r->[0] eq 'Bob'), "name;en-us eq Bob");
d35350c @gbarr *** empty log message ***
gbarr authored
184
d041411 @gbarr *** empty log message ***
gbarr authored
185 $r = $e->get_value('name', alloptions => 1, asref => 1);
ccae27f @gbarr Some testcase tweaks
gbarr authored
186 ok(($r and join("*", sort keys %$r) eq "*;en-us"), "name keys");
d35350c @gbarr *** empty log message ***
gbarr authored
187
ccae27f @gbarr Some testcase tweaks
gbarr authored
188 ok(($r and $r->{''} and @{$r->{''}} == 1 and $r->{''}[0] eq 'Graham Barr'), "name alloptions");
d35350c @gbarr *** empty log message ***
gbarr authored
189
ccae27f @gbarr Some testcase tweaks
gbarr authored
190 ok(($r and $r->{';en-us'} and @{$r->{';en-us'}} == 1 and $r->{';en-us'}[0] eq 'Bob'), "name alloptions Bob");
d35350c @gbarr *** empty log message ***
gbarr authored
191
Something went wrong with that request. Please try again.