Commit b7802255 authored by Xavier Guimard's avatar Xavier Guimard

More combination tests (#1151)

parent afcb39a3
......@@ -46,8 +46,8 @@ sub parse {
die('Bad combination: bad then or else');
}
return sub {
my ($req) = @_;
return ( $cond->($req) ? $then : $else->($req) );
my ($env) = @_;
return ( $cond->($env) ? $then : $else->($env) );
};
}
else {
......@@ -181,7 +181,7 @@ sub findB {
sub buildSub {
my ( $self, $cond ) = @_;
my $safe = Safe->new;
my $res = $safe->reval("sub{my(\$req)=@\_;return ($cond)}");
my $res = $safe->reval("sub{my(\$env)=@\_;return ($cond)}");
die "Bad condition $cond: $@" if ($@);
return $res;
}
......
......@@ -27,8 +27,8 @@ my @tests = (
'if(0) then [A,B] else [B,C]', 'B', 'C',
'if(0) then [A,B] else if(1) then [B,C] else [B,A]', 'B', 'C',
'if(0) then [A,B] else if(0) then [B,C] else [B,A]', 'B', 'A',
'if($req->{test}) then [A,B] else [B,C]', 'A', 'B',
'if($req->{false}) then [A,B] else [B,C]', 'B', 'C',
'if($env->{test}) then [A,B] else [B,C]', 'A', 'B',
'if($env->{false}) then [A,B] else [B,C]', 'B', 'C',
'[A,B] or [B,C]', 'A', 'B',
'if(1) then [A,B] or [C,A] else [B,C]', 'A', 'B',
);
......
......@@ -98,7 +98,7 @@ sub getDisplayType {
sub getStack {
my ( $self, $req, @steps ) = @_;
return $req->datas->{multiStack} if ( $req->datas->{multiStack} );
my $stack = $req->datas->{multiStack} = $self->stackSub->($req);
my $stack = $req->datas->{multiStack} = $self->stackSub->($req->env);
unless ($stack) {
$self->lmLog( 'No authentication scheme for this user', 'error' );
}
......@@ -113,7 +113,7 @@ sub try {
# If more than 1 scheme is available
my ( $res, $name );
if ( $nb < @$stack ) {
if ( $nb < @$stack - 1 ) {
# TODO: change logLevel for userLog()
( $res, $name ) = $stack->[$nb]->[$type]->( $subname, $req );
......@@ -128,7 +128,7 @@ sub try {
}
}
else {
( $res, $name ) = $stack->[$nb]->[$type]->$subname($req);
( $res, $name ) = $stack->[$nb]->[$type]->( $subname, $req );
}
$req->sessionInfo->{ [ '_auth', '_userDB' ]->[$type] } = $name;
return $res;
......
......@@ -129,7 +129,7 @@ sub do {
}
if ( !$self->conf->{noAjaxHook} and $req->wantJSON ) {
$self->lmLog( 'Processing to JSON response', 'debug' );
if ( $err > 0 and !%{ $req->sessionInfo } ) {
if ( $err > 0 and !$req->id ) {
return [
401,
[
......@@ -345,7 +345,7 @@ sub updatePersistentSession {
$uid ||= $req->{sessionInfo}->{ $self->conf->{whatToTrace} };
return () unless ($uid);
$self->lmLog("Update $uid persistent session", 'debug');
$self->lmLog( "Update $uid persistent session", 'debug' );
my $persistentSession = $self->getPersistentSession($uid);
......
......@@ -17,14 +17,27 @@ SKIP: {
}
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 ('test1','test1','Test user 1')");
$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]');
my $res = try('dwho');
expectCookie($res);
expectCookie( try('dwho') );
expectCookie( try('dvador') );
$res = try('test1');
expectCookie($res);
$client = iniCmb('[Dm] and [DB]');
expectCookie( try('rtyler') );
expectReject( try('dwho') );
$client = iniCmb('if($env->{HTTP_X} eq "dwho") then [Dm] else [DB]');
expectCookie( try('dwho') );
expectCookie( try('dvador') );
$client = iniCmb(
'if($env->{HTTP_X} eq "rtyler") then [Dm] and [DB] else if($env->{HTTP_X} eq "dvador") then [DB] else [DB]'
);
expectCookie( try('rtyler') );
expectCookie( try('dvador') );
expectReject( try('dwho') );
}
count($mainTests);
clean_sessions();
......@@ -36,8 +49,12 @@ sub try {
my $s = "user=$user&password=$user";
my $res;
ok(
$res = $client->_post( '/', IO::String->new($s), length => length($s) ),
"Test $user"
$res = $client->_post(
'/', IO::String->new($s),
length => length($s),
custom => { HTTP_X => $user }
),
" Try to connect with login $user"
);
count(1);
return $res;
......@@ -45,39 +62,45 @@ sub try {
sub iniCmb {
my $expr = shift;
my $res;
return LLNG::Manager::Test->new(
{
ini => {
logLevel => 'debug',
useSafeJail => 1,
authentication => 'Combination',
userDB => 'Same',
if (
my $res = LLNG::Manager::Test->new(
{
ini => {
logLevel => 'error',
useSafeJail => 1,
authentication => 'Combination',
userDB => 'Same',
combination => $expr,
combModules => [
{
for => 0,
name => 'DB',
type => 'DBI',
},
{
for => 0,
name => 'Dm',
type => 'Demo',
},
],
combination => $expr,
combModules => [
{
for => 0,
name => 'DB',
type => 'DBI',
},
{
for => 0,
name => 'Dm',
type => 'Demo',
},
],
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
dbiExportedVars => {},
demoExportedVars => {},
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
dbiExportedVars => {},
demoExportedVars => {},
}
}
}
);
)
)
{
pass(qq'Expression loaded: "$expr"');
count(1);
return $res;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment