lemonldap-ng/lemonldap-ng-portal/t/62-UpgradeSession.t

158 lines
3.7 KiB
Perl
Raw Normal View History

2019-06-26 22:13:12 +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);
2019-10-29 22:14:34 +01:00
my $res;
2019-06-26 22:13:12 +02:00
my $client = LLNG::Manager::Test->new( {
ini => {
2019-10-29 22:21:58 +01:00
logLevel => 'error',
upgradeSession => 1,
authentication => 'Choice',
apacheAuthnLevel => 5,
forceGlobalStorageUpgradeOTT => 1,
userDB => 'Same',
'authChoiceModules' => {
2019-06-26 22:13:12 +02:00
'strong' => 'Apache;Demo;Null;;;{}',
'weak' => 'Demo;Demo;Null;;;{}'
},
'vhostOptions' => {
'test1.example.com' => {
'vhostAuthnLevel' => 3
},
},
2019-10-27 21:06:08 +01:00
"locationRules" => {
"test1.example.com" => {
2019-10-29 22:14:34 +01:00
'default' => 'accept',
'^/AuthWeak(?#AuthnLevel=2)' => 'deny',
'^/AuthStrong(?#AuthnLevel=5)' => 'deny',
2019-10-27 21:06:08 +01:00
},
},
2019-06-26 22:13:12 +02:00
}
}
);
# Try to authenticate
# -------------------
ok(
2019-10-29 22:14:34 +01:00
$res = $client->_post(
2019-06-26 22:13:12 +02:00
'/',
IO::String->new('user=dwho&password=dwho&lmAuth=weak'),
length => 35,
accept => 'text/html',
),
'Auth query'
);
count(1);
my $id = expectCookie($res);
2019-10-29 22:14:34 +01:00
# Portal IS NOT a handler
#########################
2019-10-27 22:02:49 +01:00
ok(
2019-10-29 22:14:34 +01:00
$res = $client->_get(
'/AuthWeak',
2019-10-27 22:02:49 +01:00
accept => 'text/html',
cookie => "lemonldap=$id",
2019-10-29 22:14:34 +01:00
host => 'test1.example.com',
2019-10-27 22:02:49 +01:00
),
2019-10-29 22:14:34 +01:00
'GET http://test1.example.com/AuthWeak'
2019-10-27 22:02:49 +01:00
);
2019-10-29 22:14:34 +01:00
expectOK($res);
2019-10-27 22:02:49 +01:00
count(1);
ok(
2019-10-29 22:14:34 +01:00
$res = $client->_get(
'/AuthStrong',
2019-10-27 22:02:49 +01:00
accept => 'text/html',
cookie => "lemonldap=$id",
2019-10-29 22:14:34 +01:00
host => 'test1.example.com',
2019-10-27 22:02:49 +01:00
),
'GET http://test1.example.com/AuthStrong'
);
count(1);
2019-06-26 22:13:12 +02:00
# After attempting to access test1,
# the handler sends up back to /upgradesession
# --------------------------------------------
ok(
2019-10-29 22:14:34 +01:00
$res = $client->_get(
2019-06-26 22:13:12 +02:00
'/upgradesession',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29t',
accept => 'text/html',
cookie => "lemonldap=$id",
),
'Upgrade session query'
);
count(1);
my ( $host, $url, $query ) =
expectForm( $res, undef, '/upgradesession', 'confirm', 'url' );
# Accept session upgrade
# ----------------------
ok(
2019-10-29 22:14:34 +01:00
$res = $client->_post(
2019-06-26 22:13:12 +02:00
'/upgradesession',
IO::String->new($query),
length => length($query),
accept => 'text/html',
cookie => "lemonldap=$id",
),
'Accept session upgrade query'
);
count(1);
my $pdata = expectCookie( $res, 'lemonldappdata' );
2019-10-29 22:14:34 +01:00
( $host, $url, $query ) = expectForm( $res, '#', undef, 'upgrading', 'url' );
2019-06-26 22:13:12 +02:00
$query = $query . "&lmAuth=strong";
# Attempt login with the "strong" auth choice
# this should trigger 2FA
# -------------------------------------------
ok(
2019-10-29 22:14:34 +01:00
$res = $client->_post(
2019-06-26 22:13:12 +02:00
'/upgradesession',
IO::String->new($query),
length => length($query),
accept => 'text/html',
cookie => "lemonldap=$id;lemonldappdata=$pdata",
custom => {
REMOTE_USER => 'dwho',
},
),
'Post login'
);
count(1);
$pdata = expectCookie( $res, 'lemonldappdata' );
2019-07-02 20:03:40 +02:00
$id = expectCookie($res);
2019-06-26 22:13:12 +02:00
expectRedirection( $res, 'http://test1.example.com' );
# Make pdata was cleared and we aren't being redirected
ok(
2019-10-29 22:14:34 +01:00
$res = $client->_get(
2019-06-26 22:13:12 +02:00
'/',
accept => 'text/html',
cookie => "lemonldap=$id;lemonldappdata=$pdata",
),
'Post login'
);
count(1);
expectOK($res);
$client->logout($id);
2019-06-26 22:13:12 +02:00
clean_sessions();
done_testing( count() );