#!/usr/bin/env perl
use warnings;
use strict;
=head1 DESCRIPTION
test LDAP server
=cut
use Jifty::Test tests => 18;
use Data::Dump qw/dump/;
use_ok('A3C::LDAP::Server');
my $port = 1024 + int(rand(1024));
diag "using port $port";
ok( my $pid = A3C::LDAP::Server->run({ port => $port, fork => 1 }), "run( port => $port )" );
diag "got pid: $pid";
#isa_ok( $pid, 'A3C::LDAP::Server' );
cmp_ok( $A3C::LDAP::Server::pids->{$port}, '==', $pid, 'pids' );
ok( my $ldap = Net::LDAP->new( "localhost:$port" ), 'connect to server' );
ok( my $c = Jifty->config->app('LDAP'), 'ldap config' );
ok( $ldap->bind( $c->{dn}, password => $c->{password} ), 'bind' );
ok( my $msg = $ldap->search(
base => $c->{base},
attrs => [
"uid",
"cn",
"hrEduPersonUniqueID",
"mail",
"sn",
"givenName",
"hrEduPersonUniqueNumber",
"hrEduPersonExpireDate",
"wtAdminType",
"hrEduPersonHomeOrg",
"uidNumber",
],
filter => bless {
equalityMatch => {
assertionValue => "dobrica.pavlinusic2\@os-test0802f1-zg.skole.hr",
attributeDesc => "hrEduPersonUniqueID",
},
}, 'Net::LDAP::Filter',
), 'search hrEduPersonUniqueID' );
ok( my @entries = $msg->entries, 'entries' );
is( scalar @entries, 1, 'got 1 entry' );
diag dump( @entries );
is_deeply( shift @entries, bless({
asn => {
attributes => [
{ type => "hrEduPersonUniqueNumber", vals => ["JMBG: 0000000000000"] },
{ type => "sn", vals => ["Pavlinu\xC5\xA1i\xC4\x87"] },
{ type => "hrEduPersonHomeOrg", vals => ["os-test0802f1-zg"] },
{ type => "cn", vals => ["Dobrica Pavlinu\xC5\xA1i\xC4\x87"] },
{ type => "hrEduPersonExpireDate", vals => [20100901] },
{ type => "uid", vals => ["dobrica.pavlinusic2"] },
{
type => "hrEduPersonUniqueID",
vals => ["dobrica.pavlinusic2\@os-test0802f1-zg.skole.hr"],
},
{ type => "wtAdminType", vals => ["AS"] },
{ type => "uidNumber", vals => [339069] },
{
type => "mail",
vals => [
"dobrica.pavlinusic2\@skole.hr",
"dobrica.pavlinusic2\@os-test0802f1-zg.skole.hr",
],
},
{ type => "givenName", vals => ["Dobrica"] },
],
objectName => "uid=dobrica.pavlinusic2,dc=os-test0802f1-zg,dc=skole,dc=hr",
},
changes => [],
changetype => "modify",
}, "Net::LDAP::Entry"),
'entry' );
ok( $msg = $ldap->search(
base => $c->{base},
attrs => [
"dn",
],
filter => bless {
equalityMatch => { assertionValue => "dobrica.pavlinusic2", attributeDesc => "uid" },
}, 'Net::LDAP::Filter',
), 'search uid' );
ok( @entries = $msg->entries, 'entries' );
is( scalar @entries, 1, 'got 1 entry' );
diag dump( @entries );
is_deeply( shift @entries,
bless({
asn => {
attributes => [],
objectName => "uid=dobrica.pavlinusic2,dc=os-test0802f1-zg,dc=skole,dc=hr",
},
changes => [],
changetype => "modify",
}, "Net::LDAP::Entry")
, 'entry' );
ok( $msg = $ldap->search(
base => $c->{base},
attrs => [
"dn",
],
filter => bless {
equalityMatch => { assertionValue => "non-existant", attributeDesc => "uid" },
}, 'Net::LDAP::Filter',
), 'search non-existant' );
cmp_ok( $msg->entries, '==', 0, 'no results' );
ok( A3C::LDAP::Server->stop, 'stop' );
ok( ! kill(9,$pid), "$pid gone" );