Append unit tests (#1999)
This commit is contained in:
parent
193666d963
commit
6df09f85ad
|
@ -0,0 +1,138 @@
|
|||
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( {
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
authentication => 'Demo',
|
||||
userDB => 'Same',
|
||||
loginHistoryEnabled => 0,
|
||||
bruteForceProtection => 0,
|
||||
requireToken => 0,
|
||||
globalLogoutTimer => 0,
|
||||
globalLogoutRule => 1,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
## First successful connection for 'dwho'
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'1st "dwho" Auth query'
|
||||
);
|
||||
count(1);
|
||||
my $idd = expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
## Second successful connection for "dwho"
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'2nd "dwho" Auth query'
|
||||
);
|
||||
count(1);
|
||||
expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
## Third successful connection for 'dwho'
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'3rd "dwho" Auth query'
|
||||
);
|
||||
count(1);
|
||||
expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
## First successful connection for 'rtyler'
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=rtyler&password=rtyler'),
|
||||
length => 27,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'1st "rtyler" Auth query'
|
||||
);
|
||||
count(1);
|
||||
my $idr = expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
## 2nd successful connection for 'rtyler'
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=rtyler&password=rtyler'),
|
||||
length => 27,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'2nd "rtyler" Auth query'
|
||||
);
|
||||
count(1);
|
||||
expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
my $nbr = count_sessions();
|
||||
ok( $nbr == 5, "Five sessions found" )
|
||||
or explain("Number of session(s) found = $nbr");
|
||||
count(1);
|
||||
|
||||
## Logout request for 'rtyler'
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/',
|
||||
query => 'logout',
|
||||
cookie => "lemonldap=$idr",
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Logout request for "rtyler"'
|
||||
);
|
||||
ok( $res->[2]->[0] =~ m%<span trmsg="47"></span>%, 'Found PE_LOGOUT_OK' )
|
||||
or explain( $res->[2]->[0], "PE_LOGOUT_OK" );
|
||||
$nbr = count_sessions();
|
||||
ok( $nbr == 3, "Three sessions found" )
|
||||
or explain("Number of session(s) found = $nbr");
|
||||
count(3);
|
||||
|
||||
## Logout request for 'dwho'
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/',
|
||||
query => 'logout',
|
||||
cookie => "lemonldap=$idd"
|
||||
),
|
||||
'Logout request for "dwho"'
|
||||
);
|
||||
eval { $res = JSON::from_json( $res->[2]->[0] ) };
|
||||
ok( not($@), 'Content is JSON' )
|
||||
or explain( $res->[2]->[0], 'JSON content' );
|
||||
ok( $res->{error} == 47, 'PE_LOGOUT_OK' );
|
||||
$nbr = count_sessions();
|
||||
ok( $nbr == 0, "No session found" )
|
||||
or explain("Number of session(s) found = $nbr");
|
||||
count(4);
|
||||
|
||||
clean_sessions();
|
||||
|
||||
done_testing( count() );
|
|
@ -0,0 +1,229 @@
|
|||
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( {
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
authentication => 'Demo',
|
||||
userDB => 'Same',
|
||||
loginHistoryEnabled => 0,
|
||||
bruteForceProtection => 0,
|
||||
requireToken => 0,
|
||||
restSessionServer => 1,
|
||||
globalLogoutRule => '$uid eq "dwho"',
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
## First successful connection for 'dwho'
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'1st "dwho" Auth query'
|
||||
);
|
||||
count(1);
|
||||
my $idd = expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
## Second successful connection for "dwho"
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'2nd "dwho" Auth query'
|
||||
);
|
||||
count(1);
|
||||
expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
## Third successful connection for 'dwho'
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'3rd "dwho" Auth query'
|
||||
);
|
||||
count(1);
|
||||
expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
## First successful connection for 'rtyler'
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=rtyler&password=rtyler'),
|
||||
length => 27,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'1st "rtyler" Auth query'
|
||||
);
|
||||
count(1);
|
||||
my @idr;
|
||||
$idr[0] = expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
## 2nd successful connection for 'rtyler'
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new('user=rtyler&password=rtyler'),
|
||||
length => 27,
|
||||
accept => 'text/html',
|
||||
),
|
||||
'2nd "rtyler" Auth query'
|
||||
);
|
||||
count(1);
|
||||
$idr[1] = expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
my $nbr = count_sessions();
|
||||
ok( $nbr == 5, "Five sessions found" )
|
||||
or explain("Number of session(s) found = $nbr");
|
||||
count(1);
|
||||
|
||||
## Logout request for 'rtyler'
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/',
|
||||
query => 'logout',
|
||||
cookie => "lemonldap=$idr[0]",
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Logout request for "rtyler"'
|
||||
);
|
||||
count(1);
|
||||
|
||||
ok( $res->[2]->[0] =~ m%<span trmsg="47"></span>%, 'Found PE_LOGOUT_OK' )
|
||||
or explain( $res->[2]->[0], "PE_LOGOUT_OK" );
|
||||
count(1);
|
||||
$client->logout( $idr[1] );
|
||||
|
||||
$nbr = count_sessions();
|
||||
ok( $nbr == 3, "Three sessions found" )
|
||||
or explain("Number of session(s) found = $nbr");
|
||||
count(1);
|
||||
|
||||
## Logout request for 'dwho'
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/',
|
||||
query => 'logout',
|
||||
cookie => "lemonldap=$idd",
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Logout request for "dwho"'
|
||||
);
|
||||
count(1);
|
||||
|
||||
my ( $host, $url, $query ) =
|
||||
expectForm( $res, undef, '/globallogout?all=1', 'token' );
|
||||
ok( $res->[2]->[0] =~ m%<span trspan="globalLogout">%,
|
||||
'Found trspan="globalLogout"' )
|
||||
or explain( $res->[2]->[0], 'trspan="globalLogout"' );
|
||||
my @c = ( $res->[2]->[0] =~ m%<td scope="row">127.0.0.1</td>%gs );
|
||||
my @d = ( $res->[2]->[0] =~ m%<th scope="col"><span trspan="%gs );
|
||||
|
||||
## Three entries found
|
||||
ok( @c == 3, ' -> Three entries found' )
|
||||
or explain( $res->[2]->[0], "Number of session(s) found = " . scalar @c );
|
||||
ok( @d == 5, ' -> Five <th> found' )
|
||||
or explain( $res->[2]->[0], "Number of <th> found = " . scalar @d );
|
||||
count(3);
|
||||
|
||||
## GlobalLogout request for 'dwho'
|
||||
$query .= '&all=1';
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/globallogout',
|
||||
IO::String->new($query),
|
||||
cookie => "lemonldap=$idd",
|
||||
length => length($query),
|
||||
accept => 'text/html',
|
||||
),
|
||||
'POST /globallogout?all=1'
|
||||
);
|
||||
|
||||
$nbr = count_sessions();
|
||||
ok( $nbr == 0, "No session found" )
|
||||
or explain("Number of session(s) found = $nbr");
|
||||
count(2);
|
||||
|
||||
## Test GlobalLogout request
|
||||
# Try to auth: first request
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/', IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Post user/password 1'
|
||||
);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
$idd = expectCookie($res);
|
||||
|
||||
# Try to auth: second request
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/', IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Post user/password 2'
|
||||
);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
# Try to auth: third request
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/', IO::String->new('user=dwho&password=dwho'),
|
||||
length => 23,
|
||||
accept => 'text/html'
|
||||
),
|
||||
'Post user/password 3'
|
||||
);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
|
||||
my $nbr = count_sessions();
|
||||
ok( $nbr == 3, "Three sessions found" )
|
||||
or explain("Number of session(s) found = $nbr");
|
||||
count(4);
|
||||
|
||||
# GlobalLogout
|
||||
ok(
|
||||
$res = $client->_delete(
|
||||
'/sessions/my/global', cookie => "lemonldap=$idd",
|
||||
),
|
||||
'DELETE /sessions/my/global'
|
||||
);
|
||||
ok( $res = eval { JSON::from_json( $res->[2]->[0] ) }, ' GET JSON' )
|
||||
or print STDERR $@;
|
||||
ok( $res->{removedSessions} == 2, 'Two sessions removed' )
|
||||
or explain( $res, "removedSessions == $res->{removedSessions}" );
|
||||
ok( $res->{result} == 1, 'Found "Result == 1"' )
|
||||
or explain( $res, "result == $res->{result}" );
|
||||
$nbr = count_sessions();
|
||||
ok( $nbr == 1, "One remaining session found" )
|
||||
or explain("Number of session(s) found = $nbr");
|
||||
count(5);
|
||||
|
||||
clean_sessions();
|
||||
|
||||
done_testing( count() );
|
Loading…
Reference in New Issue