2020-02-25 16:50:50 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $res;
|
|
|
|
|
|
|
|
my $client = LLNG::Manager::Test->new( {
|
|
|
|
ini => {
|
2020-12-16 23:35:53 +01:00
|
|
|
logLevel => 'error',
|
2020-02-25 16:50:50 +01:00
|
|
|
authentication => 'Demo',
|
|
|
|
userDB => 'Same',
|
|
|
|
loginHistoryEnabled => 1,
|
|
|
|
bruteForceProtection => 1,
|
|
|
|
bruteForceProtectionIncrementalTempo => 1,
|
2020-08-28 14:44:03 +02:00
|
|
|
failedLoginNumber => 6,
|
2020-12-16 23:35:53 +01:00
|
|
|
bruteForceProtectionMaxLockTime => 600,
|
2020-12-17 22:40:28 +01:00
|
|
|
bruteForceProtectionLockTimes => '5 , 500, bad ,20, -10, 700',
|
|
|
|
bruteForceProtectionMaxFailed => 2,
|
2020-02-25 16:50:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
## First successful connection
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'1st Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
my $id = expectCookie($res);
|
|
|
|
expectRedirection( $res, 'http://auth.example.com/' );
|
|
|
|
$client->logout($id);
|
|
|
|
|
2020-08-28 10:41:40 +02:00
|
|
|
## First allowed failed login
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'1st allowed Bad Auth query'
|
|
|
|
);
|
2020-12-17 22:40:28 +01:00
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="5"><\/span>/, 'Bad credential' )
|
2020-08-28 10:41:40 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
|
|
|
|
## Second allowed failed login
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'2nd allowed Bad Auth query'
|
|
|
|
);
|
2020-12-17 22:40:28 +01:00
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="5"><\/span>/, 'Bad credential' )
|
2020-08-28 10:41:40 +02:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
|
2020-02-25 16:50:50 +01:00
|
|
|
## First failed connection
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'1st Bad Auth query'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="86"><\/span>/,
|
|
|
|
'Rejected -> Protection enabled' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-12-19 19:31:33 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%(\d) <span trspan="seconds">seconds</span>%,
|
|
|
|
"LockTime = $1" );
|
|
|
|
ok( $1 <= 5 && $1 >= 3, 'LockTime in range' )
|
2020-02-25 16:50:50 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-12-19 19:31:33 +01:00
|
|
|
count(4);
|
2020-02-25 16:50:50 +01:00
|
|
|
|
|
|
|
# Waiting
|
|
|
|
Time::Fake->offset("+4s");
|
|
|
|
|
|
|
|
## Try to connect
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="86"><\/span>/,
|
|
|
|
'Rejected -> Protection enabled' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-12-16 23:35:53 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%(\d) <span trspan="seconds">seconds</span>%,
|
2020-12-17 22:40:28 +01:00
|
|
|
"LockTime = $1" );
|
|
|
|
ok( $1 <= 6 && $1 >= 3, 'LockTime in range' )
|
2020-12-16 23:35:53 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(4);
|
|
|
|
|
|
|
|
# Waiting
|
|
|
|
Time::Fake->offset("+8s");
|
2020-02-25 16:50:50 +01:00
|
|
|
|
|
|
|
## Second failed connection
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
2020-12-16 23:35:53 +01:00
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
2020-02-25 16:50:50 +01:00
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
2020-12-16 23:35:53 +01:00
|
|
|
'Auth query'
|
2020-02-25 16:50:50 +01:00
|
|
|
);
|
2020-12-14 22:53:27 +01:00
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="86"><\/span>/,
|
|
|
|
'Rejected -> Protection enabled' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-12-16 23:35:53 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%(\d{2}) <span trspan="seconds">seconds</span>%,
|
2020-12-17 22:40:28 +01:00
|
|
|
"LockTime = $1" );
|
|
|
|
ok( $1 <= 18 && $1 >= 15, 'LockTime in range' )
|
2020-12-16 23:35:53 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(4);
|
2020-12-14 22:53:27 +01:00
|
|
|
|
|
|
|
# Waiting
|
2020-12-16 23:35:53 +01:00
|
|
|
Time::Fake->offset("+20s");
|
2020-12-14 22:53:27 +01:00
|
|
|
|
|
|
|
## Third failed connection
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'3rd Bad Auth query'
|
|
|
|
);
|
2020-02-25 16:50:50 +01:00
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="86"><\/span>/,
|
|
|
|
'Rejected -> Protection enabled' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-12-16 23:35:53 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%(\d{3}) <span trspan="seconds">seconds</span>%,
|
2020-12-17 22:40:28 +01:00
|
|
|
"LockTime = $1" );
|
|
|
|
ok( $1 <= 490 && $1 >= 480, 'LockTime in range' )
|
2020-12-16 23:35:53 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(4);
|
2020-02-25 16:50:50 +01:00
|
|
|
|
|
|
|
# Waiting
|
2020-12-16 23:35:53 +01:00
|
|
|
Time::Fake->offset("+510s");
|
|
|
|
|
2020-02-25 16:50:50 +01:00
|
|
|
## Try to connect
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
$id = expectCookie($res);
|
|
|
|
expectRedirection( $res, 'http://auth.example.com/' );
|
|
|
|
$client->logout($id);
|
|
|
|
|
2020-12-16 23:35:53 +01:00
|
|
|
# Waiting
|
|
|
|
Time::Fake->offset("+1000s");
|
|
|
|
|
|
|
|
## Allowed failed login
|
2020-02-25 16:50:50 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
2020-12-16 23:35:53 +01:00
|
|
|
'2nd allowed Bad Auth query'
|
2020-02-25 16:50:50 +01:00
|
|
|
);
|
2020-12-17 22:40:28 +01:00
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="5"><\/span>/, 'Bad credential' )
|
2020-02-25 16:50:50 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-12-16 23:35:53 +01:00
|
|
|
count(2);
|
2020-02-25 16:50:50 +01:00
|
|
|
|
|
|
|
## Forth failed connection
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=ohwd'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
2020-12-16 23:35:53 +01:00
|
|
|
'3rd Bad Auth query'
|
2020-02-25 16:50:50 +01:00
|
|
|
);
|
|
|
|
ok( $res->[2]->[0] =~ /<span trmsg="86"><\/span>/,
|
|
|
|
'Rejected -> Protection enabled' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-12-16 23:35:53 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%(\d{3}) <span trspan="seconds">seconds</span>%,
|
2020-12-17 22:40:28 +01:00
|
|
|
"LockTime = $1" );
|
|
|
|
ok( $1 <= 5000 && $1 >= 490, 'LockTime in range' )
|
2020-02-25 16:50:50 +01:00
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2020-12-16 23:35:53 +01:00
|
|
|
count(4);
|
2020-02-25 16:50:50 +01:00
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|