2019-03-06 17:58:09 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $res;
|
|
|
|
|
2019-03-07 18:22:16 +01:00
|
|
|
my $client = LLNG::Manager::Test->new( {
|
|
|
|
ini => {
|
|
|
|
logLevel => 'error',
|
|
|
|
authentication => 'Demo',
|
|
|
|
userDB => 'Same',
|
|
|
|
loginHistoryEnabled => 0,
|
|
|
|
brutForceProtection => 0,
|
|
|
|
portalMainLogo => 'common/logos/logo_llng_old.png',
|
|
|
|
requireToken => 0,
|
|
|
|
checkUser => 1,
|
2019-03-10 22:23:12 +01:00
|
|
|
impersonationRule => '$uid ne "msmith"',
|
|
|
|
impersonationIdRule => '$uid ne "msmith"',
|
2019-05-04 12:32:38 +02:00
|
|
|
impersonationPrefix => 'testPrefix_',
|
2019-05-11 23:01:52 +02:00
|
|
|
securedCookie => 1,
|
|
|
|
https => 0,
|
2019-03-06 17:58:09 +01:00
|
|
|
checkUserDisplayPersistentInfo => 0,
|
|
|
|
checkUserDisplayEmptyValues => 0,
|
2019-03-06 21:29:03 +01:00
|
|
|
impersonationMergeSSOgroups => 0,
|
2019-07-06 23:27:45 +02:00
|
|
|
checkUserHiddenAttributes => '_loginHistory hGroups',
|
2019-03-10 22:53:41 +01:00
|
|
|
macros => {
|
2019-05-04 12:32:38 +02:00
|
|
|
test_impersonation => '"$testPrefix__user/$_user"',
|
2019-03-10 22:53:41 +01:00
|
|
|
_whatToTrace =>
|
|
|
|
'$_auth eq "SAML" ? "$_user@$_idpConfKey" : $_user',
|
2020-04-25 19:06:51 +02:00
|
|
|
mail => 'uc $mail'
|
|
|
|
}
|
2019-03-06 17:58:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-03-10 22:23:12 +01:00
|
|
|
## Try to impersonate with a bad spoofed user
|
2019-03-07 18:22:16 +01:00
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
2019-03-07 15:23:57 +01:00
|
|
|
count(1);
|
|
|
|
my ( $host, $url, $query ) =
|
|
|
|
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
|
|
|
|
|
|
|
|
$query =~ s/user=/user=rtyler/;
|
|
|
|
$query =~ s/password=/password=rtyler/;
|
|
|
|
$query =~ s/spoofId=/spoofId=dwho*/;
|
2019-03-07 18:22:16 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2019-03-07 15:23:57 +01:00
|
|
|
'/',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
2020-02-26 22:31:22 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%<span trmsg="40">%, ' PE40 found' )
|
2019-03-10 22:23:12 +01:00
|
|
|
or explain( $res->[2]->[0], "PE40 - Bad formed user" );
|
2019-03-07 15:23:57 +01:00
|
|
|
count(2);
|
|
|
|
|
2019-04-30 14:56:42 +02:00
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
|
|
|
count(1);
|
|
|
|
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
|
2019-03-06 17:58:09 +01:00
|
|
|
|
2019-03-10 22:23:12 +01:00
|
|
|
## Try to impersonate with a forbidden identity
|
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
|
|
|
count(1);
|
|
|
|
( $host, $url, $query ) =
|
|
|
|
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
|
|
|
|
|
|
|
|
$query =~ s/user=/user=rtyler/;
|
|
|
|
$query =~ s/password=/password=rtyler/;
|
|
|
|
$query =~ s/spoofId=/spoofId=msmith/;
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2020-05-23 23:52:09 +02:00
|
|
|
m%<div class="message message-negative alert"><span trmsg="5">%,
|
2019-03-10 22:23:12 +01:00
|
|
|
' PE5 found'
|
|
|
|
) or explain( $res->[2]->[0], "PE5 - Forbidden identity" );
|
|
|
|
count(2);
|
|
|
|
|
2019-04-30 14:56:42 +02:00
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
|
|
|
count(1);
|
|
|
|
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
|
2019-03-10 22:23:12 +01:00
|
|
|
|
|
|
|
## An unauthorized user try to impersonate
|
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
|
|
|
count(1);
|
|
|
|
( $host, $url, $query ) =
|
|
|
|
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
|
|
|
|
|
|
|
|
$query =~ s/user=/user=msmith/;
|
|
|
|
$query =~ s/password=/password=msmith/;
|
|
|
|
$query =~ s/spoofId=/spoofId=rtyler/;
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2020-05-23 23:52:09 +02:00
|
|
|
m%<div class="message message-negative alert"><span trmsg="93">%,
|
2019-03-10 22:23:12 +01:00
|
|
|
' PE93 found'
|
|
|
|
) or explain( $res->[2]->[0], "PE93 - Impersonation service not allowed" );
|
|
|
|
count(2);
|
|
|
|
|
2019-04-30 14:56:42 +02:00
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
|
|
|
count(1);
|
|
|
|
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
|
2019-03-10 22:23:12 +01:00
|
|
|
|
2019-03-11 22:53:58 +01:00
|
|
|
## An unauthorized user to impersonate tries to authenticate
|
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
|
|
|
count(1);
|
|
|
|
( $host, $url, $query ) =
|
|
|
|
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
|
|
|
|
|
|
|
|
$query =~ s/user=/user=msmith/;
|
|
|
|
$query =~ s/password=/password=msmith/;
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
2019-04-30 14:56:42 +02:00
|
|
|
my $id = expectCookie($res);
|
2019-03-11 22:53:58 +01:00
|
|
|
expectRedirection( $res, 'http://auth.example.com/' );
|
|
|
|
|
2019-05-26 12:56:33 +02:00
|
|
|
# Get Menu
|
|
|
|
# ------------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Get Menu',
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectOK($res);
|
|
|
|
ok(
|
2019-06-08 22:09:32 +02:00
|
|
|
$res->[2]->[0] =~ m%<span trspan="connectedAs">Connected as</span> msmith%,
|
2019-05-26 12:56:33 +02:00
|
|
|
'Connected as msmith'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
2019-05-31 17:50:59 +02:00
|
|
|
expectAuthenticatedAs( $res, 'msmith' );
|
2019-05-26 12:56:33 +02:00
|
|
|
count(1);
|
|
|
|
|
2019-03-11 22:53:58 +01:00
|
|
|
# CheckUser form
|
|
|
|
# ------------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/checkuser',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'CheckUser form',
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
( $host, $url, $query ) =
|
|
|
|
expectForm( $res, undef, '/checkuser', 'user', 'url' );
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="checkUser">%, 'Found trspan="checkUser"' )
|
|
|
|
or explain( $res->[2]->[0], 'trspan="checkUser"' );
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
'/checkuser',
|
|
|
|
IO::String->new($query),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'POST checkuser'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">test_impersonation</td>%,
|
2019-03-11 22:53:58 +01:00
|
|
|
'Found macro test_impersonation' )
|
|
|
|
or explain( $res->[2]->[0], 'test_impersonation' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">msmith/msmith</td>%,
|
2019-03-11 22:53:58 +01:00
|
|
|
'Found msmith/msmith' )
|
|
|
|
or explain( $res->[2]->[0], 'Found msmith/msmith' );
|
2020-04-25 19:06:51 +02:00
|
|
|
my $nbr = $res->[2]->[0] =~ s%MSMITH\@BADWOLF\.ORG%%g;
|
|
|
|
ok( $nbr == 2, 'Found two MSMITH@BADWOLF.ORG' )
|
|
|
|
or explain( $res->[2]->[0], 'Found two MSMITH@BADWOLF.ORG' );
|
|
|
|
count(3);
|
2019-03-11 22:53:58 +01:00
|
|
|
|
|
|
|
$client->logout($id);
|
|
|
|
|
2019-03-06 17:58:09 +01:00
|
|
|
## Try to authenticate
|
2019-03-07 18:22:16 +01:00
|
|
|
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Menu', );
|
2019-03-06 17:58:09 +01:00
|
|
|
count(1);
|
2019-03-10 22:23:12 +01:00
|
|
|
( $host, $url, $query ) =
|
2019-03-06 17:58:09 +01:00
|
|
|
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
|
|
|
|
|
|
|
|
$query =~ s/user=/user=rtyler/;
|
|
|
|
$query =~ s/password=/password=rtyler/;
|
|
|
|
$query =~ s/spoofId=/spoofId=dwho/;
|
2019-03-07 18:22:16 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2019-03-06 17:58:09 +01:00
|
|
|
'/',
|
|
|
|
IO::String->new($query),
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Auth query'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
2019-03-07 15:23:57 +01:00
|
|
|
$id = expectCookie($res);
|
2019-03-06 17:58:09 +01:00
|
|
|
expectRedirection( $res, 'http://auth.example.com/' );
|
|
|
|
|
2019-05-26 12:56:33 +02:00
|
|
|
# Get Menu
|
|
|
|
# ------------------------
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
'/',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Get Menu',
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectOK($res);
|
2019-06-08 22:09:32 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="connectedAs">Connected as</span> dwho%,
|
|
|
|
'Connected as dwho' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
2019-05-31 17:50:59 +02:00
|
|
|
expectAuthenticatedAs( $res, 'dwho' );
|
2019-05-26 12:56:33 +02:00
|
|
|
count(1);
|
|
|
|
|
2019-03-06 17:58:09 +01:00
|
|
|
# CheckUser form
|
|
|
|
# ------------------------
|
2019-03-07 18:22:16 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
2019-03-06 17:58:09 +01:00
|
|
|
'/checkuser',
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'CheckUser form',
|
|
|
|
);
|
|
|
|
count(1);
|
2019-03-07 18:22:16 +01:00
|
|
|
( $host, $url, $query ) =
|
|
|
|
expectForm( $res, undef, '/checkuser', 'user', 'url' );
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="checkUser">%, 'Found trspan="checkUser"' )
|
|
|
|
or explain( $res->[2]->[0], 'trspan="checkUser"' );
|
2019-03-06 17:58:09 +01:00
|
|
|
count(1);
|
|
|
|
|
|
|
|
$query =~ s/url=/url=test1.example.com/;
|
|
|
|
|
2019-03-07 18:22:16 +01:00
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
2019-03-06 17:58:09 +01:00
|
|
|
'/checkuser',
|
|
|
|
IO::String->new($query),
|
|
|
|
cookie => "lemonldap=$id",
|
|
|
|
length => length($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
),
|
|
|
|
'POST checkuser'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
|
2019-03-07 18:22:16 +01:00
|
|
|
( $host, $url, $query ) =
|
|
|
|
expectForm( $res, undef, '/checkuser', 'user', 'url' );
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="checkUser">%, 'Found trspan="checkUser"' )
|
|
|
|
or explain( $res->[2]->[0], 'trspan="checkUser"' );
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
2019-06-17 14:56:31 +02:00
|
|
|
m%<div class="alert alert-success"><div class="text-center"><b><span trspan="allowed"></span></b></div></div>%,
|
2019-03-06 17:58:09 +01:00
|
|
|
'Found trspan="allowed"'
|
|
|
|
) or explain( $res->[2]->[0], 'trspan="allowed"' );
|
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="headers">%, 'Found trspan="headers"' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], 'trspan="headers"' );
|
2019-03-06 21:29:03 +01:00
|
|
|
|
2019-03-06 17:58:09 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="macros">%, 'Found trspan="macros"' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], 'trspan="macros"' );
|
2019-03-06 17:58:09 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%<span trspan="attributes">%,
|
|
|
|
'Found trspan="attributes"' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], 'trspan="attributes"' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">_userDB</td>%, 'Found _userDB' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], '_userDB' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%Auth-User: %, 'Found Auth-User' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], 'Header Key: Auth-User' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%: dwho<br/>%, 'Found dwho' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], 'Header Value: dwho' );
|
2019-03-06 21:29:03 +01:00
|
|
|
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">_whatToTrace</td>%,
|
2019-03-06 17:58:09 +01:00
|
|
|
'Found _whatToTrace' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], 'Macro Key _whatToTrace' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">testPrefix_groups</td>%,
|
2019-05-04 12:32:38 +02:00
|
|
|
'Found testPrefix_groups' )
|
|
|
|
or explain( $res->[2]->[0], 'testPrefix_groups' );
|
2019-12-28 14:08:34 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">[^<]*su; su_test; test_su</td>%,
|
2019-06-08 22:09:32 +02:00
|
|
|
'Found "su; su_test; test_su"' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], 'su' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">testPrefix_uid</td>%,
|
2019-05-11 20:18:43 +02:00
|
|
|
'Found testPrefix_uid' )
|
2019-05-04 12:32:38 +02:00
|
|
|
or explain( $res->[2]->[0], 'testPrefix_groups' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">rtyler</td>%, 'Found rtyler' )
|
2019-03-07 18:22:16 +01:00
|
|
|
or explain( $res->[2]->[0], 'su' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">test_impersonation</td>%,
|
2019-03-10 22:55:21 +01:00
|
|
|
'Found macro test_impersonation' )
|
2019-03-10 22:53:41 +01:00
|
|
|
or explain( $res->[2]->[0], 'test_impersonation' );
|
2019-06-17 14:56:31 +02:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">rtyler/dwho</td>%, 'Found rtyler/dwo' )
|
2019-03-10 22:53:41 +01:00
|
|
|
or explain( $res->[2]->[0], 'Found rtyler/dwo' );
|
2020-01-03 12:36:35 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">_session_id</td>%, 'Found _session_id' )
|
|
|
|
or explain( $res->[2]->[0], 'Found _session_id' );
|
2020-02-20 23:34:02 +01:00
|
|
|
ok( $res->[2]->[0] =~ m%<td scope="row">_session_kind</td>%,
|
|
|
|
'Found _session_id' )
|
2020-01-03 20:04:33 +01:00
|
|
|
or explain( $res->[2]->[0], 'Found _session_kind' );
|
2019-12-28 14:08:34 +01:00
|
|
|
count(17);
|
2019-03-06 17:58:09 +01:00
|
|
|
|
2019-06-17 14:56:31 +02:00
|
|
|
my %attributes = map /<td scope="row">(.+)?<\/td>/g, $res->[2]->[0];
|
2020-04-01 18:38:01 +02:00
|
|
|
ok( keys %attributes == 34, 'Found 34 attributes' )
|
|
|
|
or print STDERR ( keys %attributes < 34 )
|
2020-05-23 23:52:09 +02:00
|
|
|
? "Missing attributes -> " . scalar keys(%attributes) . "\n"
|
|
|
|
: "Too much attributes -> " . scalar keys(%attributes) . "\n";
|
2019-06-14 17:23:26 +02:00
|
|
|
ok( $attributes{'_auth'} eq 'Demo', '_auth' )
|
|
|
|
or print STDERR Dumper( \%attributes );
|
|
|
|
ok( $attributes{'uid'}, 'uid' ) or print STDERR Dumper( \%attributes );
|
2019-06-13 09:25:59 +02:00
|
|
|
ok( $attributes{'testPrefix__auth'}, 'testPrefix__auth' )
|
|
|
|
or print STDERR Dumper( \%attributes );
|
|
|
|
ok( $attributes{'testPrefix_uid'} eq 'rtyler', 'testPrefix_uid' )
|
|
|
|
or print STDERR Dumper( \%attributes );
|
|
|
|
count(5);
|
2019-05-03 21:41:56 +02:00
|
|
|
|
2019-03-06 17:58:09 +01:00
|
|
|
$client->logout($id);
|
|
|
|
clean_sessions();
|
|
|
|
|
2019-03-07 18:22:16 +01:00
|
|
|
done_testing( count() );
|