2018-09-05 21:13:39 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
2018-11-26 21:38:59 +01:00
|
|
|
my $maintests = 10;
|
2018-09-09 23:18:49 +02:00
|
|
|
|
|
|
|
use_ok('Lemonldap::NG::Common::FormEncode');
|
2018-09-05 21:13:39 +02:00
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
2018-09-05 21:13:39 +02:00
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
2018-11-26 21:59:40 +01:00
|
|
|
rest2fActivation => 1,
|
|
|
|
rest2fInitUrl => 'http://auth.example.com/init',
|
|
|
|
rest2fInitArgs => { name => 'uid' },
|
|
|
|
rest2fVerifyUrl => 'http://auth.example.com/vrfy',
|
|
|
|
rest2fVerifyArgs => { code => 'code' },
|
|
|
|
rest2fLogo => 'u2f.png',
|
2018-11-26 21:38:59 +01:00
|
|
|
totp2fActivation => '$uid eq "dwho"',
|
2018-09-05 21:13:39 +02:00
|
|
|
ext2fActivation => 1,
|
2019-02-14 22:09:59 +01:00
|
|
|
ext2fCodeActivation => 0,
|
2018-09-05 21:13:39 +02:00
|
|
|
ext2FSendCommand => 't/sendOTP.pl -uid $uid',
|
|
|
|
ext2FValidateCommand => 't/vrfyOTP.pl -uid $uid -code $code',
|
2018-11-26 21:38:59 +01:00
|
|
|
ext2fLogo => 'yubikey.png',
|
2018-09-09 23:18:49 +02:00
|
|
|
loginHistoryEnabled => 1,
|
|
|
|
authentication => 'Demo',
|
|
|
|
userDB => 'Same',
|
2018-09-05 21:13:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2018-09-09 23:18:49 +02:00
|
|
|
|
2018-09-05 21:13:39 +02:00
|
|
|
my $res;
|
|
|
|
|
|
|
|
# Try to authenticate
|
|
|
|
# -------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
2018-09-09 23:18:49 +02:00
|
|
|
IO::String->new('user=dwho&password=dwho&checkLogins=1'),
|
|
|
|
length => 37,
|
2018-09-05 21:13:39 +02:00
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2018-09-09 23:18:49 +02:00
|
|
|
|
|
|
|
my ( $host, $url, $query ) =
|
2018-11-26 21:38:59 +01:00
|
|
|
expectForm( $res, undef, '/2fchoice', 'token', 'checkLogins' );
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2019-02-05 23:12:17 +01:00
|
|
|
qq%<img src="/static/bootstrap/u2f.png" alt="rest2F" title="rest2F" />%,
|
2018-11-26 21:38:59 +01:00
|
|
|
'Found u2f.png'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2019-02-05 23:12:17 +01:00
|
|
|
qq%<img src="/static/bootstrap/yubikey.png" alt="ext2F" title="ext2F" />%,
|
2018-11-26 21:38:59 +01:00
|
|
|
'Found yubikey.png'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2019-02-05 23:12:17 +01:00
|
|
|
qq%<img src="/static/bootstrap/totp.png" alt="totp2F" title="totp2F" />%,
|
2018-11-26 21:38:59 +01:00
|
|
|
'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 ) =
|
2019-09-03 11:56:48 +02:00
|
|
|
expectForm( $res, undef, '/ext2fcheck?skin=bootstrap', 'token', 'code', 'checkLogins' );
|
2018-09-05 21:13:39 +02:00
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2019-01-09 19:01:49 +01:00
|
|
|
qr%<input name="code" value="" class="form-control" id="extcode" trplaceholder="code" autocomplete="off" />%,
|
2018-09-05 21:13:39 +02:00
|
|
|
'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),
|
2018-09-09 23:18:49 +02:00
|
|
|
accept => 'text/html',
|
2018-09-05 21:13:39 +02:00
|
|
|
),
|
|
|
|
'Post code'
|
|
|
|
);
|
2018-09-09 23:18:49 +02:00
|
|
|
|
2018-09-05 21:13:39 +02:00
|
|
|
my $id = expectCookie($res);
|
2018-09-09 23:18:49 +02:00
|
|
|
|
|
|
|
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' );
|
|
|
|
|
2018-09-05 21:13:39 +02:00
|
|
|
$client->logout($id);
|
|
|
|
|
|
|
|
count($maintests);
|
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|
|
|
|
|