Improve unit tests (#2275)

This commit is contained in:
Christophe Maudoux 2020-08-16 12:11:07 +02:00
parent 4ba29f10a7
commit 192861d639
5 changed files with 42 additions and 27 deletions

View File

@ -143,9 +143,9 @@ m#<img class="renewcaptchaclick" src="/static/common/icons/arrow_refresh.png" al
ok( $res = $client->_get( '/renewcaptcha', accept => 'text/html' ),
'Unauth request to renew Captcha' );
$json = eval { JSON::from_json( $res->[2]->[0] ) };
ok( ( defined $json->{newtoken} and $json->{newtoken} =~ /^\d{10}_\d+$/ ),
ok( ( defined $json->{newtoken} and $json->{newtoken} =~ /^\w+$/ ),
'New token has been received' )
or explain( $json->{newtoken}, 'NO token received' );
or explain( $json->{newtoken}, 'New token not received' );
ok( (
defined $json->{newimage}
and $json->{newimage} =~ m%^data:image/png;base64,.+%

View File

@ -22,6 +22,7 @@ my $client = LLNG::Manager::Test->new( {
securedCookie => 3,
restSessionServer => 1,
globalLogoutRule => 1,
tokenUseGlobalStorage => 1,
}
}
);
@ -117,9 +118,12 @@ ok(
ok( $res->[2]->[0] =~ m%<span trmsg="47"></span>%, 'Found PE_LOGOUT_OK' )
or explain( $res->[2]->[0], "PE_LOGOUT_OK" );
my $nbr = count_sessions();
ok( $nbr == 2, "Two sessions left" )
or explain("Number of session(s) found = $nbr\n");
count(3);
ok( $nbr == 2, "Two SSO sessions found" )
or explain( $nbr, "Two SSO sessions found" );
$nbr = count_sessions('TOKEN');
ok( $nbr == 1, "One TOKEN session found" )
or explain( $nbr, "One TOKEN session found" );
count(4);
clean_sessions();

View File

@ -201,7 +201,7 @@ ok( $res->[2]->[0] =~ m%<h3 trspan="otherSessions"></h3>%,
or explain( $res->[2]->[0], 'otherSessions found' );
ok(
$res->[2]->[0] =~
m%<a href="http://auth.example.com/removeOther\?token=\d{10}_\d+" onclick="_go=0" trspan="removeOtherSessions"></a>%,
m%<a href="http://auth.example.com/removeOther\?token=\w+?" onclick="_go=0" trspan="removeOtherSessions"></a>%,
'Link found'
) or explain( $res->[2]->[0], 'Link found' );
ok( $res->[2]->[0] =~ m%action="http://test1.example.com/"%, 'action found' )

View File

@ -18,6 +18,7 @@ SKIP: {
totp2fSelfRegistration => 1,
totp2fActivation => 1,
sfRequired => 1,
tokenUseGlobalStorage => 1,
}
}
);

View File

@ -153,13 +153,22 @@ sub clean_sessions {
}
sub count_sessions {
my $dir = shift;
$dir ||= $tmpDir;
my ( $kind, $dir ) = @_;
my $nbr = 0;
$kind ||= 'SSO';
$dir ||= $tmpDir;
opendir D, $dir or die $!;
foreach ( grep { /^\w{64}$/ } readdir(D) ) {
open( my $fh, '<', "$dir/$_" ) or die($!);
while (<$fh>) {
chomp;
if ( $_ =~ /"_session_kind":"$kind"/ ) {
$nbr++;
last;
}
}
close $fh;
}
$nbr;
}
@ -587,6 +596,7 @@ our $defaultIni = {
domain => 'example.com',
templateDir => 'site/templates',
staticPrefix => '/static',
tokenUseGlobalStorage => 0,
securedCookie => 0,
https => 0,
globalStorageOptions => {