Add Choice test (#595)
This commit is contained in:
parent
ffac3fddbf
commit
37ad0047d8
|
@ -21,6 +21,11 @@ sub init {
|
||||||
my ( $self, $type ) = @_;
|
my ( $self, $type ) = @_;
|
||||||
$self->type($type);
|
$self->type($type);
|
||||||
|
|
||||||
|
unless( $self->conf->{authChoiceModules} and %{ $self->conf->{authChoiceModules} } ) {
|
||||||
|
$self->error("'authChoiceModules' is empty");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $name ( keys %{ $self->conf->{authChoiceModules} } ) {
|
foreach my $name ( keys %{ $self->conf->{authChoiceModules} } ) {
|
||||||
my @mods =
|
my @mods =
|
||||||
split( /[;\|]/, $self->conf->{authChoiceModules}->{$name} );
|
split( /[;\|]/, $self->conf->{authChoiceModules}->{$name} );
|
||||||
|
|
82
lemonldap-ng-portal/t/09-AuthChoice.t
Normal file
82
lemonldap-ng-portal/t/09-AuthChoice.t
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
use Test::More;
|
||||||
|
use strict;
|
||||||
|
use IO::String;
|
||||||
|
|
||||||
|
require 't/test-lib.pm';
|
||||||
|
|
||||||
|
my $res;
|
||||||
|
|
||||||
|
eval { unlink 't/userdb.db' };
|
||||||
|
|
||||||
|
SKIP: {
|
||||||
|
eval { require DBI; require DBD::SQLite; };
|
||||||
|
if ($@) {
|
||||||
|
skip 'DBD::SQLite not found', 3;
|
||||||
|
}
|
||||||
|
elsif ( !$ENV{LDAPSERVER} ) {
|
||||||
|
skip 'No LDAP server given', 3;
|
||||||
|
}
|
||||||
|
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')");
|
||||||
|
|
||||||
|
init(
|
||||||
|
{
|
||||||
|
logLevel => 'error',
|
||||||
|
useSafeJail => 1,
|
||||||
|
authentication => 'Choice',
|
||||||
|
userDB => 'Choice',
|
||||||
|
|
||||||
|
authChoiceParam => 'test',
|
||||||
|
authChoiceModules => {
|
||||||
|
ldap => 'LDAP;LDAP;LDAP',
|
||||||
|
sql => 'DBI;DBI;DBI',
|
||||||
|
},
|
||||||
|
|
||||||
|
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
|
||||||
|
dbiAuthUser => '',
|
||||||
|
dbiAuthPassword => '',
|
||||||
|
dbiAuthTable => 'users',
|
||||||
|
dbiAuthLoginCol => 'user',
|
||||||
|
dbiAuthPasswordCol => 'password',
|
||||||
|
dbiAuthPasswordHash => '',
|
||||||
|
|
||||||
|
LDAPFilter => $ENV{LDAPFILTER} || '(cn=$user)',
|
||||||
|
ldapServer => $ENV{LDAPSERVER},
|
||||||
|
ldapBase => $ENV{LDAPBASE},
|
||||||
|
managerDn => $ENV{MANAGERDN} || '',
|
||||||
|
managerPassword => $ENV{MANAGERPASSWORD} || '',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
foreach my $postString (
|
||||||
|
'user='
|
||||||
|
. ( $ENV{LDAPACCOUNT} || 'dwho' )
|
||||||
|
. '&password='
|
||||||
|
. ( $ENV{LDAPPWD} || 'dwho' )
|
||||||
|
. '&test=ldap',
|
||||||
|
'user=dwho&password=dwho&test=sql'
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
# Try yo authenticate
|
||||||
|
# -------------------
|
||||||
|
ok(
|
||||||
|
$res = &client->_post(
|
||||||
|
'/', IO::String->new($postString),
|
||||||
|
length => length($postString)
|
||||||
|
),
|
||||||
|
'Auth query'
|
||||||
|
);
|
||||||
|
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
|
||||||
|
my $cookies = getCookies($res);
|
||||||
|
my $id;
|
||||||
|
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
|
||||||
|
or explain( $res, 'Set-Cookie: something' );
|
||||||
|
logout($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_sessions();
|
||||||
|
}
|
||||||
|
count(3);
|
||||||
|
eval { unlink 't/userdb.db' };
|
||||||
|
done_testing( count() );
|
Loading…
Reference in New Issue
Block a user