From a084ba3c84332d4cd4e787c804227f5e1dc57b60 Mon Sep 17 00:00:00 2001 From: Christophe Maudoux Date: Sat, 2 Feb 2019 22:23:56 +0100 Subject: [PATCH] Improve unit tests (#1605) --- .../t/42-Register-Demo-with-captcha.t | 9 +++-- .../t/42-Register-Demo-with-token.t | 8 ++++- .../t/43-MailPasswordReset-with-captcha.t | 30 ++++++++-------- .../t/43-MailPasswordReset-with-token.t | 34 ++++++++++--------- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/lemonldap-ng-portal/t/42-Register-Demo-with-captcha.t b/lemonldap-ng-portal/t/42-Register-Demo-with-captcha.t index 257852fb1..662d9a703 100644 --- a/lemonldap-ng-portal/t/42-Register-Demo-with-captcha.t +++ b/lemonldap-ng-portal/t/42-Register-Demo-with-captcha.t @@ -9,7 +9,7 @@ BEGIN { }; } -my $maintests = 24; +my $maintests = 26; my ( $res, $user, $pwd, $host, $url, $query ); my $mailSend = 0; @@ -79,6 +79,12 @@ SKIP: { # Test normal first access # ------------------------ + ok( $res = $client->_get( '/', accept => 'text/html' ), + 'Get Menu', ); + ok( $res->[2]->[0] + =~ m%%, + 'Found Register link & submit button' + ) or print STDERR Dumper( $res->[2]->[0] ); ok( $res = $client->_get( '/register', accept => 'text/html' ), 'Unauth request', ); @@ -103,7 +109,6 @@ SKIP: { =~ m%[2]->[0] ); - $query .= "&captcha=$captcha"; ok( $res = $client->_post( diff --git a/lemonldap-ng-portal/t/42-Register-Demo-with-token.t b/lemonldap-ng-portal/t/42-Register-Demo-with-token.t index ece3746a0..45aa43887 100644 --- a/lemonldap-ng-portal/t/42-Register-Demo-with-token.t +++ b/lemonldap-ng-portal/t/42-Register-Demo-with-token.t @@ -9,7 +9,7 @@ BEGIN { }; } -my $maintests = 10; +my $maintests = 12; my ( $res, $user, $pwd ); SKIP: { @@ -33,6 +33,12 @@ SKIP: { # Test normal first access # ------------------------ + ok( $res = $client->_get( '/', accept => 'text/html' ), + 'Get Menu', ); + ok( $res->[2]->[0] + =~ m%%, + 'Found Register link & submit button' + ) or print STDERR Dumper( $res->[2]->[0] ); ok( $res = $client->_get( '/register', accept => 'text/html' ), 'Unauth request', diff --git a/lemonldap-ng-portal/t/43-MailPasswordReset-with-captcha.t b/lemonldap-ng-portal/t/43-MailPasswordReset-with-captcha.t index dc0379d56..891de88f4 100644 --- a/lemonldap-ng-portal/t/43-MailPasswordReset-with-captcha.t +++ b/lemonldap-ng-portal/t/43-MailPasswordReset-with-captcha.t @@ -10,20 +10,19 @@ BEGIN { } my ( $res, $host, $url, $query ); -my $maintests = 12; +my $maintests = 14; my $mailSend = 0; my $mail2 = 0; SKIP: { eval - 'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;'; + 'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;'; if ($@) { skip 'Missing dependencies', $maintests; } my $client = LLNG::Manager::Test->new( - { - ini => { + { ini => { logLevel => 'error', useSafeJail => 1, portalDisplayRegister => 1, @@ -33,13 +32,19 @@ SKIP: { captcha_mail_enabled => 1, requireToken => 1, portalDisplayResetPassword => 1, - portalMainLogo => 'common/logos/logo_llng_old.png', + portalMainLogo => 'common/logos/logo_llng_old.png', } } ); # Test form # ------------------------ + ok( $res = $client->_get( '/', accept => 'text/html' ), + 'Get Menu', ); + ok( $res->[2]->[0] + =~ m%%, + 'Found ResetPassword link & submit button' + ) or print STDERR Dumper( $res->[2]->[0] ); ok( $res = $client->_get( '/resetpwd', accept => 'text/html' ), 'Reset form', ); ( $host, $url, $query ) = expectForm( $res, '#', undef, 'mail', 'token' ); @@ -58,16 +63,15 @@ SKIP: { ok( $ts = getCache()->get($token), ' Found token session' ); $ts = eval { JSON::from_json($ts) }; ok( $captcha = $ts->{captcha}, ' Found captcha value' ); - ok( - $res->[2]->[0] =~ m%[2]->[0] + =~ m%[2]->[0] ); $query .= "&captcha=$captcha"; # Post email - ok( - $res = $client->_post( + ok( $res = $client->_post( '/resetpwd', IO::String->new($query), length => length($query), accept => 'text/html' @@ -76,14 +80,13 @@ SKIP: { ); ok( mail() =~ m%Content-Type: image/png; name="logo_llng_old.png"%, 'Found custom Main logo in mail' ) - or print STDERR Dumper( mail() ); + or print STDERR Dumper( mail() ); ok( mail() =~ m#a href="http://auth.example.com/resetpwd\?(.*?)"#, 'Found link in mail' ); $query = $1; - ok( - $res = $client->_get( + ok( $res = $client->_get( '/resetpwd', query => $query, accept => 'text/html' @@ -96,8 +99,7 @@ SKIP: { $query .= '&newpassword=zz&confirmpassword=zz'; # Post new password - ok( - $res = $client->_post( + ok( $res = $client->_post( '/resetpwd', IO::String->new($query), length => length($query), accept => 'text/html' diff --git a/lemonldap-ng-portal/t/43-MailPasswordReset-with-token.t b/lemonldap-ng-portal/t/43-MailPasswordReset-with-token.t index 871e1c19f..a3c169d8a 100644 --- a/lemonldap-ng-portal/t/43-MailPasswordReset-with-token.t +++ b/lemonldap-ng-portal/t/43-MailPasswordReset-with-token.t @@ -10,21 +10,20 @@ BEGIN { } my ( $res, $user, $pwd ); -my $maintests = 9; +my $maintests = 11; my $mailSend = 0; my $mail2 = 0; SKIP: { eval - 'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;'; + 'require Email::Sender::Simple;use GD::SecurityImage;use Image::Magick;'; if ($@) { skip 'Missing dependencies', $maintests; } my $client = LLNG::Manager::Test->new( - { - ini => { + { ini => { logLevel => 'error', useSafeJail => 1, portalDisplayRegister => 1, @@ -34,43 +33,47 @@ SKIP: { captcha_mail_enabled => 0, requireToken => 1, portalDisplayResetPassword => 1, - portalMainLogo => 'common/logos/logo_llng_old.png', + portalMainLogo => 'common/logos/logo_llng_old.png', } } ); # Test form # ------------------------ + ok( $res = $client->_get( '/', accept => 'text/html' ), + 'Get Menu', ); + ok( $res->[2]->[0] + =~ m%%, + 'Found ResetPassword link & submit button' + ) or print STDERR Dumper( $res->[2]->[0] ); ok( $res = $client->_get( '/resetpwd', accept => 'text/html' ), 'Reset form', ); - my ( $host, $url, $query ) = - expectForm( $res, '#', undef, 'mail', 'token' ); + my ( $host, $url, $query ) + = expectForm( $res, '#', undef, 'mail', 'token' ); $query =~ s/mail=&//; $query .= '&mail=dwho%40badwolf.org'; # Post email - ok( - $res = $client->_post( + ok( $res = $client->_post( '/resetpwd', IO::String->new($query), length => length($query), accept => 'text/html' ), 'Post mail' ); - ok( - $res->[2]->[0] =~ m%[2]->[0] + =~ m%[2]->[0] ); ok( mail() =~ m%Content-Type: image/png; name="logo_llng_old.png"%, 'Found custom Main logo in mail' ) - or print STDERR Dumper( mail() ); + or print STDERR Dumper( mail() ); ok( mail() =~ m#a href="http://auth.example.com/resetpwd\?(.*?)"#, 'Found link in mail' ); $query = $1; - ok( - $res = $client->_get( + ok( $res = $client->_get( '/resetpwd', query => $query, accept => 'text/html' @@ -83,8 +86,7 @@ SKIP: { $query .= '&newpassword=zz&confirmpassword=zz'; # Post new password - ok( - $res = $client->_post( + ok( $res = $client->_post( '/resetpwd', IO::String->new($query), length => length($query), accept => 'text/html'