perl-ldap
view release on metacpan or search on metacpan
t/common.pl view on Meta::CPAN
and (!$arg{ssl} or $SSL_PORT)
and (!$arg{ipc} or $IPC_SOCK));
if ($CONF_IN and -f $CONF_IN) {
# Create slapd config file
open(CONFI, "<$CONF_IN") or die "$!";
open(CONFO, ">$CONF") or die "$!";
while(<CONFI>) {
# this will choke if a variable is not defined
s/\$([A-Z]\w*)/${$1}/g;
s/^TLS/#TLS/ unless $SSL_PORT;
s/^(sasl.*)/#$1/ unless $SASL;
s/^#module/module/ if $SLAPD_MODULE_DIR;
print CONFO;
}
close(CONFI);
close(CONFO);
}
rmtree($TESTDB) if ( -d $TESTDB );
mkdir($TESTDB, 0777);
die "$TESTDB is not a directory" unless -d $TESTDB;
note("@LDAPD") if $ENV{TEST_VERBOSE};
my $log = $TEMPDIR . "/" . basename($0,'.t');
unless ($pid = fork) {
die "fork: $!" unless defined $pid;
open(STDERR, ">$log");
open(STDOUT, ">&STDERR");
close(STDIN);
exec(@LDAPD) or die "cannot exec @LDAPD";
}
sleep 2; # wait for server to start
return 1;
}
sub kill_server {
if ($pid) {
kill 9, $pid;
sleep 2;
undef $pid;
}
}
END {
kill_server();
}
sub client {
my %arg = @_;
my $ldap;
my $count;
local $^W = 0;
my %opt = map { $_ => $arg{$_} } grep { exists($arg{$_}) } qw/inet4 inet6 debug/;
if ($arg{ssl}) {
require Net::LDAPS;
until($ldap = Net::LDAPS->new($HOST, %opt, port => $SSL_PORT, version => 3)) {
die "ldaps://$HOST:$SSL_PORT/ $@" if ++$count > 10;
sleep 1;
}
}
elsif ($arg{ipc}) {
require Net::LDAPI;
until($ldap = Net::LDAPI->new($IPC_SOCK)) {
die "ldapi://$IPC_SOCK/ $@" if ++$count > 10;
sleep 1;
}
}
elsif ($arg{url}) {
print "Trying $arg{url}\n";
until($ldap = Net::LDAP->new($arg{url}, %opt)) {
die "$arg{url} $@" if ++$count > 10;
sleep 1;
}
}
else {
until($ldap = Net::LDAP->new($HOST, %opt, port => $PORT, version => $LDAP_VERSION)) {
die "ldap://$HOST:$PORT/ $@" if ++$count > 10;
sleep 1;
}
}
$ldap;
}
sub compare_ldif {
my($test,$mesg) = splice(@_,0,2);
unless (ok(!$mesg->code, $mesg->error)) {
skip($mesg->error, 2);
return;
}
my $ldif = Net::LDAP::LDIF->new("$TEMPDIR/${test}-out.ldif","w", lowercase => 1);
unless (ok($ldif, "Read ${test}-out.ldif")) {
skip("Read error", 1);
return;
}
my @canon_opt = (casefold => 'lower', separator => ', ');
foreach $entry (@_) {
$entry->dn(canonical_dn($entry->dn, @canon_opt));
foreach $attr ($entry->attributes) {
$entry->delete($attr) if $attr =~ /^(modifiersname|modifytimestamp|creatorsname|createtimestamp)$/i;
if ($attr =~ /^(seealso|member|owner)$/i) {
$entry->replace($attr => [ map { canonical_dn($_, @canon_opt) } $entry->get_value($attr) ]);
}
}
$ldif->write($entry);
}
$ldif->done; # close the file;
ok(!compare_text("$TEMPDIR/${test}-out.ldif", "data/${test}-cmp.ldif"), "data/${test}-cmp.ldif");
( run in 3.232 seconds using v1.01-cache-2.11-cpan-98e64b0badf )