2018-09-05 22:24:23 +02:00
|
|
|
use lib 'inc';
|
2017-01-07 21:37:07 +01:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
2018-04-10 06:54:08 +02:00
|
|
|
use LWP::UserAgent;
|
2018-09-05 22:24:23 +02:00
|
|
|
use LWP::Protocol::PSGI;
|
2017-01-07 21:37:07 +01:00
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
}
|
|
|
|
|
2020-02-05 17:12:07 +01:00
|
|
|
my $maintests = 2;
|
2017-01-07 21:37:07 +01:00
|
|
|
my $debug = 'error';
|
|
|
|
my ( $issuer, $sp, $res );
|
|
|
|
|
2018-04-10 06:54:08 +02:00
|
|
|
# Redefine LWP methods for tests
|
|
|
|
LWP::Protocol::PSGI->register(
|
|
|
|
sub {
|
|
|
|
my $req = Plack::Request->new(@_);
|
|
|
|
ok( $req->uri =~ m#http://auth.((?:id|s)p).com(.*)#,
|
|
|
|
' @ SOAP REQUEST @' );
|
|
|
|
my $host = $1;
|
|
|
|
my $url = $2;
|
|
|
|
my $res;
|
2019-07-02 20:03:40 +02:00
|
|
|
my $s = $req->content;
|
2018-04-10 06:54:08 +02:00
|
|
|
my $client = ( $host eq 'idp' ? $issuer : $sp );
|
|
|
|
switch ( $host eq 'idp' ? 'issuer' : 'sp' );
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
$url,
|
|
|
|
IO::String->new($s),
|
|
|
|
length => length($s),
|
|
|
|
type => $req->header('Content-Type'),
|
|
|
|
custom => {
|
|
|
|
HTTP_SOAPACTION => $req->header('Soapaction'),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
' Execute request'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
ok( getHeader( $res, 'Content-Type' ) =~ m#^(?:text|application)/xml#,
|
|
|
|
' Content is XML' )
|
|
|
|
or explain( $res->[1], 'Content-Type => application/xml' );
|
|
|
|
pass(' @ END OF SOAP REQUEST @');
|
|
|
|
count(4);
|
|
|
|
switch ( $host eq 'idp' ? 'sp' : 'issuer' );
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-01-07 21:37:07 +01:00
|
|
|
SKIP: {
|
|
|
|
eval 'use SOAP::Lite';
|
|
|
|
if ($@) {
|
|
|
|
skip 'SOAP::Lite not found', $maintests;
|
|
|
|
}
|
|
|
|
|
2020-02-05 17:12:07 +01:00
|
|
|
$issuer = register('issuer', \&issuer);
|
|
|
|
$sp = register('sp', \&sp);
|
2017-01-07 21:37:07 +01:00
|
|
|
|
|
|
|
# Simple SP access
|
|
|
|
my $res;
|
|
|
|
ok(
|
|
|
|
$res = $sp->_get(
|
|
|
|
'/', accept => 'text/html',
|
|
|
|
),
|
|
|
|
'Unauth SP request'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
|
|
|
|
# Try to auth
|
|
|
|
ok(
|
|
|
|
$res = $sp->_post(
|
|
|
|
'/', IO::String->new('user=dwho&password=dwho'),
|
|
|
|
length => 23,
|
|
|
|
accept => 'text/html'
|
|
|
|
),
|
|
|
|
'Post user/password'
|
|
|
|
);
|
|
|
|
expectRedirection( $res, 'http://auth.sp.com' );
|
2017-01-23 06:49:32 +01:00
|
|
|
my $spId = expectCookie($res);
|
|
|
|
|
|
|
|
# Test if we're authenticated
|
|
|
|
ok( $res = $sp->_get( '/', cookie => "lemonldap=$spId" ),
|
|
|
|
'Try to get menu' );
|
|
|
|
count(1);
|
|
|
|
expectOK($res);
|
|
|
|
|
2017-01-23 23:04:24 +01:00
|
|
|
use_ok('Lemonldap::NG::Common::Apache::Session::SOAP');
|
|
|
|
ok(
|
|
|
|
$res =
|
|
|
|
Lemonldap::NG::Common::Apache::Session::SOAP
|
2019-02-07 09:27:56 +01:00
|
|
|
->get_key_from_all_sessions( {
|
2017-01-23 23:04:24 +01:00
|
|
|
proxy => 'http://auth.idp.com/adminSessions',
|
|
|
|
ns => 'urn:Lemonldap/NG/Common/PSGI/SOAPService'
|
|
|
|
},
|
|
|
|
[ 'uid', 'cn' ],
|
|
|
|
),
|
|
|
|
'Try get_key_from_all_sessions'
|
|
|
|
);
|
|
|
|
ok( defined $res->{$spId}, ' Found session' );
|
|
|
|
count(3);
|
|
|
|
|
2017-01-23 06:49:32 +01:00
|
|
|
# Logout
|
|
|
|
ok(
|
|
|
|
$res = $sp->_get(
|
|
|
|
'/',
|
|
|
|
query => 'logout',
|
|
|
|
accept => 'text/html',
|
|
|
|
cookie => "lemonldap=$spId"
|
|
|
|
),
|
|
|
|
'Ask for logout'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectOK($res);
|
|
|
|
|
|
|
|
# Test if logout is done
|
|
|
|
ok(
|
|
|
|
$res = $sp->_get(
|
|
|
|
'/', cookie => "lemonldap=$spId",
|
|
|
|
),
|
|
|
|
'Test if user is reject on IdP'
|
|
|
|
);
|
|
|
|
count(1);
|
|
|
|
expectReject($res);
|
2017-01-07 21:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
count($maintests);
|
|
|
|
clean_sessions();
|
|
|
|
done_testing( count() );
|
|
|
|
|
|
|
|
sub issuer {
|
2019-02-07 09:27:56 +01:00
|
|
|
return LLNG::Manager::Test->new( {
|
2017-01-07 21:37:07 +01:00
|
|
|
ini => {
|
2017-01-08 09:42:16 +01:00
|
|
|
logLevel => $debug,
|
|
|
|
domain => 'idp.com',
|
|
|
|
portal => 'http://auth.idp.com',
|
|
|
|
authentication => 'Demo',
|
2017-02-05 10:13:20 +01:00
|
|
|
userDB => 'Same',
|
2017-01-08 09:42:16 +01:00
|
|
|
soapSessionServer => 1,
|
2017-01-07 21:37:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub sp {
|
2019-02-07 09:27:56 +01:00
|
|
|
return LLNG::Manager::Test->new( {
|
2017-01-07 21:37:07 +01:00
|
|
|
ini => {
|
2017-01-09 07:11:30 +01:00
|
|
|
logLevel => $debug,
|
|
|
|
domain => 'sp.com',
|
|
|
|
portal => 'http://auth.sp.com',
|
|
|
|
authentication => 'Proxy',
|
2017-02-05 10:13:20 +01:00
|
|
|
userDB => 'Same',
|
2017-01-09 07:11:30 +01:00
|
|
|
proxyAuthService => 'http://auth.idp.com/sessions',
|
|
|
|
proxyUseSoap => 1,
|
2017-01-07 21:37:07 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|