lemonldap-ng/lemonldap-ng-portal/t/76-2F-Ext-with-GrantSession.t

76 lines
1.8 KiB
Perl
Raw Normal View History

2018-10-06 23:10:48 +02:00
use Test::More;
use strict;
use IO::String;
use Data::Dumper;
require 't/test-lib.pm';
use_ok('Lemonldap::NG::Common::FormEncode');
count(1);
2019-02-07 09:27:56 +01:00
my $client = LLNG::Manager::Test->new( {
2018-10-12 10:04:03 +02:00
ini => {
2019-02-16 22:00:25 +01:00
logLevel => 'error',
2018-10-06 23:10:48 +02:00
ext2fActivation => 1,
2019-02-14 22:09:59 +01:00
ext2fCodeActivation => 0,
2018-10-06 23:10:48 +02:00
ext2FSendCommand => 't/sendOTP.pl -uid $uid',
ext2FValidateCommand => 't/vrfyOTP.pl -uid $uid -code $code',
authentication => 'Demo',
userDB => 'Same',
2018-10-12 10:04:03 +02:00
grantSessionRules => { 'Dwho_notAllowed##Test' => '$uid ne "dwho"' }
2018-10-06 23:10:48 +02:00
}
}
);
my $res;
# Try to authenticate
# -------------------
2018-10-12 10:04:03 +02:00
ok(
$res = $client->_post(
2018-10-06 23:10:48 +02:00
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23,
accept => 'text/html',
),
'Auth query'
);
count(1);
2018-10-12 10:04:03 +02:00
my ( $host, $url, $query ) =
expectForm( $res, undef, '/ext2fcheck?skin=bootstrap', 'token', 'code' );
2018-10-06 23:10:48 +02:00
2018-10-12 10:04:03 +02:00
ok(
$res->[2]->[0] =~
2021-08-20 17:20:58 +02:00
qr%<input name="code" value="" type="text" class="form-control" id="extcode" trplaceholder="code" autocomplete="one-time-code" />%,
2018-10-06 23:10:48 +02:00
'Found EXTCODE input'
) or print STDERR Dumper( $res->[2]->[0] );
count(1);
$query =~ s/code=/code=123456/;
2018-10-12 10:04:03 +02:00
ok(
$res = $client->_post(
2018-10-06 23:10:48 +02:00
'/ext2fcheck',
IO::String->new($query),
length => length($query),
accept => 'text/html',
),
'Post code'
);
count(1);
ok( $res->[2]->[0] =~ /<h3 trspan="Dwho_notAllowed">Dwho_notAllowed<\/h3>/,
'dwho rejected with custom message' )
2018-10-12 10:04:03 +02:00
or print STDERR Dumper( $res->[2]->[0] );
2018-10-06 23:10:48 +02:00
count(1);
ok( $res->[2]->[0] =~ qr%src="/static/common/js/info.(?:min\.)?js"></script>%,
2018-10-12 10:04:03 +02:00
'Found INFO js' )
or print STDERR Dumper( $res->[2]->[0] );
2018-10-06 23:10:48 +02:00
count(1);
clean_sessions();
done_testing( count() );