Append unit test (#2325)
This commit is contained in:
parent
fa363b0bb1
commit
ffa804f6a3
|
@ -31,7 +31,7 @@ Just enable it in the Manager (section ``General Parameters`` > ``Advanced param
|
|||
|
||||
Following variables are available in:
|
||||
|
||||
\* Warning email body => ``$newLocationIP``, ``$newLocationDate``
|
||||
\* Warning email body => ``$newLocationIP``, ``$newLocationDate``, ``$newLocationUrl``
|
||||
|
||||
.. |image0| image:: /documentation/beta.png
|
||||
:width: 100px
|
|
@ -672,6 +672,7 @@ t/61-CrowdSec-warn.t
|
|||
t/61-CrowdSec.t
|
||||
t/61-ForceAuthn.t
|
||||
t/61-GrantSession.t
|
||||
t/61-NewLocationWarning-Custom.t
|
||||
t/61-NewLocationWarning.t
|
||||
t/61-Session-ActivityTimeout.t
|
||||
t/61-Session-Timeout.t
|
||||
|
|
|
@ -59,6 +59,7 @@ sub _sendMail {
|
|||
my $date = strftime( '%F %X', localtime );
|
||||
my $ipSource = $req->env->{ipAddr};
|
||||
my $host = $req->env->{HTTP_HOST};
|
||||
my $url = $self->conf->{portal};
|
||||
my $mail =
|
||||
$req->sessionInfo->{ $self->conf->{newLocationWarningMailAttribute}
|
||||
|| 'mail' };
|
||||
|
@ -81,6 +82,7 @@ sub _sendMail {
|
|||
# Replace variables in body
|
||||
$body =~ s/\$newLocationIP/$ipSource/ge;
|
||||
$body =~ s/\$newLocationDate/$date/ge;
|
||||
$body =~ s/\$newLocationUrl/$url/ge;
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -97,13 +99,16 @@ sub _sendMail {
|
|||
);
|
||||
$html = 1;
|
||||
}
|
||||
if ( $mail && $subject && $body ) {
|
||||
$self->logger->warn("User $mail is signing in from a new location");
|
||||
|
||||
$self->logger->warn("User $mail is signing in from a new location");
|
||||
|
||||
# Send mail
|
||||
$self->logger->debug('Unable to send new location warning mail')
|
||||
unless ( $self->send_mail( $mail, $subject, $body, $html ) );
|
||||
|
||||
# Send mail
|
||||
$self->logger->debug('Unable to send new location warning mail')
|
||||
unless ( $self->send_mail( $mail, $subject, $body, $html ) );
|
||||
}
|
||||
else{
|
||||
$self->logger->error('Unable to send new location warning mail: missing parameter(s)');
|
||||
}
|
||||
return PE_OK;
|
||||
}
|
||||
|
||||
|
|
76
lemonldap-ng-portal/t/61-NewLocationWarning-Custom.t
Normal file
76
lemonldap-ng-portal/t/61-NewLocationWarning-Custom.t
Normal file
|
@ -0,0 +1,76 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use IO::String;
|
||||
|
||||
BEGIN {
|
||||
eval {
|
||||
require 't/test-lib.pm';
|
||||
require 't/smtp.pm';
|
||||
};
|
||||
}
|
||||
|
||||
my $res;
|
||||
my $maintests = 4;
|
||||
|
||||
SKIP: {
|
||||
eval 'require Email::Sender::Simple;';
|
||||
if ($@) {
|
||||
skip 'Missing dependencies', $maintests;
|
||||
}
|
||||
|
||||
my $client = LLNG::Manager::Test->new( {
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
useSafeJail => 1,
|
||||
authentication => 'Demo',
|
||||
userDB => 'Same',
|
||||
passwordDB => 'Demo',
|
||||
captcha_mail_enabled => 0,
|
||||
portalMainLogo => 'common/logos/logo_llng_old.png',
|
||||
newLocationWarning => 1,
|
||||
loginHistoryEnabled => 1,
|
||||
newLocationWarningMailSubject => 'Test new location mail',
|
||||
newLocationWarningMailBody =>
|
||||
'Test $newLocationIP $newLocationDate $newLocationUrl',
|
||||
#newLocationWarningMailAttribute => 'email'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
## Simple access
|
||||
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
|
||||
my ( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'user', 'password' );
|
||||
|
||||
## Authentication #1 with IP #1 (Test 1)
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'First auth query'
|
||||
);
|
||||
|
||||
## Authentication #1 with IP #2 (Test 2)
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
ip => '127.0.0.2',
|
||||
),
|
||||
'Second auth query'
|
||||
);
|
||||
like(
|
||||
mail(),
|
||||
qr#^Test 127\.0\.0\.2 \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} http://auth.example.com/$#,
|
||||
' Mail sent (IP, Date & URL found)'
|
||||
);
|
||||
}
|
||||
|
||||
count($maintests);
|
||||
clean_sessions();
|
||||
done_testing( count() );
|
Loading…
Reference in New Issue
Block a user