From 38157dabd508f682cadd23c048552315507dde89 Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Tue, 7 Sep 2021 09:16:08 +0200 Subject: [PATCH] unit test for hidden history fields (#2609) --- lemonldap-ng-portal/t/63-History.t | 16 +++++++++++- lemonldap-ng-portal/t/HistoryPlugin.pm | 3 ++- lemonldap-ng-portal/t/test-lib.pm | 35 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lemonldap-ng-portal/t/63-History.t b/lemonldap-ng-portal/t/63-History.t index 2cbbade84..febbec519 100644 --- a/lemonldap-ng-portal/t/63-History.t +++ b/lemonldap-ng-portal/t/63-History.t @@ -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,Language,, "Found plugin-set label" ); count(1); @@ -132,13 +132,27 @@ my @cf = ( $res->[2]->[0] =~ /PE5<\/td>/gs ); my @ccv1 = ( $res->[2]->[0] =~ /dwho<\/td>/gs ); my @ccv2 = ( $res->[2]->[0] =~ /Demo<\/td>/gs ); my @ccv3 = ( $res->[2]->[0] =~ /en<\/td>/gs ); +my @ccv4 = ( $res->[2]->[0] =~ /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(); diff --git a/lemonldap-ng-portal/t/HistoryPlugin.pm b/lemonldap-ng-portal/t/HistoryPlugin.pm index 389e9ff10..509ac6528 100644 --- a/lemonldap-ng-portal/t/HistoryPlugin.pm +++ b/lemonldap-ng-portal/t/HistoryPlugin.pm @@ -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; } diff --git a/lemonldap-ng-portal/t/test-lib.pm b/lemonldap-ng-portal/t/test-lib.pm index 2c6654123..917b6b2f9 100644 --- a/lemonldap-ng-portal/t/test-lib.pm +++ b/lemonldap-ng-portal/t/test-lib.pm @@ -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: