lemonldap-ng/lemonldap-ng-portal/t/28-AuthChoice.t

85 lines
2.3 KiB
Perl
Raw Normal View History

2016-07-07 22:55:27 +02:00
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
2017-01-15 23:04:35 +01:00
my $mainTests = 2;
2016-07-07 22:55:27 +02:00
eval { unlink 't/userdb.db' };
SKIP: {
eval { require DBI; require DBD::SQLite; };
if ($@) {
2016-12-23 11:02:21 +01:00
skip 'DBD::SQLite not found', $mainTests;
2016-07-07 22:55:27 +02:00
}
elsif ( !$ENV{LDAPSERVER} ) {
2016-12-23 11:02:21 +01:00
skip 'No LDAP server given', $mainTests;
2016-07-07 22:55:27 +02:00
}
my $dbh = DBI->connect("dbi:SQLite:dbname=t/userdb.db");
$dbh->do('CREATE TABLE users (user text,password text,name text)');
$dbh->do("INSERT INTO users VALUES ('dwho','dwho','Doctor who')");
2016-11-14 13:34:46 +01:00
my $client = LLNG::Manager::Test->new(
2016-07-07 22:55:27 +02:00
{
2016-11-14 13:34:46 +01:00
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Choice',
userDB => 'Same',
2016-07-07 22:55:27 +02:00
2016-11-14 13:34:46 +01:00
authChoiceParam => 'test',
authChoiceModules => {
ldap => 'LDAP;LDAP;LDAP',
sql => 'DBI;DBI;DBI',
},
2016-07-07 22:55:27 +02:00
2016-11-14 13:34:46 +01:00
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
2016-07-07 22:55:27 +02:00
2016-11-14 13:34:46 +01:00
LDAPFilter => $ENV{LDAPFILTER} || '(cn=$user)',
ldapServer => $ENV{LDAPSERVER},
ldapBase => $ENV{LDAPBASE},
managerDn => $ENV{MANAGERDN} || '',
managerPassword => $ENV{MANAGERPASSWORD} || '',
}
2016-07-07 22:55:27 +02:00
}
);
2017-01-15 23:04:35 +01:00
# Test LDAP and SQL
2016-07-07 22:55:27 +02:00
foreach my $postString (
'user='
. ( $ENV{LDAPACCOUNT} || 'dwho' )
. '&password='
. ( $ENV{LDAPPWD} || 'dwho' )
. '&test=ldap',
'user=dwho&password=dwho&test=sql'
)
{
# Try yo authenticate
# -------------------
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_post(
2016-07-07 22:55:27 +02:00
'/', IO::String->new($postString),
length => length($postString)
),
'Auth query'
);
2016-12-23 11:02:21 +01:00
expectOK($res);
my $id = expectCookie($res);
2016-11-14 13:34:46 +01:00
$client->logout($id);
2016-07-07 22:55:27 +02:00
}
clean_sessions();
}
2016-12-23 11:02:21 +01:00
count($mainTests);
2016-07-07 22:55:27 +02:00
eval { unlink 't/userdb.db' };
done_testing( count() );