File: 73assert.t

package info (click to toggle)
libnet-ldap-perl 1%3A0.6500%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,660 kB
  • ctags: 731
  • sloc: perl: 15,059; sh: 76; makefile: 5
file content (187 lines) | stat: -rw-r--r-- 6,076 bytes parent folder | download | duplicates (3)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!perl

use Test::More;

use Net::LDAP;
use Net::LDAP::Constant qw(LDAP_CONTROL_ASSERTION);
use Net::LDAP::Control::Assertion;

BEGIN { require "t/common.pl" }


my @tests;

{ # parse DATA into a list (= tests) of hashes (= test parameters) of lists (= parameter values)
  local $/ = '';
  while(my $para = <DATA> ) {
    my @lines = split(/\n/, $para);
    my %params;
    chomp(@lines);
    @lines = grep(!/^\s*(?:#.*?)?$/, @lines);
    map { push(@{$params{$1}}, $2) if (/^(\w+):\s*(.*)$/) } @lines;
    push(@tests, \%params)  if (%params);
  }
}

start_server()
? plan tests => 4 + 2 * scalar(@tests)
: plan skip_all => 'no server';


$ldap = client();
isa_ok($ldap, Net::LDAP, "client");

$rootdse = $ldap->root_dse;
isa_ok($rootdse, Net::LDAP::RootDSE, "root_dse");


SKIP: {
  skip("RootDSE does not offer Assertion control", 2 + 2 * scalar(@tests))
    unless($rootdse->supported_control(LDAP_CONTROL_ASSERTION));

  #$mesg = $ldap->start_tls;
  #ok(!$mesg->code, "start_tls: " . $mesg->code . ": " . $mesg->error);

  $mesg = $ldap->bind($MANAGERDN, password => $PASSWD);
  ok(!$mesg->code, "bind: " . $mesg->code . ": " . $mesg->error);

  ok(ldif_populate($ldap, "data/40-in.ldif"), "data/40-in.ldif");

  foreach my $test (@tests) {
    $control = Net::LDAP::Control::Assertion->new(assertion => $test->{assertion}->[0]);
    isa_ok($control, Net::LDAP::Control::Assertion, "control object");

    if ($test->{action}->[0] eq 'search') {
      $mesg = $ldap->search(base => $test->{dn}->[0],
		filter => $test->{filter} ? $test->{filter}->[0] : '(objectclass=*)',
		scope => $test->{scope} ? $test->{scope}->[0] : 'sub',
		control => $control);
      is($mesg->code, $test->{code}->[0] || 0,
		($test->{code}->[0] ? "search [expecting ".$test->{code}->[0]."]: " : "search: ") .
		$mesg->code . ": " . $mesg->error);
    }
    elsif ($test->{action}->[0] eq 'compare') {
      $mesg = $ldap->compare($test->{dn}->[0],
		attr => $test->{attr}->[0],
		value => $test->{value}->[0],
		control => $control);
      is($mesg->code, $test->{code}->[0] || 6,
		($test->{code}->[0] ? "compare [expecting ".$test->{code}->[0]."]: " : "search: ") .
		$mesg->code . ": " . $mesg->error);
    }
    elsif ($test->{action}->[0] eq 'modify') {
      $mesg = $ldap->modify($test->{dn}->[0],
		$test->{changetype}->[0] => {
			map { $_ => $test->{$_} } @{$test->{attrs}}
		},
		control => $control);
      is($mesg->code, $test->{code}->[0] || 0,
		($test->{code}->[0] ? "modify [expecting ".$test->{code}->[0]."]: " : "modify: ") .
		$mesg->code . ": " . $mesg->error);
    }
    elsif ($test->{action}->[0] eq 'moddn') {
      my %sup = $test->{newsuperior} ? ( newsuperior => $test->{newsuperior}->[0] ) : ();
      $mesg = $ldap->moddn($test->{dn}->[0],
		newrdn => $test->{newrdn}->[0],
		%sup,
		control => $control);
      is($mesg->code, $test->{code}->[0] || 0,
		($test->{code}->[0] ? "moddn [expecting ".$test->{code}->[0]."]: " : "moddn: ") .
		$mesg->code . ": " . $mesg->error);
    }
    elsif ($test->{action}->[0] eq 'delete') {
      $mesg = $ldap->delete($test->{dn}->[0],
		control => $control);
      is($mesg->code, $test->{code}->[0] || 0,
		($test->{code}->[0] ? "delete [expecting ".$test->{code}->[0]."]: " : "delete: ") .
		$mesg->code . ": " . $mesg->error);
    }
    else {
      ok(0, "illegal action");
      note("test: ", explain($test));
    }
  }
}

__DATA__

## each section below represents one test; logic similar to , structure similar to LDIF
# each tests needs at least the elements
# - assertion: the assertion filter to use
# - action:    the action on which the assertion is to be tested
# - dn:        (base-)DN to use in the operation
# - ...:       all other elements depend on the operation [see above]

# search (expect failing assertion)
action: search
dn: ou=People, o=University of Michigan, c=US
filter: (cn=Babs Jensen)
assertion: (title=Mythical Manager, Research Systems)
code: 122

# search
action: search
dn: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
filter: (cn=Babs Jensen)
assertion: (title=Mythical Manager, Research Systems)

# modify
action: modify
dn: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
assertion: (title=MegaMythical Manager, Research Systems)
changetype: replace
attrs: title
title: Uber-Mythical Manager, Research Systems
title: Hyper-Mythical Manager, Research Systems
code: 122

# modify
action: modify
dn: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
assertion: (title=Mythical Manager, Research Systems)
changetype: replace
attrs: title
title: Uber-Mythical Manager, Research Systems
title: Hyper-Mythical Manager, Research Systems

# compare (expect failing assertion)
action: compare
dn: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
filter: (cn=Babs Jensen)
assertion: (title=HyperMythical Manager, Research Systems)
attr: sn
value: Jensen
code: 122

# compare
action: compare
dn: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
filter: (cn=Babs Jensen)
assertion: (title=Hyper-Mythical Manager, Research Systems)
attr: sn
value: Jensen

# moddn
action: moddn
dn: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
newrdn: cn=Babs Jensen
assertion: (title=HyperMythical Manager, Research Systems)
code: 122

# moddn
action: moddn
dn: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
newrdn: cn=Babs Jensen
assertion: (title=Hyper-Mythical Manager, Research Systems)

# delete
action: delete
dn: cn=Babs Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
assertion: (title=HyperMythical Manager, Research Systems)
code: 122

# delete
action: delete
dn: cn=Babs Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
assertion: (title=Hyper-Mythical Manager, Research Systems)