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;
|
2019-02-02 21:31:37 +01:00
|
|
|
my $maintests = 21;
|
2018-04-28 09:09:34 +02:00
|
|
|
|
|
|
|
eval { unlink 't/userdb.db' };
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
my $dbh = DBI->connect("dbi:SQLite:dbname=t/userdb.db");
|
|
|
|
$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',
|
2019-02-02 19:06:18 +01:00
|
|
|
'7_Kerberos' => 'Kerberos;Null;Null',
|
2018-04-28 09:09:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db',
|
|
|
|
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,
|
2019-02-02 19:06:18 +01:00
|
|
|
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' );
|
2019-02-02 21:31:37 +01:00
|
|
|
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' );
|
2019-02-02 19:06:18 +01:00
|
|
|
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-03-19 05:56:36 +01: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-07-02 20:12:11 +02:00
|
|
|
or
|
|
|
|
explain( $res->[2]->[0], '<img src="/static/common/modules/Apache.png' );
|
2019-02-02 19:06:18 +01:00
|
|
|
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-07-02 20:12:11 +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"%,
|
2019-02-02 21:31:37 +01:00
|
|
|
' Redirect URL found'
|
2019-07-02 20:12:11 +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-03-19 05:56:36 +01:00
|
|
|
m%<script type="application/init">\s*\{"sslHost":"https://authssl.example.com:19876"\}\s*</script>%s,
|
2019-02-02 21:31:37 +01:00
|
|
|
' SSL AJAX URL found'
|
2019-07-02 20:12:11 +02:00
|
|
|
)
|
|
|
|
or
|
|
|
|
explain( $res->[2]->[0], '<script type="application/init">\{"sslHost"' );
|
2019-02-02 19:06:18 +01:00
|
|
|
expectForm( $res, '#', undef, 'kerberos' );
|
2019-02-05 23:12:17 +01:00
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~ m%<input type="hidden" name="kerberos" value="0" />%,
|
2019-02-02 19:06:18 +01:00
|
|
|
'Found hidden attribut "kerberos" with value="0"'
|
2019-03-19 05:56:36 +01:00
|
|
|
) or explain( $res->[2]->[0], '<input type="hidden" name="kerberos"' );
|
2019-02-02 21:31:37 +01:00
|
|
|
ok( $res->[2]->[0] =~ /kerberosChoice\.(?:min\.)?js/,
|
|
|
|
'Get Kerberos javascript' )
|
2019-03-19 05:56:36 +01: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">%,
|
2019-02-02 21:31:37 +01:00
|
|
|
' Redirect URL found'
|
2019-03-19 05:56:36 +01:00
|
|
|
) or explain( $res->[2]->[0], '<form id="lformKerberos"' );
|
2019-02-02 21:31:37 +01:00
|
|
|
ok( $res->[2]->[0] =~ /sslChoice\.(?:min\.)?js/,
|
|
|
|
'Get sslChoice javascript' )
|
2019-03-19 05:56:36 +01: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">%,
|
2019-02-02 21:31:37 +01:00
|
|
|
' Action # found'
|
2019-03-19 05:56:36 +01:00
|
|
|
) or explain( $res->[2]->[0], '<form id="lformSSL"' );
|
2018-11-26 14:40:21 +01:00
|
|
|
my $header = getHeader( $res, 'Content-Security-Policy' );
|
2018-11-03 23:30:45 +01:00
|
|
|
ok( $header =~ m%;form-action \'self\' https://test.example.com;%,
|
2018-11-03 23:19:25 +01:00
|
|
|
' CSP URL found' )
|
2019-07-02 20:12:11 +02:00
|
|
|
or
|
|
|
|
explain( $res->[1], 'form-action \'self\' 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-07-02 20:12:11 +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);
|
|
|
|
eval { unlink 't/userdb.db' };
|
|
|
|
clean_sessions();
|
|
|
|
done_testing( count() );
|