perl-ldap
view release on metacpan or search on metacpan
t/73assert.t view on Meta::CPAN
#!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}}
( run in 1.604 second using v1.01-cache-2.11-cpan-5e09290becf )