76-2F-Ext-with-HISTORY.t 2.81 KB
Newer Older
1 2 3 4 5 6
use Test::More;
use strict;
use IO::String;
use Data::Dumper;

require 't/test-lib.pm';
Christophe Maudoux's avatar
Christophe Maudoux committed
7
my $maintests = 10;
8 9

use_ok('Lemonldap::NG::Common::FormEncode');
10 11 12 13 14

my $client = LLNG::Manager::Test->new(
    {
        ini => {
            logLevel             => 'error',
Christophe Maudoux's avatar
Christophe Maudoux committed
15 16 17 18 19 20
            rest2fActivation     => 1,
            rest2fInitUrl        => 'http://auth.example.com/init',
            rest2fInitArgs       => { name => 'uid' },
            rest2fVerifyUrl      => 'http://auth.example.com/vrfy',
            rest2fVerifyArgs     => { code => 'code' },
            rest2fLogo           => 'u2f.png',
Christophe Maudoux's avatar
Christophe Maudoux committed
21
            totp2fActivation     => '$uid eq "dwho"',
22 23 24
            ext2fActivation      => 1,
            ext2FSendCommand     => 't/sendOTP.pl -uid $uid',
            ext2FValidateCommand => 't/vrfyOTP.pl -uid $uid -code $code',
Christophe Maudoux's avatar
Christophe Maudoux committed
25
            ext2fLogo            => 'yubikey.png',
26 27 28
            loginHistoryEnabled  => 1,
            authentication       => 'Demo',
            userDB               => 'Same',
29 30 31
        }
    }
);
32

33 34 35 36 37 38 39
my $res;

# Try to authenticate
# -------------------
ok(
    $res = $client->_post(
        '/',
40 41
        IO::String->new('user=dwho&password=dwho&checkLogins=1'),
        length => 37,
42 43 44 45
        accept => 'text/html',
    ),
    'Auth query'
);
46 47

my ( $host, $url, $query ) =
Christophe Maudoux's avatar
Christophe Maudoux committed
48 49 50 51 52
  expectForm( $res, undef, '/2fchoice', 'token', 'checkLogins' );


ok(
    $res->[2]->[0] =~
Christophe Maudoux's avatar
Christophe Maudoux committed
53
qq%<img src="/static/bootstrap/u2f.png" alt="rest2F" title="rest2F" />%,
Christophe Maudoux's avatar
Christophe Maudoux committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    'Found u2f.png'
) or print STDERR Dumper( $res->[2]->[0] );

ok(
    $res->[2]->[0] =~
qq%<img src="/static/bootstrap/yubikey.png" alt="ext2F" title="ext2F" />%,
    'Found yubikey.png'
) or print STDERR Dumper( $res->[2]->[0] );

ok(
    $res->[2]->[0] =~
qq%<img src="/static/bootstrap/totp.png" alt="totp2F" title="totp2F" />%,
    'Found totp.png'
) or print STDERR Dumper( $res->[2]->[0] );

$query .= '&sf=ext';
ok(
    $res = $client->_post(
        '/2fchoice',
        IO::String->new($query),
        length => length($query),
        accept => 'text/html',
    ),
    'Post ext2f choice'
);

( $host, $url, $query ) =
81
  expectForm( $res, undef, '/ext2fcheck', 'token', 'code', 'checkLogins' );
82 83 84 85 86 87 88 89 90 91 92 93 94

ok(
    $res->[2]->[0] =~
qr%<input name="code" value="" class="form-control" id="extcode" trplaceholder="code">%,
    'Found EXTCODE input'
) or print STDERR Dumper( $res->[2]->[0] );

$query =~ s/code=/code=123456/;
ok(
    $res = $client->_post(
        '/ext2fcheck',
        IO::String->new($query),
        length => length($query),
95
        accept => 'text/html',
96 97 98
    ),
    'Post code'
);
99

100
my $id = expectCookie($res);
101 102 103 104 105 106

ok( $res->[2]->[0] =~ /trspan="lastLogins"/, 'History found' )
  or print STDERR Dumper( $res->[2]->[0] );
my @c = ( $res->[2]->[0] =~ /<td>127.0.0.1/gs );
ok( @c == 1, 'One entry found' );

107 108 109 110 111 112 113 114
$client->logout($id);

count($maintests);

clean_sessions();

done_testing( count() );