2019-07-18 22:41:24 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
require 't/smtp.pm';
|
|
|
|
|
|
|
|
use_ok('Lemonldap::NG::Common::FormEncode');
|
|
|
|
count(1);
|
|
|
|
|
2020-02-16 14:35:14 +01:00
|
|
|
my $res;
|
2019-07-18 22:41:24 +02:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
|
|
|
ini => {
|
2020-02-13 13:21:15 +01:00
|
|
|
logLevel => 'error',
|
|
|
|
localSessionStorage => "Cache::NullCache",
|
|
|
|
tokenUseGlobalStorage => 1,
|
|
|
|
authentication => 'Demo',
|
|
|
|
userDB => 'Same',
|
2020-04-15 17:09:18 +02:00
|
|
|
restSessionServer => 1,
|
2020-02-13 13:21:15 +01:00
|
|
|
'sfExtra' => {
|
2019-07-18 22:41:24 +02:00
|
|
|
'home' => {
|
|
|
|
'over' => {
|
2019-08-01 17:27:14 +02:00
|
|
|
mail2fCodeRegex => '\w{4}',
|
2019-07-18 22:41:24 +02:00
|
|
|
},
|
2020-02-13 13:21:15 +01:00
|
|
|
'logo' => 'home.jpg',
|
2019-08-04 19:31:48 +02:00
|
|
|
'label' => "Home Label",
|
2020-02-13 13:21:15 +01:00
|
|
|
'rule' => '$uid eq "dwho" or $uid eq "msmith"',
|
2020-04-15 17:09:18 +02:00
|
|
|
'type' => 'Mail2F',
|
|
|
|
'level' => 5,
|
2019-07-18 22:41:24 +02:00
|
|
|
},
|
|
|
|
'work' => {
|
|
|
|
'over' => {
|
2019-08-01 17:27:14 +02:00
|
|
|
mail2fCodeRegex => '\d{8}',
|
2019-07-18 22:41:24 +02:00
|
|
|
},
|
2019-08-01 17:27:14 +02:00
|
|
|
'logo' => 'work.jpg',
|
2019-07-18 22:41:24 +02:00
|
|
|
'rule' => '$uid eq "dwho" or $uid eq "rtyler"',
|
|
|
|
'type' => 'Mail2F'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Login with rtyler
|
|
|
|
# -----------------
|
|
|
|
ok(
|
2020-02-16 14:35:14 +01:00
|
|
|
$res = $client->_post(
|
2019-07-18 22:41:24 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=rtyler&password=rtyler'),
|
|
|
|
length => 27,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
# Only "work" option is available
|
|
|
|
my ( $host, $url, $query ) =
|
2019-09-03 11:56:48 +02:00
|
|
|
expectForm( $res, undef, '/work2fcheck?skin=bootstrap', 'token', 'code' );
|
2019-07-18 22:41:24 +02:00
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2019-12-12 20:04:04 +01:00
|
|
|
qr%<input name="code" value="" type="text" class="form-control" id="extcode" trplaceholder="code" autocomplete="off" />%,
|
2019-07-18 22:41:24 +02:00
|
|
|
'Found EXTCODE input'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
ok( mail() =~ m%<b>(\d{8})</b>%, 'Found 2F code in mail' )
|
|
|
|
or print STDERR Dumper( mail() );
|
|
|
|
|
|
|
|
my $code = $1;
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
$query =~ s/code=/code=${code}/;
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/work2fcheck',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Post code'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
my $id = expectCookie($res);
|
|
|
|
$client->logout($id);
|
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
# Login with dwho
|
|
|
|
# ---------------
|
|
|
|
ok(
|
2020-02-16 14:35:14 +01:00
|
|
|
$res = $client->_post(
|
2019-07-18 22:41:24 +02:00
|
|
|
'/',
|
|
|
|
IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
# Expect choice page
|
2020-02-16 14:35:14 +01:00
|
|
|
( $host, $url, $query ) =
|
2019-07-18 22:41:24 +02:00
|
|
|
expectForm( $res, undef, '/2fchoice', 'token', 'checkLogins' );
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
qq%<img src="/static/bootstrap/work.jpg" alt="work2F" title="work2F" />%,
|
2019-08-01 17:27:14 +02:00
|
|
|
'Found work.jpg'
|
2019-07-18 22:41:24 +02:00
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
qq%<img src="/static/bootstrap/home.jpg" alt="home2F" title="home2F" />%,
|
2019-08-01 17:27:14 +02:00
|
|
|
'Found home.jpg'
|
2019-08-04 19:31:48 +02:00
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(1);
|
|
|
|
|
2020-02-13 13:21:15 +01:00
|
|
|
ok( $res->[2]->[0] =~ qq%<h4 trspan="work2f"></h4>%, 'Found translation label' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-08-04 19:31:48 +02:00
|
|
|
count(1);
|
|
|
|
|
2020-02-13 13:21:15 +01:00
|
|
|
ok( $res->[2]->[0] =~ qq%<h4>Home Label</h4>%, 'Found overriden label' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-07-18 22:41:24 +02:00
|
|
|
count(1);
|
|
|
|
|
|
|
|
$query .= '&sf=home';
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/2fchoice',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Post ext2f choice'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
2020-02-16 14:35:14 +01:00
|
|
|
( $host, $url, $query ) =
|
2019-09-03 11:56:48 +02:00
|
|
|
expectForm( $res, undef, '/home2fcheck?skin=bootstrap', 'token', 'code' );
|
2019-07-18 22:41:24 +02:00
|
|
|
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2019-12-12 20:04:04 +01:00
|
|
|
qr%<input name="code" value="" type="text" class="form-control" id="extcode" trplaceholder="code" autocomplete="off" />%,
|
2019-07-18 22:41:24 +02:00
|
|
|
'Found EXTCODE input'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
ok( mail() =~ m%<b>(\w{4})</b>%, 'Found 2F code in mail' )
|
|
|
|
or print STDERR Dumper( mail() );
|
|
|
|
|
2020-02-16 14:35:14 +01:00
|
|
|
$code = $1;
|
2019-07-18 22:41:24 +02:00
|
|
|
count(1);
|
|
|
|
|
|
|
|
$query =~ s/code=/code=${code}/;
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/home2fcheck',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Post code'
|
|
|
|
);
|
|
|
|
count(1);
|
2020-02-16 14:35:14 +01:00
|
|
|
$id = expectCookie($res);
|
2020-04-15 17:09:18 +02:00
|
|
|
|
|
|
|
# Verify Authn Level
|
|
|
|
ok( $res = $client->_get("/sessions/global/$id"), 'Get session' );
|
|
|
|
expectOK($res);
|
|
|
|
ok( $res = eval { JSON::from_json( $res->[2]->[0] ) }, ' GET JSON' )
|
|
|
|
or print STDERR $@;
|
|
|
|
is( $res->{authenticationLevel}, 5, "Correct authentication level" );
|
|
|
|
count(3);
|
|
|
|
|
2019-07-18 22:41:24 +02:00
|
|
|
$client->logout($id);
|
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
|
|
|
|
done_testing( count() );
|
|
|
|
|