From 97b8b40cc5033fe14342ad913df707c45f21a056 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Fri, 17 Feb 2017 07:40:15 +0000 Subject: [PATCH] Add grantSession test (#595) --- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 4 +- lemonldap-ng-portal/t/61-grantSession.t | 60 +++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 lemonldap-ng-portal/t/61-grantSession.t diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index 602603984..1f30bdbd1 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -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, [ diff --git a/lemonldap-ng-portal/t/61-grantSession.t b/lemonldap-ng-portal/t/61-grantSession.t new file mode 100644 index 000000000..2872ba848 --- /dev/null +++ b/lemonldap-ng-portal/t/61-grantSession.t @@ -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() );