Fix unit test (#2564) & some warnings

This commit is contained in:
Christophe Maudoux 2021-07-28 10:38:45 +02:00
parent 350f2e505e
commit 21ba445141
9 changed files with 33 additions and 20 deletions

View File

@ -639,6 +639,7 @@ sub oauth2Init {
sub substitute { sub substitute {
my ( $class, $expr ) = @_; my ( $class, $expr ) = @_;
$expr ||= '';
# substitute special vars, just for retro-compatibility # substitute special vars, just for retro-compatibility
$expr =~ s/\$date\b/&date/sg; $expr =~ s/\$date\b/&date/sg;

View File

@ -140,7 +140,7 @@ sub run {
# Try to recover cookie and user session # Try to recover cookie and user session
$id = $class->fetchId($req); $id = $class->fetchId($req);
$class->data( {} ) unless($id); $class->data( {} ) unless ($id);
if ( $id if ( $id
and $session = $class->retrieveSession( $req, $id ) ) and $session = $class->retrieveSession( $req, $id ) )
{ {
@ -321,7 +321,7 @@ sub getLevel {
$i++ $i++
) )
{ {
if ( $uri =~ $class->tsv->{locationRegexp}->{$vhost}->[$i] ) { if ( $uri && $uri =~ $class->tsv->{locationRegexp}->{$vhost}->[$i] ) {
$level = $class->tsv->{locationAuthnLevel}->{$vhost}->[$i]; $level = $class->tsv->{locationAuthnLevel}->{$vhost}->[$i];
last; last;
} }

View File

@ -45,7 +45,7 @@ ok( &$checkDate == "1",
my $sub4 = my $sub4 =
"sub { return(checkDate('20000101000000+0100','21000101000000+0100')) }"; "sub { return(checkDate('20000101000000+0100','21000101000000+0100')) }";
my $checkDate = $jail->jail_reval($sub4); $checkDate = $jail->jail_reval($sub4);
ok( &$checkDate == "1", ok( &$checkDate == "1",
'checkDate extended function working without Safe Jail' ); 'checkDate extended function working without Safe Jail' );

View File

@ -406,7 +406,9 @@ sub tests {
}, },
samlSignatureOverrideNeedsCertificate => sub { samlSignatureOverrideNeedsCertificate => sub {
return 1 if $conf->{samlServicePublicKeySig} =~ /CERTIFICATE/; return 1
if $conf->{samlServicePublicKeySig}
&& $conf->{samlServicePublicKeySig} =~ /CERTIFICATE/;
my @offenders; my @offenders;
for my $idp ( keys %{ $conf->{samlIDPMetaDataOptions} } ) { for my $idp ( keys %{ $conf->{samlIDPMetaDataOptions} } ) {
@ -693,7 +695,7 @@ sub tests {
abs $_; abs $_;
} }
grep { /\d+/ } grep { /\d+/ }
split /\s*,\s*/, $conf->{bruteForceProtectionLockTimes}; split /\s*,\s*/, $conf->{bruteForceProtectionLockTimes} || '';
$conf->{bruteForceProtectionLockTimes} = join ', ', @lockTimes $conf->{bruteForceProtectionLockTimes} = join ', ', @lockTimes
if scalar @lockTimes; if scalar @lockTimes;
return 1 unless ( $conf->{bruteForceProtection} ); return 1 unless ( $conf->{bruteForceProtection} );

View File

@ -576,14 +576,14 @@ sub updateSession {
if ($id) { if ($id) {
# Update sessionInfo data # 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 ## See https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues/430
$self->logger->debug("Update session $id"); $self->logger->debug("Update session $id");
foreach ( keys %$infos ) { foreach ( keys %$infos ) {
$self->logger->debug("Update sessionInfo $_"); $self->logger->debug("Update sessionInfo $_");
$self->_dump( $infos->{$_} ); $self->_dump( $infos->{$_} );
$req->{sessionInfo}->{$_} = $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->{$_}; $self->HANDLER->data->{$_} = $infos->{$_};
} }
} }

View File

@ -262,7 +262,7 @@ sub _register {
# Mail session expiration date # Mail session expiration date
my $expTimestamp = my $expTimestamp =
( $self->{conf}->{registerTimeout} || $self->conf->{timeout} ) + time; ( $self->conf->{registerTimeout} || $self->conf->{timeout} ) + time;
$self->logger->debug("Register expiration timestamp: $expTimestamp"); $self->logger->debug("Register expiration timestamp: $expTimestamp");

View File

@ -91,7 +91,7 @@ SKIP: {
), ),
'Query IdP to access to SP' 'Query IdP to access to SP'
); );
my ( $host, $url, $query ) = ( $host, $url, $query ) =
expectAutoPost( $res, 'auth.sp.com', '/saml/proxySingleSignOnPost', expectAutoPost( $res, 'auth.sp.com', '/saml/proxySingleSignOnPost',
'SAMLResponse' ); 'SAMLResponse' );

View File

@ -220,7 +220,7 @@ SKIP: {
), ),
'Test if still logged on PROXY' ); 'Test if still logged on PROXY' );
my ( $urlidp, $queryidp ) = ( $urlidp, $queryidp ) =
expectRedirection( $res, expectRedirection( $res,
qr#http://auth.idp.com(/saml/singleSignOn)\?(.*)$# ); qr#http://auth.idp.com(/saml/singleSignOn)\?(.*)$# );

View File

@ -9,7 +9,7 @@ BEGIN {
}; };
} }
my $maintests = 14; my $maintests = 16;
my ( $res, $user, $pwd, $mail, $subject, $email, $ipAddr ); my ( $res, $user, $pwd, $mail, $subject, $email, $ipAddr );
SKIP: { SKIP: {
@ -26,13 +26,16 @@ SKIP: {
authentication => 'Demo', authentication => 'Demo',
userDB => 'Same', userDB => 'Same',
registerDB => 'Demo', registerDB => 'Demo',
registerTimeout => '600',
registerConfirmSubject => 'Registration demonstration', registerConfirmSubject => 'Registration demonstration',
registerConfirmBody => 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', registerDoneSubject => 'Registration successful',
registerDoneBody => registerDoneBody =>
'Congratulations! Your account has been succesfully created with $mail from [$ipAddr]... '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, captcha_register_enabled => 0,
} }
} }
@ -67,12 +70,14 @@ Login=$login & Password=$password - Thanks to LemonLDAP::NG team.',
) or explain( $subject, 'Custom registration subject' ); ) or explain( $subject, 'Custom registration subject' );
ok( ok(
$mail =~ $mail =~
m#Hello Fôo Bà Bar, follows this link to register your account http://auth.example.com/register\?(.+?)&skin=bootstrap#, m#Hello Fôo Bà Bar, follows this link to register your account http://auth\.example\.com/register#s,
'Found register token' 'Found custom body'
) or explain( $mail, 'Custom body' ); ) or explain( $mail, 'Custom body (link)' );
ok( $mail =~ /[?&](register_token=.+)[$&]/, 'Found register_token' );
$query = $1; $query = $1;
ok( $query =~ /register_token=/, 'Found register_token' );
ok( $mail =~ /Fôo/, 'UTF-8 works' ) or explain( $mail, 'Fôo' ); 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( ok(
$res = $res =
@ -96,12 +101,17 @@ m#Congratulations! Your account has been succesfully created with (.+?) from \[(
or explain( $email, 'email' ); or explain( $email, 'email' );
ok( $ipAddr eq '127.0.0.1', 'Get good ipAddr' ) ok( $ipAddr eq '127.0.0.1', 'Get good ipAddr' )
or explain( $ipAddr, 'ipAddr' ); or explain( $ipAddr, 'ipAddr' );
ok( $mail =~ m#Login=(\w+?) & Password=(.+?)- Thanks to LemonLDAP::NG team\.#s, ok(
'Found user and password' ) $mail =~
or explain( $mail, 'Custom done body' ); m#Login=(\w+?) & Password=(.+?)- Thanks to LemonLDAP::NG team\.#s,
'Found user and password'
) or explain( $mail, 'Custom done body ($login & $password)' );
$user = $1; $user = $1;
$pwd = $2; $pwd = $2;
ok( $user eq 'fbabar', 'Get good login' ); 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( ok(
$res = $client->_post( $res = $client->_post(