Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

t/70sortctrl.t: add multi-attribute testcase

  • Loading branch information...
commit b65f50afdd86446b388562164a583e0ce285ff96 1 parent 5017a02
Peter Marschall marschap authored

Showing 1 changed file with 40 additions and 28 deletions. Show diff stats Hide diff stats

  1. +40 28 t/70sortctrl.t
68 t/70sortctrl.t
@@ -5,14 +5,6 @@
5 5 # that the order of entries returned by 'attr' is the exact
6 6 # opposite of '-attr' this is not guaranteed if two entries have
7 7 # the same value for attr.
8   -#
9   -# Obviously the filter should be specific enough to ensure that
10   -# a relatively small set of entries is returned
11   -#
12   -# TODO:
13   -#
14   -# This test should be expanded to test sort controls with
15   -# more than one attribute specified.
16 8
17 9 use Test::More;
18 10
@@ -27,8 +19,14 @@ use Net::LDAP::Constant qw(
27 19 );
28 20
29 21
  22 +# @testcases is a list of ($order => $reversed) tuples
  23 +my @testcases = (
  24 + [ 'cn:2.5.13.3' => '-cn:2.5.13.3' ] ,
  25 + [ 'sn:2.5.13.3 uid:2.5.13.3' => '-sn:2.5.13.3 -uid:2.5.13.3' ]
  26 +);
  27 +
30 28 start_server()
31   -? plan tests => 13
  29 +? plan tests => (4 + scalar(@testcases) * 9)
32 30 : plan skip_all => 'no server';
33 31
34 32
@@ -51,43 +49,57 @@ SKIP: {
51 49
52 50 ok(ldif_populate($ldap, "data/40-in.ldif"), "data/40-in.ldif");
53 51
54   - my $sort = Net::LDAP::Control::Sort->new(order => 'cn:2.5.13.3');
55   - isa_ok($sort, Net::LDAP::Control::Sort, 'sort control object');
  52 + foreach my $elem (@testcases) {
  53 + my ($ordered,$reversed) = @{$elem};
  54 + my @attrs = map { s/:.*$//; $_ } split(/\s+/, $ordered);
  55 + my $sort = Net::LDAP::Control::Sort->new(order => $ordered);
  56 + isa_ok($sort, Net::LDAP::Control::Sort, "sort control object");
56 57
57   - my $mesg = $ldap->search(
  58 + my $mesg = $ldap->search(
58 59 base => $BASEDN,
59 60 filter => '(objectclass=OpenLDAPperson)',
60 61 control => [ $sort ],
61 62 );
62   - is($mesg->code, LDAP_SUCCESS, "search: " . $mesg->code . ": " . $mesg->error);
  63 + is($mesg->code, LDAP_SUCCESS, "search: " . $mesg->code . ": " . $mesg->error);
63 64
64   - my ($resp) = $mesg->control( LDAP_CONTROL_SORTRESULT );
65   - ok($resp, 'LDAP_CONTROL_SORTRESULT response');
  65 + my ($resp) = $mesg->control( LDAP_CONTROL_SORTRESULT );
  66 + ok($resp, 'LDAP_CONTROL_SORTRESULT response');
66 67
67   - ok($resp && $resp->result == LDAP_SUCCESS , 'LDAP_CONTROL_SORTRESULT success');
  68 + ok($resp && $resp->result == LDAP_SUCCESS , 'LDAP_CONTROL_SORTRESULT success');
68 69
69   - #print "# ",$mesg->count,"\n";
  70 + #note $mesg->count;
  71 + if ($ENV{TEST_VERBOSE}) {
  72 + foreach my $e ($mesg->entries) {
  73 + note join(':', map { join(',',$e->get_value($_)) } @attrs);
  74 + }
  75 + }
70 76
71   - my $dn1 = join ";", map { $_->dn } $mesg->entries;
  77 + my $dn1 = join ";", map { $_->dn } $mesg->entries;
72 78
73   - $sort = Net::LDAP::Control::Sort->new(order => "-cn:2.5.13.3");
74   - isa_ok($sort, Net::LDAP::Control::Sort, 'sort control object (reverse order)');
  79 + $sort = Net::LDAP::Control::Sort->new(order => $reversed);
  80 + isa_ok($sort, Net::LDAP::Control::Sort, "sort control object (reversed)");
75 81
76   - $mesg = $ldap->search(
  82 + $mesg = $ldap->search(
77 83 base => $BASEDN,
78 84 filter => '(objectclass=OpenLDAPperson)',
79 85 control => [ $sort ],
80 86 );
81   - is($mesg->code, LDAP_SUCCESS, 'search result');
  87 + is($mesg->code, LDAP_SUCCESS, 'search result');
82 88
83   - ($resp) = $mesg->control( LDAP_CONTROL_SORTRESULT );
84   - ok($resp, 'LDAP_CONTROL_SORTRESULT response');
  89 + ($resp) = $mesg->control( LDAP_CONTROL_SORTRESULT );
  90 + ok($resp, 'LDAP_CONTROL_SORTRESULT response');
85 91
86   - ok($resp && $resp->result == LDAP_SUCCESS , 'LDAP_CONTROL_SORTRESULT success');
  92 + ok($resp && $resp->result == LDAP_SUCCESS , 'LDAP_CONTROL_SORTRESULT success');
87 93
88   - #print "# ",$mesg->count,"\n";
  94 + #note $mesg->count;
  95 + if ($ENV{TEST_VERBOSE}) {
  96 + foreach my $e (reverse $mesg->entries) {
  97 + note join(':', map { join(',',$e->get_value($_)) } @attrs);
  98 + }
  99 + }
89 100
90   - my $dn2 = join ";", map { $_->dn } reverse $mesg->entries;
  101 + my $dn2 = join ";", map { $_->dn } reverse $mesg->entries;
91 102
92   - is($dn1, $dn2, 'sort order');
  103 + is($dn1, $dn2, 'sort order');
  104 + }
93 105 }

0 comments on commit b65f50a

Please sign in to comment.
Something went wrong with that request. Please try again.