lemonldap-ng/lemonldap-ng-portal/t/61-GrantSession.t

169 lines
4.0 KiB
Perl
Raw Normal View History

2017-02-17 08:40:15 +01:00
use Test::More;
use strict;
use IO::String;
2018-10-02 20:29:43 +02:00
use Data::Dumper;
2017-02-17 08:40:15 +01:00
BEGIN {
require 't/test-lib.pm';
}
my $res;
2019-02-07 09:27:56 +01:00
my $client = LLNG::Manager::Test->new( {
2018-11-26 14:40:21 +01:00
ini => {
2018-10-07 11:40:26 +02:00
logLevel => 'error',
authentication => 'Demo',
userdb => 'Same',
portalMainLogo => 'common/logos/logo_llng_old.png',
2018-10-07 11:40:26 +02:00
grantSessionRules => {
'$uid . " not allowed"##rule1' => '$uid ne "dwho"',
2018-10-07 15:40:45 +02:00
'Rtyler_Allowed##rule3' => '$uid eq "rtyler"',
'##rule2' => '$uid ne "msmith"',
'##rule4' => '$uid ne "jdoe"',
'##bad_rule' => '$uid n "jdoe"',
2017-02-17 08:40:15 +01:00
}
}
}
);
2018-11-26 14:40:21 +01:00
ok(
$res = $client->_post(
2017-02-17 08:40:15 +01:00
'/',
IO::String->new('user=dwho&password=dwho'),
2018-10-02 20:29:43 +02:00
accept => 'text/html',
2017-02-17 08:40:15 +01:00
length => 23
),
'Auth query'
);
count(1);
ok( $res->[2]->[0] =~ /<h3 trspan="dwho not allowed">dwho not allowed<\/h3>/,
2018-11-26 14:40:21 +01:00
'dwho rejected with custom message and session data' )
or print STDERR Dumper( $res->[2]->[0] );
2018-10-02 20:29:43 +02:00
count(1);
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=ohwd'),
accept => 'text/html',
length => 23
),
'Auth query'
);
count(1);
2020-05-24 00:04:33 +02:00
ok(
$res->[2]->[0] =~ /<span trmsg="5">/,
'dwho rejected with PE_BADCREDENTIALS'
) or print STDERR Dumper( $res->[2]->[0] );
count(1);
ok( $res->[2]->[0] =~ m%<span trspan="connect">Connect</span>%,
'Found connect button' )
2019-02-05 23:12:17 +01:00
or print STDERR Dumper( $res->[2]->[0] );
2019-02-04 19:20:28 +01:00
count(1);
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
accept => 'text/html',
length => 23
),
'Auth query'
);
count(1);
ok( $res->[2]->[0] =~ /<h3 trspan="dwho not allowed">dwho not allowed<\/h3>/,
'dwho rejected with custom message and session data' )
or print STDERR Dumper( $res->[2]->[0] );
count(1);
2018-10-07 11:40:26 +02:00
ok( $res->[2]->[0] =~ qr%src="/static/common/js/info.(?:min\.)?js"></script>%,
2018-11-26 14:40:21 +01:00
'Found INFO js' )
or print STDERR Dumper( $res->[2]->[0] );
2018-10-02 20:40:55 +02:00
count(1);
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/logo_llng_old.png"%,
'Found custom Main Logo' )
2018-11-26 14:40:21 +01:00
or print STDERR Dumper( $res->[2]->[0] );
count(1);
2018-11-26 14:40:21 +01:00
ok(
$res = $client->_post(
2018-10-02 20:29:43 +02:00
'/',
IO::String->new('user=rtyler&password=rtyler'),
length => 27
),
'Auth query'
);
count(1);
expectOK($res);
expectCookie($res);
2018-11-26 14:40:21 +01:00
ok(
$res = $client->_post(
2018-10-02 20:29:43 +02:00
'/',
IO::String->new('user=msmith&password=msmith'),
2018-10-02 20:29:43 +02:00
accept => 'text/html',
length => 27
2018-10-02 20:29:43 +02:00
),
'Auth query'
);
count(1);
2018-11-26 14:40:21 +01:00
ok(
$res->[2]->[0] =~ /<span trmsg="41">/,
2018-10-07 11:40:26 +02:00
'rtyler rejected with PE_SESSIONNOTGRANTED'
) or print STDERR Dumper( $res->[2]->[0] );
2018-10-02 20:29:43 +02:00
count(1);
ok(
$res = $client->_post(
'/',
IO::String->new('user=jdoe&password=jdoe'),
accept => 'text/html',
length => 23
),
'Auth query'
);
count(1);
ok(
$res->[2]->[0] =~ /<span trmsg="5">/,
'rtyler rejected with PE_BADCREDENTIALS'
) or print STDERR Dumper( $res->[2]->[0] );
count(1);
ok( $res->[2]->[0] =~ m%<span trspan="connect">Connect</span>%,
'Found connect button' )
2019-02-05 23:12:17 +01:00
or print STDERR Dumper( $res->[2]->[0] );
2019-02-04 19:20:28 +01:00
count(1);
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/logo_llng_old.png"%,
'Found custom Main Logo' )
2018-11-26 14:40:21 +01:00
or print STDERR Dumper( $res->[2]->[0] );
count(1);
2017-02-17 08:40:15 +01:00
my $c = getCookies($res);
ok( not(%$c), 'No cookie' );
count(1);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
2019-02-07 09:27:56 +01:00
$client = LLNG::Manager::Test->new( {
2018-11-26 14:40:21 +01:00
ini => {
2018-10-01 15:20:41 +02:00
authentication => 'Demo',
userdb => 'Same',
2018-10-07 11:40:26 +02:00
grantSessionRules => { '' => '$uid eq "dwho"', }
2017-02-17 08:40:15 +01:00
}
}
);
2018-11-26 14:40:21 +01:00
ok(
$res = $client->_post(
2017-02-17 08:40:15 +01:00
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
),
'auth query'
);
count(1);
expectOK($res);
expectCookie($res);
clean_sessions();
done_testing( count() );