lemonldap-ng/lemonldap-ng-portal/t/21-Auth-and-password-LDAP.t

52 lines
1.4 KiB
Perl
Raw Normal View History

2016-05-12 21:02:48 +02:00
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
SKIP: {
skip 'No LDAP server given', 3 unless ( $ENV{LDAPSERVER} );
2016-11-14 13:34:46 +01:00
my $client = LLNG::Manager::Test->new(
2016-05-12 21:02:48 +02:00
{
2016-11-14 13:34:46 +01:00
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'LDAP',
userDB => 'LDAP',
LDAPFilter => $ENV{LDAPFILTER} || '(cn=$user)',
ldapServer => $ENV{LDAPSERVER},
ldapBase => $ENV{LDAPBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
}
2016-05-12 21:02:48 +02:00
}
);
my $postString = 'user='
. ( $ENV{LDAPACCOUNT} || 'dwho' )
. '&password='
. ( $ENV{LDAPPWD} || 'dwho' );
# Try yo authenticate
# -------------------
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_post(
'/', IO::String->new($postString),
2016-05-30 22:20:50 +02:00
length => length($postString)
2016-05-12 21:02:48 +02:00
),
'Auth query'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
2016-11-14 13:34:46 +01:00
my $cookies = $client->getCookies($res);
2016-05-12 21:02:48 +02:00
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
2016-11-14 13:34:46 +01:00
$client->logout($id);
2016-05-12 21:02:48 +02:00
clean_sessions();
}
count(3);
done_testing( count() );