76-2F-Ext-with-GrantSession.t 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
use Test::More;
use strict;
use IO::String;
use Data::Dumper;

require 't/test-lib.pm';

use_ok('Lemonldap::NG::Common::FormEncode');
count(1);

my $client = LLNG::Manager::Test->new(
Clément OUDOT's avatar
Clément OUDOT committed
12 13
    {
        ini => {
14 15 16 17 18 19
            logLevel             => 'error',
            ext2fActivation      => 1,
            ext2FSendCommand     => 't/sendOTP.pl -uid $uid',
            ext2FValidateCommand => 't/vrfyOTP.pl -uid $uid -code $code',
            authentication       => 'Demo',
            userDB               => 'Same',
Clément OUDOT's avatar
Clément OUDOT committed
20
            grantSessionRules => { 'Dwho_notAllowed##Test' => '$uid ne "dwho"' }
21 22 23 24 25 26 27 28
        }
    }
);

my $res;

# Try to authenticate
# -------------------
Clément OUDOT's avatar
Clément OUDOT committed
29 30
ok(
    $res = $client->_post(
31 32 33 34 35 36 37 38 39
        '/',
        IO::String->new('user=dwho&password=dwho'),
        length => 23,
        accept => 'text/html',
    ),
    'Auth query'
);
count(1);

Clément OUDOT's avatar
Clément OUDOT committed
40 41
my ( $host, $url, $query ) =
  expectForm( $res, undef, '/ext2fcheck', 'token', 'code' );
42

Clément OUDOT's avatar
Clément OUDOT committed
43 44 45
ok(
    $res->[2]->[0] =~
qr%<input name="code" value="" class="form-control" id="extcode" trplaceholder="code">%,
46 47 48 49 50
    'Found EXTCODE input'
) or print STDERR Dumper( $res->[2]->[0] );
count(1);

$query =~ s/code=/code=123456/;
Clément OUDOT's avatar
Clément OUDOT committed
51 52
ok(
    $res = $client->_post(
53 54 55 56 57 58 59 60 61 62 63
        '/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' )
Clément OUDOT's avatar
Clément OUDOT committed
64
  or print STDERR Dumper( $res->[2]->[0] );
65 66 67
count(1);

ok( $res->[2]->[0] =~ qr%src="/static/common/js/info.(?:min\.)?js"></script>%,
Clément OUDOT's avatar
Clément OUDOT committed
68 69
    'Found INFO js' )
  or print STDERR Dumper( $res->[2]->[0] );
70 71 72 73 74 75
count(1);

clean_sessions();

done_testing( count() );