Commit 8c409fc5 authored by Christophe Maudoux's avatar Christophe Maudoux

Fix error msg & Improve unit test (#1628)

parent 9fa7f58c
package Lemonldap::NG::Portal::Plugins::GrantSession;
use Data::Dumper;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(
PE_OK
PE_SESSIONNOTGRANTED
PE_BADCREDENTIALS
);
our $VERSION = '2.0.0';
......@@ -43,6 +45,9 @@ sub run {
return !$A ? 1 : !$B ? -1 : $A cmp $B;
}
# Avoid display notification if AuthResult not null
return PE_BADCREDENTIALS if $req->authResult > 0;
foreach ( sort sortByComment keys %{ $self->rules } ) {
$self->logger->debug( "Grant session condition -> "
. $self->conf->{grantSessionRules}->{$_} );
......
......@@ -7,7 +7,7 @@ package Lemonldap::NG::Portal::UserDB::Demo;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_USERNOTFOUND);
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_BADCREDENTIALS);
extends 'Lemonldap::NG::Common::Module';
......@@ -60,7 +60,7 @@ sub getUser {
}
eval { $self->p->_authentication->setSecurity($req) };
PE_USERNOTFOUND;
PE_BADCREDENTIALS;
}
## @apmethod int setSessionInfo()
......
......@@ -5,7 +5,7 @@ use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(
PE_ERROR
PE_OK
PE_USERNOTFOUND
PE_BADCREDENTIALS
);
extends 'Lemonldap::NG::Common::Module', 'Lemonldap::NG::Portal::Lib::REST';
......@@ -46,7 +46,7 @@ sub getUser {
}
unless ( $res->{result} ) {
$self->userLogger->warn( 'User ' . $req->user . ' not found' );
return PE_USERNOTFOUND;
return PE_BADCREDENTIALS;
}
$req->data->{restUserDBInfo} = $res->{info} || {};
return PE_OK;
......
......@@ -19,7 +19,8 @@ my $client = LLNG::Manager::Test->new(
grantSessionRules => {
'$uid . " not allowed"##rule1' => '$uid ne "dwho"',
'Rtyler_Allowed##rule3' => '$uid eq "rtyler"',
'##rule2' => '$uid ne "mrsmith"',
'##rule2' => '$uid ne "msmith"',
'##rule4' => '$uid ne "jdoe"',
}
}
}
......@@ -39,6 +40,38 @@ ok( $res->[2]->[0] =~ /<h3 trspan="dwho not allowed">dwho not allowed<\/h3>/,
'dwho rejected with custom message and session data' )
or print STDERR Dumper( $res->[2]->[0] );
count(1);
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=ohwd'),
accept => 'text/html',
length => 23
),
'Auth query'
);
count(1);
ok(
$res->[2]->[0] =~ /<span trmsg="5"><\/span><\/div>/,
'dwho rejected with PE_BADCREDENTIALS'
) or print STDERR Dumper( $res->[2]->[0] );
count(1);
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
accept => 'text/html',
length => 23
),
'Auth query'
);
count(1);
ok( $res->[2]->[0] =~ /<h3 trspan="dwho not allowed">dwho not allowed<\/h3>/,
'dwho rejected with custom message and session data' )
or print STDERR Dumper( $res->[2]->[0] );
count(1);
ok( $res->[2]->[0] =~ qr%src="/static/common/js/info.(?:min\.)?js"></script>%,
'Found INFO js' )
or print STDERR Dumper( $res->[2]->[0] );
......@@ -62,18 +95,35 @@ expectCookie($res);
ok(
$res = $client->_post(
'/',
IO::String->new('user=mrsmith&password=mrsmith'),
IO::String->new('user=msmith&password=msmith'),
accept => 'text/html',
length => 29
length => 27
),
'Auth query'
);
count(1);
ok(
$res->[2]->[0] =~ /<span trmsg="4"><\/span><\/div>/,
$res->[2]->[0] =~ /<span trmsg="41"><\/span><\/div>/,
'rtyler rejected with PE_SESSIONNOTGRANTED'
) or print STDERR Dumper( $res->[2]->[0] );
count(1);
ok(
$res = $client->_post(
'/',
IO::String->new('user=jdoe&password=jdoe'),
accept => 'text/html',
length => 23
),
'Auth query'
);
count(1);
ok(
$res->[2]->[0] =~ /<span trmsg="5"><\/span><\/div>/,
'rtyler rejected with PE_BADCREDENTIALS'
) or print STDERR Dumper( $res->[2]->[0] );
count(1);
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/logo_llng_old.png"%,
'Found custom Main Logo' )
or print STDERR Dumper( $res->[2]->[0] );
......
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