lemonldap-ng/lemonldap-ng-portal/t/36-Combination-with-over.t

99 lines
2.8 KiB
Perl
Raw Normal View History

use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
2018-02-08 21:55:21 +01:00
my $maintests = 0;
my $client;
2019-08-29 10:04:06 +02:00
my $userdb = tempdb();
SKIP: {
eval { require DBI; require DBD::SQLite; };
if ($@) {
2018-02-08 21:55:21 +01:00
skip 'DBD::SQLite not found', $maintests;
}
2019-08-29 10:04:06 +02:00
my $dbh = DBI->connect("dbi:SQLite:dbname=$userdb");
$dbh->do('CREATE TABLE users (user text,password text,name text)');
$dbh->do("INSERT INTO users VALUES ('dvador','dvador','Test user 1')");
$dbh->do("INSERT INTO users VALUES ('rtyler','rtyler','Test user 1')");
$client = iniCmb('[Dm] or [DB]');
2020-04-23 15:36:48 +02:00
$client->logout( expectCookie( try('dwho') ) );
$client->logout( expectCookie( try('dvador') ) );
}
2018-02-08 21:55:21 +01:00
count($maintests);
clean_sessions();
done_testing( count() );
sub try {
my $user = shift;
my $s = "user=$user&password=$user";
my $res;
ok(
$res = $client->_post(
'/', IO::String->new($s),
length => length($s),
custom => { HTTP_X => $user }
),
" Try to connect with login $user"
);
count(1);
return $res;
}
sub iniCmb {
my $expr = shift;
count(1);
if (
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Combination',
userDB => 'Same',
combination => $expr,
2017-02-06 13:36:27 +01:00
combModules => {
DB => {
for => 0,
type => 'DBI',
2017-02-06 13:36:27 +01:00
over => {
2020-02-20 23:34:02 +01:00
dbiAuthChain => "dbi:SQLite:dbname=$userdb",
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
2017-02-06 13:36:27 +01:00
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
dbiExportedVars => '{"user":"user"}',
2017-02-06 13:36:27 +01:00
}
},
2017-02-06 13:36:27 +01:00
Dm => {
for => 0,
type => 'Demo',
},
},
2017-02-06 13:36:27 +01:00
demoExportedVars => {},
}
}
)
)
{
pass(qq'Expression loaded: "$expr"');
ok(
$client->{p}->{loadedModules}->{'Lemonldap::NG::Portal::Auth::DBI'}
->{conf}->{dbiExportedVars}->{user} eq 'user',
'JSON is parsed'
);
count(1);
return $client;
}
else {
fail "Unable to build object";
}
}