76-2F-Ext-with-HISTORY.t 2.88 KB
Newer Older
Christophe Maudoux's avatar
Christophe Maudoux committed
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');
Christophe Maudoux's avatar
Christophe Maudoux committed
10

Yadd's avatar
Yadd committed
11
my $client = LLNG::Manager::Test->new( {
Christophe Maudoux's avatar
Christophe Maudoux committed
12 13
        ini => {
            logLevel             => 'error',
Christophe Maudoux's avatar
Christophe Maudoux committed
14 15 16 17 18 19
            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
20
            totp2fActivation     => '$uid eq "dwho"',
Christophe Maudoux's avatar
Christophe Maudoux committed
21
            ext2fActivation      => 1,
Christophe Maudoux's avatar
Christophe Maudoux committed
22
            ext2fCodeActivation  => 0,
Christophe Maudoux's avatar
Christophe Maudoux committed
23 24
            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',
Christophe Maudoux's avatar
Christophe Maudoux committed
29 30 31
        }
    }
);
32

Christophe Maudoux's avatar
Christophe Maudoux committed
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,
Christophe Maudoux's avatar
Christophe Maudoux committed
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
  expectForm( $res, undef, '/2fchoice', 'token', 'checkLogins' );

ok(
    $res->[2]->[0] =~
Yadd's avatar
Tidy  
Yadd committed
52
      qq%<img src="/static/bootstrap/u2f.png" alt="rest2F" title="rest2F" />%,
Christophe Maudoux's avatar
Christophe Maudoux committed
53 54 55 56 57
    'Found u2f.png'
) or print STDERR Dumper( $res->[2]->[0] );

ok(
    $res->[2]->[0] =~
Yadd's avatar
Tidy  
Yadd committed
58
      qq%<img src="/static/bootstrap/yubikey.png" alt="ext2F" title="ext2F" />%,
Christophe Maudoux's avatar
Christophe Maudoux committed
59 60 61 62 63
    'Found yubikey.png'
) or print STDERR Dumper( $res->[2]->[0] );

ok(
    $res->[2]->[0] =~
Yadd's avatar
Tidy  
Yadd committed
64
      qq%<img src="/static/bootstrap/totp.png" alt="totp2F" title="totp2F" />%,
Christophe Maudoux's avatar
Christophe Maudoux committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    '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 ) =
80
  expectForm( $res, undef, '/ext2fcheck', 'token', 'code', 'checkLogins' );
Christophe Maudoux's avatar
Christophe Maudoux committed
81 82 83

ok(
    $res->[2]->[0] =~
84
qr%<input name="code" value="" class="form-control" id="extcode" trplaceholder="code" autocomplete="off" />%,
Christophe Maudoux's avatar
Christophe Maudoux committed
85 86 87 88 89 90 91 92 93
    '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),
94
        accept => 'text/html',
Christophe Maudoux's avatar
Christophe Maudoux committed
95 96 97
    ),
    'Post code'
);
98

Christophe Maudoux's avatar
Christophe Maudoux committed
99
my $id = expectCookie($res);
100 101 102 103 104 105

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' );

Christophe Maudoux's avatar
Christophe Maudoux committed
106 107 108 109 110 111 112 113
$client->logout($id);

count($maintests);

clean_sessions();

done_testing( count() );