Add grantSession test (#595)

This commit is contained in:
Xavier Guimard 2017-02-17 07:40:15 +00:00
parent 64970971a7
commit 97b8b40cc5
2 changed files with 62 additions and 2 deletions

View File

@ -110,7 +110,7 @@ sub refresh {
my %datas = %{ $req->userData };
$req->user( $datas{ $self->conf->{whatToTrace} } );
$req->id( $datas{_session_id} );
$self->userLogger->notice('Refresh request for '.$req->user);
$self->userLogger->notice( 'Refresh request for ' . $req->user );
foreach ( keys %datas ) {
delete $datas{$_} unless ( /^_/ or /^(?:startTime)$/ );
}
@ -158,7 +158,7 @@ sub do {
}
if ( !$self->conf->{noAjaxHook} and $req->wantJSON ) {
$self->logger->debug('Processing to JSON response');
if ( $err > 0 and !$req->id ) {
if ( ( $err > 0 and !$req->id ) or $err eq PE_SESSIONNOTGRANTED ) {
return [
401,
[

View File

@ -0,0 +1,60 @@
use Test::More;
use strict;
use IO::String;
BEGIN {
require 't/test-lib.pm';
}
my $res;
my $client = LLNG::Manager::Test->new(
{
ini => {
authentication => 'Demo',
userdb => 'Same',
grantSessionRule => {
no => '$uid ne "dwho"',
}
}
}
);
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
),
'Auth query'
);
count(1);
expectReject($res);
$client = LLNG::Manager::Test->new(
{
ini => {
authentication => 'Demo',
userdb => 'Same',
grantSessionRule => {
yes => '$uid eq "dwho"',
}
}
}
);
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
),
'auth query'
);
count(1);
expectOK($res);
expectCookie($res);
clean_sessions();
done_testing( count() );