2018-09-28 23:04:03 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $res;
|
|
|
|
|
|
|
|
my $client = LLNG::Manager::Test->new(
|
2018-10-12 10:04:03 +02:00
|
|
|
{
|
|
|
|
ini => {
|
2018-09-28 23:04:03 +02:00
|
|
|
logLevel => 'error',
|
|
|
|
authentication => 'Demo',
|
|
|
|
userDB => 'Same',
|
|
|
|
loginHistoryEnabled => 1,
|
|
|
|
bruteForceProtection => 1,
|
|
|
|
bruteForceProtectionTempo => 5,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
## First successful connection
|
2018-10-12 10:04:03 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-09-28 23:04:03 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
my $id1 = expectCookie($res);
|
|
|
|
expectRedirection( $res, 'http://auth.example.com/' );
|
|
|
|
|
|
|
|
$client->logout($id1);
|
|
|
|
|
|
|
|
## Second successful connection
|
2018-10-12 10:04:03 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-09-28 23:04:03 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
$id1 = expectCookie($res);
|
|
|
|
expectRedirection( $res, 'http://auth.example.com/' );
|
|
|
|
|
|
|
|
$client->logout($id1);
|
|
|
|
|
|
|
|
## First failed connection
|
2018-10-12 10:04:03 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-09-28 23:04:03 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectReject($res);
|
|
|
|
|
|
|
|
## Second failed connection
|
2018-10-12 10:04:03 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-09-28 23:04:03 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectReject($res);
|
|
|
|
|
|
|
|
## Third failed connection -> rejected
|
2018-10-12 10:04:03 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-09-28 23:04:03 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="86"><\/span>/, 'Protection enabled' );
|
|
|
|
count(1);
|
|
|
|
sleep 1;
|
|
|
|
|
|
|
|
## Fourth failed connection -> Rejected
|
2018-10-12 10:04:03 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-09-28 23:04:03 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="86"><\/span>/, 'Protection enabled' );
|
|
|
|
count(1);
|
|
|
|
sleep 2;
|
|
|
|
|
|
|
|
## Third successful connection -> Rejected
|
2018-10-12 10:04:03 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-09-28 23:04:03 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="86"><\/span>/, 'Protection enabled' );
|
|
|
|
count(1);
|
|
|
|
sleep 3;
|
|
|
|
|
|
|
|
## Fourth successful connection -> Accepted
|
2018-10-12 10:04:03 +02:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2018-09-28 23:04:03 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho&checkLogins=1'),
|
|
|
|
length => 37,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
$id1 = expectCookie($res);
|
|
|
|
|
|
|
|
ok( $res->[2]->[0] =~ /trspan="lastLogins"/, 'History found' )
|
2018-10-12 10:04:03 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2018-09-28 23:04:03 +02:00
|
|
|
|
|
|
|
my @c = ( $res->[2]->[0] =~ /<td>127.0.0.1/gs );
|
|
|
|
my @cf = ( $res->[2]->[0] =~ /PE5<\/td>/gs );
|
|
|
|
|
|
|
|
# History with 5 entries
|
|
|
|
ok( @c == 7, ' -> Seven entries found' );
|
|
|
|
ok( @cf == 4, " -> Four 'failedLogin' entries found" );
|
|
|
|
count(3);
|
|
|
|
|
|
|
|
$client->logout($id1);
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|