Skip to content
Newer
Older
100644 109 lines (81 sloc) 2.56 KB
b3b8f0c @gbarr Add a test for sort control
gbarr authored Jun 14, 2001
1 #!perl
2 #
3 # For this test to run you must defined the following in test.cfg
4 # $EXTERNAL_TESTS = 1
5 # %sortctrl with the following entries
6 # host => name of ldap server
7 # base => the base for the search
8 # filter => the filter for the search
9 # order => the attribute name to order by
10 #
11 # The attribute given must have unique values over the entries
12 # returned from the search. This is because this test checks
13 # that the order of entries returned by 'attr' is the exact
14 # opposite of '-attr' this is not guaranteed if two entries have
15 # the same value for attr.
16 #
17 # Obviously the filter should be specific enough to ensure that
18 # a relatively small set of entries is returned
19 #
20 # TODO:
21 #
22 # This test should be expanded to test sort controls with
23 # more than one attribute specified.
24
1196abd @gbarr Avoid Name "main::sortctrl" used only once warning
gbarr authored Sep 5, 2001
25 use vars qw(%sortctrl);
26
b3b8f0c @gbarr Add a test for sort control
gbarr authored Jun 14, 2001
27 BEGIN { require "t/common.pl" }
28
29 use Net::LDAP::LDIF;
30 use Net::LDAP::Control::Sort;
31 use Net::LDAP::Constant qw(
32 LDAP_CONTROL_SORTREQUEST
33 LDAP_CONTROL_SORTRESULT
34 LDAP_SUCCESS
35 );
36
1154865 @gbarr Say why we are skipping the test when we do
gbarr authored May 8, 2003
37 unless ($EXTERNAL_TESTS) {
38 print "1..0 # Skip External tests disabled\n";
39 exit 0;
40 }
41
b3b8f0c @gbarr Add a test for sort control
gbarr authored Jun 14, 2001
42 my($host, $base, $filter, $order) = @sortctrl{qw(host base filter order)};
43
1154865 @gbarr Say why we are skipping the test when we do
gbarr authored May 8, 2003
44 my $ldap = $host && Net::LDAP->new($host, version => 3);
45
46 unless ($ldap) {
47 print "1..0 # Skip Cannot connect to host\n";
48 exit 0;
49 }
50
b3b8f0c @gbarr Add a test for sort control
gbarr authored Jun 14, 2001
51 my $dse = $ldap && $ldap->root_dse;
52
53 unless ($dse and grep { $_ eq LDAP_CONTROL_SORTREQUEST } $dse->get_value('supportedControl')) {
1154865 @gbarr Say why we are skipping the test when we do
gbarr authored May 8, 2003
54 print "1..0 # Skip server does not support LDAP_CONTROL_SORTREQUEST\n";
b3b8f0c @gbarr Add a test for sort control
gbarr authored Jun 14, 2001
55 exit;
56 }
57
58 print "1..9\n";
59
60 Net::LDAP::LDIF->new(qw(- w))->write_entry($dse);
61
62 my $sort = Net::LDAP::Control::Sort->new(order => $order) or print "not ";
63 print "ok 1\n";
64
65 my $mesg = $ldap->search(
66 base => $base,
67 control => [$sort],
68 filter => $filter,
69 );
70
71 print "not " if $mesg->code;
72 print "ok 2\n";
73
74 my ($resp) = $mesg->control( LDAP_CONTROL_SORTRESULT ) or print "not ";
75 print "ok 3\n";
76
77 $resp && $resp->result == LDAP_SUCCESS or print "not ";
78 print "ok 4\n";
79
80 print "# ",$mesg->count,"\n";
81
82 my $dn1 = join ";", map { $_->dn } $mesg->entries;
83
84 $sort = Net::LDAP::Control::Sort->new(order => "-$order") or print "not ";
85 print "ok 5\n";
86
87 $mesg = $ldap->search(
88 base => $base,
89 control => [$sort],
90 filter => $filter,
91 );
92
93 print "not " if $mesg->code;
94 print "ok 6\n";
95
96 ($resp) = $mesg->control( LDAP_CONTROL_SORTRESULT ) or print "not ";
97 print "ok 7\n";
98
99 $resp && $resp->result == LDAP_SUCCESS or print "not ";
100 print "ok 8\n";
101
102 print "# ",$mesg->count,"\n";
103
104 my $dn2 = join ";", map { $_->dn } reverse $mesg->entries;
105
106 print "not " unless $dn1 eq $dn2;
107 print "ok 9\n";
108
Something went wrong with that request. Please try again.