lemonldap-ng/lemonldap-ng-portal/t/28-AuthChoice-with-rules.t

148 lines
5.5 KiB
Perl
Raw Permalink Normal View History

2018-04-28 09:09:34 +02:00
use Test::More;
use strict;
use IO::String;
2019-02-05 10:34:39 +01:00
BEGIN {
require 't/test-lib.pm';
eval "use GSSAPI";
}
2018-04-28 09:09:34 +02:00
my $res;
my $maintests = 21;
2018-04-28 09:09:34 +02:00
2019-08-29 10:04:06 +02:00
my $userdb = tempdb();
2018-04-28 09:09:34 +02:00
SKIP: {
2019-02-05 10:34:39 +01:00
eval { require DBI; require DBD::SQLite; require GSSAPI; };
2018-04-28 09:09:34 +02:00
if ($@) {
2019-02-05 10:34:39 +01:00
skip 'Missing dependencies', $maintests;
2018-04-28 09:09:34 +02:00
}
2019-08-29 10:04:06 +02:00
my $dbh = DBI->connect("dbi:SQLite:dbname=$userdb");
2018-04-28 09:09:34 +02:00
$dbh->do('CREATE TABLE users (user text,password text,name text)');
$dbh->do("INSERT INTO users VALUES ('dwho','dwho','Doctor who')");
2019-02-07 09:27:56 +01:00
my $client = LLNG::Manager::Test->new( {
2019-02-05 23:12:17 +01:00
ini => {
2018-04-28 09:09:34 +02:00
logLevel => 'error',
useSafeJail => 1,
2018-11-03 23:01:29 +01:00
portalMainLogo => 'common/logos/logo_llng_old.png',
2018-04-28 09:09:34 +02:00
authentication => 'Choice',
userDB => 'Same',
authChoiceParam => 'test',
authChoiceModules => {
2018-11-03 22:55:20 +01:00
'1_demo' => 'Demo;Demo;Null;;0',
'2_sql' => 'DBI;DBI;DBI;;1',
'3_demo' =>
2019-02-05 23:12:17 +01:00
'Demo;Demo;Null;https://test.example.com;$env->{ipAddr} =~ /127.0.0.1/',
2018-11-03 22:55:20 +01:00
'4_demo' =>
2019-02-05 23:12:17 +01:00
'Demo;Demo;Null;https://test.example.com;$env->{ipAddr} =~ /1.2.3.4/',
2018-11-29 21:13:09 +01:00
'5_ssl' => 'SSL;Demo;Demo',
2018-11-26 14:40:21 +01:00
'6_FakeCustom' => 'Custom;Demo;Demo',
'7_Kerberos' => 'Kerberos;Null;Null',
2018-04-28 09:09:34 +02:00
},
2019-08-29 10:04:06 +02:00
dbiAuthChain => "dbi:SQLite:dbname=$userdb",
2018-04-28 09:09:34 +02:00
dbiAuthUser => '',
dbiAuthPassword => '',
dbiAuthTable => 'users',
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
2018-11-23 23:04:47 +01:00
customAuth => '::Auth::Apache',
2018-11-26 14:40:21 +01:00
customAddParams => {},
2019-02-01 23:22:11 +01:00
sslByAjax => 1,
sslHost => 'https://authssl.example.com:19876',
krbKeytab => '/etc/keytab',
krbByJs => 1,
krbAuthnLevel => 4,
2018-04-28 09:09:34 +02:00
}
}
);
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu' );
2018-11-26 14:40:21 +01:00
ok( $res->[2]->[0] !~ /1_demo/, '1_demo not displayed' );
ok( $res->[2]->[0] =~ /2_sql/, '2_sql displayed' );
2018-11-26 14:40:21 +01:00
ok( $res->[2]->[0] =~ /3_demo/, '3_demo displayed' );
ok( $res->[2]->[0] =~ /5_ssl/, '5_ssl displayed' );
2018-11-23 23:04:47 +01:00
ok( $res->[2]->[0] =~ /6_FakeCustom/, '6_FakeCustom displayed' );
ok( $res->[2]->[0] =~ /7_Kerberos/, '7_Kerberos displayed' );
ok( $res->[2]->[0] =~ qr%<img src="/static/common/modules/SSL.png"%,
'Found 5_ssl Logo' )
2019-08-29 10:04:06 +02:00
or explain( $res->[2]->[0], '<img src="/static/common/modules/SSL.png' );
2018-11-23 23:04:47 +01:00
ok( $res->[2]->[0] =~ qr%img src="/static/common/modules/Apache.png"%,
'Found 6_FakeCustom Logo' )
2019-08-29 10:04:06 +02:00
or
explain( $res->[2]->[0], '<img src="/static/common/modules/Apache.png' );
ok( $res->[2]->[0] =~ qr%<img src="/static/common/modules/Kerberos.png"%,
2019-02-05 23:12:17 +01:00
'Found 7_Kerberos Logo' )
2019-08-29 10:04:06 +02:00
or explain( $res->[2]->[0],
'<img src="/static/common/modules/Kerberos.png' );
2019-02-05 23:12:17 +01:00
ok(
$res->[2]->[0] =~
m%<form id="lformDemo" action="https://test.example.com"%,
' Redirect URL found'
2019-08-29 10:04:06 +02:00
)
or explain( $res->[2]->[0],
'<form id="lformDemo" action="https://test.example.com"' );
2019-02-05 23:12:17 +01:00
ok(
$res->[2]->[0] =~
2019-08-29 10:04:06 +02:00
m%<script type="application/init">\s*\{"sslHost":"https://authssl.example.com:19876"\}\s*</script>%s,
' SSL AJAX URL found'
2019-08-29 10:04:06 +02:00
)
or
explain( $res->[2]->[0], '<script type="application/init">\{"sslHost"' );
expectForm( $res, '#', undef, 'kerberos' );
2019-02-05 23:12:17 +01:00
ok(
$res->[2]->[0] =~ m%<input type="hidden" name="kerberos" value="0" />%,
'Found hidden attribut "kerberos" with value="0"'
2019-08-29 10:04:06 +02:00
) or explain( $res->[2]->[0], '<input type="hidden" name="kerberos"' );
ok( $res->[2]->[0] =~ /kerberosChoice\.(?:min\.)?js/,
'Get Kerberos javascript' )
2019-08-29 10:04:06 +02:00
or explain( $res->[2]->[0], 'kerberosChoice.(min.)?js' );
2019-02-05 23:12:17 +01:00
ok(
$res->[2]->[0] =~
m%<form id="lformKerberos" action="#" method="post" class="login Kerberos">%,
' Redirect URL found'
2019-08-29 10:04:06 +02:00
) or explain( $res->[2]->[0], '<form id="lformKerberos"' );
ok( $res->[2]->[0] =~ /sslChoice\.(?:min\.)?js/,
'Get sslChoice javascript' )
2019-08-29 10:04:06 +02:00
or explain( $res->[2]->[0], 'sslChoice.(min.)?js' );
2019-02-05 23:12:17 +01:00
ok(
$res->[2]->[0] =~
m%<form id="lformSSL" action="#" method="post" class="login SSL">%,
' Action # found'
2019-08-29 10:04:06 +02:00
) or explain( $res->[2]->[0], '<form id="lformSSL"' );
2018-11-26 14:40:21 +01:00
my $header = getHeader( $res, 'Content-Security-Policy' );
2021-04-22 17:48:18 +02:00
ok( $header =~ m%;form-action \* https://test.example.com;%,
2018-11-03 23:19:25 +01:00
' CSP URL found' )
2021-04-22 17:48:18 +02:00
or explain( $res->[1], 'form-action * https://test.example.com;' );
2018-11-03 22:55:20 +01:00
ok( $res->[2]->[0] !~ /4_demo/, '4_Demo not displayed' );
2019-02-05 23:12:17 +01:00
ok(
$res->[2]->[0] =~ qr%<img src="/static/common/logos/logo_llng_old.png"%,
2018-11-26 14:40:21 +01:00
'Found custom Main Logo'
2019-08-29 10:04:06 +02:00
)
or explain( $res->[2]->[0],
'<img src="/static/common/logos/logo_llng_old.png"' );
2018-04-28 09:09:34 +02:00
# Test SQL
2018-11-03 22:55:20 +01:00
my $postString = 'user=dwho&password=dwho&test=2_sql';
2018-04-28 09:09:34 +02:00
2019-06-01 11:48:07 +02:00
# Try to authenticate
2018-04-28 09:09:34 +02:00
# -------------------
2019-02-05 23:12:17 +01:00
ok(
$res = $client->_post(
2018-04-28 09:09:34 +02:00
'/', IO::String->new($postString),
length => length($postString)
),
'Auth query'
);
expectOK($res);
my $id = expectCookie($res);
$client->logout($id);
clean_sessions();
}
count($maintests);
clean_sessions();
done_testing( count() );