unit test for hidden history fields (#2609)

This commit is contained in:
Maxime Besson 2021-09-07 09:16:08 +02:00
parent 0b0bd5f183
commit 38157dabd5
3 changed files with 52 additions and 2 deletions

View File

@ -122,7 +122,7 @@ ok( $res->[2]->[0] =~ /trspan="lastLoginsCaptionLabel"/,
ok( $res->[2]->[0] =~ /trspan="lastFailedLoginsCaptionLabel"/,
'Failed history array caption found' )
or explain( $res->[2]->[0] );
count(2);
count(3);
like( $res->[2]->[0], qr,<th>Language</th>,, "Found plugin-set label" );
count(1);
@ -132,13 +132,27 @@ my @cf = ( $res->[2]->[0] =~ /PE5<\/td>/gs );
my @ccv1 = ( $res->[2]->[0] =~ /<td>dwho<\/td>/gs );
my @ccv2 = ( $res->[2]->[0] =~ /<td>Demo<\/td>/gs );
my @ccv3 = ( $res->[2]->[0] =~ /<td>en<\/td>/gs );
my @ccv4 = ( $res->[2]->[0] =~ /<td>1<\/td>/gs );
# History with 5 entries and 10 custom values
ok( @c == 5, ' -> Five entries found' );
ok( @cf == 2, " -> Two 'failedLogin' entries found" );
is( @ccv1 + @ccv2 + @ccv3, 15, "Custom value entries found" );
is( @ccv4, 0, "Hidden history field is missing" );
count(4);
# Check psession content
my $psession = getPSession('dwho');
is( $psession->{data}->{_loginHistory}->{successLogin}->[0]->{_language},
'en', "Field found in psession" );
is(
$psession->{data}->{_loginHistory}->{successLogin}->[0]
->{authenticationLevel},
'1', "Hidden field found in psession"
);
count(2);
$client->logout($id1);
clean_sessions();

View File

@ -5,7 +5,8 @@ extends 'Lemonldap::NG::Portal::Main::Plugin';
sub init {
my ($self) = @_;
$self->addSessionDataToRemember( { "_language" => "Language" } );
$self->addSessionDataToRemember(
{ "_language" => "Language", "authenticationLevel" => "__hidden__" } );
return 1;
}

View File

@ -61,6 +61,7 @@ use Time::Fake;
use URI::Escape;
use MIME::Base64;
use Lemonldap::NG::Common::FormEncode;
use Lemonldap::NG::Common::Util qw/getPSessionID/;
#use 5.10.0;
@ -184,6 +185,40 @@ sub getCache {
);
}
sub getSession {
my $id = shift;
my @sessionsOpts = (
storageModule => "Apache::Session::File",
storageModuleOptions => {
Directory => "$tmpDir",
LockDirectory => "$tmpDir/lock",
},
kind => 'SSO'
);
return Lemonldap::NG::Common::Session->new( {
@sessionsOpts, id => $id,
}
);
}
sub getPSession {
my $uid = shift;
my @sessionsOpts = (
storageModule => "Apache::Session::File",
storageModuleOptions => {
Directory => "$tmpDir",
LockDirectory => "$tmpDir/lock",
},
kind => 'Persistent'
);
return Lemonldap::NG::Common::Session->new( {
@sessionsOpts, id => getPSessionID($uid),
}
);
}
=head4 expectRedirection( $res, $location )
Verify that request result is a redirection to $location. $location can be: