From 21ba4451417a6b7a2deb0e5f4d1a938afd54c24b Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Wed, 28 Jul 2021 10:38:45 +0200 Subject: [PATCH] Fix unit test (#2564) & some warnings --- .../lib/Lemonldap/NG/Handler/Main/Reload.pm | 1 + .../lib/Lemonldap/NG/Handler/Main/Run.pm | 4 +-- .../t/13-Lemonldap-NG-Handler-Fake-Safe.t | 2 +- .../lib/Lemonldap/NG/Manager/Conf/Tests.pm | 6 ++-- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 4 +-- .../Lemonldap/NG/Portal/Plugins/Register.pm | 2 +- ...-Auth-and-issuer-SAML-POST-IdP-initiated.t | 2 +- .../t/37-Logout-from-2-chained-SAML-SP-SOAP.t | 2 +- .../t/42-Register-Demo-with-CustomBody.t | 30 ++++++++++++------- 9 files changed, 33 insertions(+), 20 deletions(-) diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm index cfb24ab58..00cea3128 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm @@ -639,6 +639,7 @@ sub oauth2Init { sub substitute { my ( $class, $expr ) = @_; + $expr ||= ''; # substitute special vars, just for retro-compatibility $expr =~ s/\$date\b/&date/sg; diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Run.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Run.pm index b424c6453..c0fba404c 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Run.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Run.pm @@ -140,7 +140,7 @@ sub run { # Try to recover cookie and user session $id = $class->fetchId($req); - $class->data( {} ) unless($id); + $class->data( {} ) unless ($id); if ( $id and $session = $class->retrieveSession( $req, $id ) ) { @@ -321,7 +321,7 @@ sub getLevel { $i++ ) { - if ( $uri =~ $class->tsv->{locationRegexp}->{$vhost}->[$i] ) { + if ( $uri && $uri =~ $class->tsv->{locationRegexp}->{$vhost}->[$i] ) { $level = $class->tsv->{locationAuthnLevel}->{$vhost}->[$i]; last; } diff --git a/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t b/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t index c2911f736..d3601b28b 100644 --- a/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t +++ b/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t @@ -45,7 +45,7 @@ ok( &$checkDate == "1", my $sub4 = "sub { return(checkDate('20000101000000+0100','21000101000000+0100')) }"; -my $checkDate = $jail->jail_reval($sub4); +$checkDate = $jail->jail_reval($sub4); ok( &$checkDate == "1", 'checkDate extended function working without Safe Jail' ); diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm index 1fc7b4698..f9e3e8dee 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm @@ -406,7 +406,9 @@ sub tests { }, samlSignatureOverrideNeedsCertificate => sub { - return 1 if $conf->{samlServicePublicKeySig} =~ /CERTIFICATE/; + return 1 + if $conf->{samlServicePublicKeySig} + && $conf->{samlServicePublicKeySig} =~ /CERTIFICATE/; my @offenders; for my $idp ( keys %{ $conf->{samlIDPMetaDataOptions} } ) { @@ -693,7 +695,7 @@ sub tests { abs $_; } grep { /\d+/ } - split /\s*,\s*/, $conf->{bruteForceProtectionLockTimes}; + split /\s*,\s*/, $conf->{bruteForceProtectionLockTimes} || ''; $conf->{bruteForceProtectionLockTimes} = join ', ', @lockTimes if scalar @lockTimes; return 1 unless ( $conf->{bruteForceProtection} ); 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 e4976e69e..86461764c 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -576,14 +576,14 @@ sub updateSession { if ($id) { # Update sessionInfo data - ## sessionInfo updated if $id defined : quite strange !! + ## sessionInfo updated if $id defined : quite strange!! ## See https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues/430 $self->logger->debug("Update session $id"); foreach ( keys %$infos ) { $self->logger->debug("Update sessionInfo $_"); $self->_dump( $infos->{$_} ); $req->{sessionInfo}->{$_} = $infos->{$_}; - if ( $id eq $self->HANDLER->data->{_session_id} ) { + if ( $self->HANDLER->data->{_session_id} && $id eq $self->HANDLER->data->{_session_id} ) { $self->HANDLER->data->{$_} = $infos->{$_}; } } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm index c1d956c6f..b77b83fce 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm @@ -262,7 +262,7 @@ sub _register { # Mail session expiration date my $expTimestamp = - ( $self->{conf}->{registerTimeout} || $self->conf->{timeout} ) + time; + ( $self->conf->{registerTimeout} || $self->conf->{timeout} ) + time; $self->logger->debug("Register expiration timestamp: $expTimestamp"); diff --git a/lemonldap-ng-portal/t/30-Auth-and-issuer-SAML-POST-IdP-initiated.t b/lemonldap-ng-portal/t/30-Auth-and-issuer-SAML-POST-IdP-initiated.t index 02c1730cd..b1d545193 100644 --- a/lemonldap-ng-portal/t/30-Auth-and-issuer-SAML-POST-IdP-initiated.t +++ b/lemonldap-ng-portal/t/30-Auth-and-issuer-SAML-POST-IdP-initiated.t @@ -91,7 +91,7 @@ SKIP: { ), 'Query IdP to access to SP' ); - my ( $host, $url, $query ) = + ( $host, $url, $query ) = expectAutoPost( $res, 'auth.sp.com', '/saml/proxySingleSignOnPost', 'SAMLResponse' ); diff --git a/lemonldap-ng-portal/t/37-Logout-from-2-chained-SAML-SP-SOAP.t b/lemonldap-ng-portal/t/37-Logout-from-2-chained-SAML-SP-SOAP.t index 86a503dcb..cc5427354 100644 --- a/lemonldap-ng-portal/t/37-Logout-from-2-chained-SAML-SP-SOAP.t +++ b/lemonldap-ng-portal/t/37-Logout-from-2-chained-SAML-SP-SOAP.t @@ -220,7 +220,7 @@ SKIP: { ), 'Test if still logged on PROXY' ); - my ( $urlidp, $queryidp ) = + ( $urlidp, $queryidp ) = expectRedirection( $res, qr#http://auth.idp.com(/saml/singleSignOn)\?(.*)$# ); diff --git a/lemonldap-ng-portal/t/42-Register-Demo-with-CustomBody.t b/lemonldap-ng-portal/t/42-Register-Demo-with-CustomBody.t index 475c4be46..a71d848dc 100644 --- a/lemonldap-ng-portal/t/42-Register-Demo-with-CustomBody.t +++ b/lemonldap-ng-portal/t/42-Register-Demo-with-CustomBody.t @@ -9,7 +9,7 @@ BEGIN { }; } -my $maintests = 14; +my $maintests = 16; my ( $res, $user, $pwd, $mail, $subject, $email, $ipAddr ); SKIP: { @@ -26,13 +26,16 @@ SKIP: { authentication => 'Demo', userDB => 'Same', registerDB => 'Demo', + registerTimeout => '600', registerConfirmSubject => 'Registration demonstration', registerConfirmBody => -'Hello $firstname $lastname, follows this link to register your account $url', +'Hello $firstname $lastname, follows this link to register your account $url +Expired time: $expMailDate $expMailTime', registerDoneSubject => 'Registration successful', registerDoneBody => 'Congratulations! Your account has been succesfully created with $mail from [$ipAddr]... -Login=$login & Password=$password - Thanks to LemonLDAP::NG team.', +Login=$login & Password=$password - Thanks to LemonLDAP::NG team. +Go to Portal $url', captcha_register_enabled => 0, } } @@ -67,12 +70,14 @@ Login=$login & Password=$password - Thanks to LemonLDAP::NG team.', ) or explain( $subject, 'Custom registration subject' ); ok( $mail =~ -m#Hello Fôo Bà Bar, follows this link to register your account http://auth.example.com/register\?(.+?)&skin=bootstrap#, - 'Found register token' - ) or explain( $mail, 'Custom body' ); +m#Hello Fôo Bà Bar, follows this link to register your account http://auth\.example\.com/register#s, + 'Found custom body' + ) or explain( $mail, 'Custom body (link)' ); + ok( $mail =~ /[?&](register_token=.+)[$&]/, 'Found register_token' ); $query = $1; - ok( $query =~ /register_token=/, 'Found register_token' ); ok( $mail =~ /Fôo/, 'UTF-8 works' ) or explain( $mail, 'Fôo' ); + ok( $mail =~ m#Expired time: \d{2}/\d{2}/\d{4} \d{2}:\d{2}#s, 'Found time' ) + or explain( $mail, 'Custom body (expired time)' ); ok( $res = @@ -96,12 +101,17 @@ m#Congratulations! Your account has been succesfully created with (.+?) from \[( or explain( $email, 'email' ); ok( $ipAddr eq '127.0.0.1', 'Get good ipAddr' ) or explain( $ipAddr, 'ipAddr' ); - ok( $mail =~ m#Login=(\w+?) & Password=(.+?)- Thanks to LemonLDAP::NG team\.#s, - 'Found user and password' ) - or explain( $mail, 'Custom done body' ); + ok( + $mail =~ + m#Login=(\w+?) & Password=(.+?)- Thanks to LemonLDAP::NG team\.#s, + 'Found user and password' + ) or explain( $mail, 'Custom done body ($login & $password)' ); $user = $1; $pwd = $2; ok( $user eq 'fbabar', 'Get good login' ); + ok( $mail =~ m#Go to Portal http://auth.example.com/\?skin=bootstrap#s, + 'Custom done body (Portal $url)' ) + or explain( $mail, 'Custom done body' ); ok( $res = $client->_post(