BEGIN {
require
't/test-lib.pm'
;
}
my
(
$issuer
,
$sp
,
$res
,
$spId
,
$idpId
);
my
%handlerOR
= (
issuer
=> [],
sp
=> [] );
LWP::Protocol::PSGI->register(
sub
{
my
$req
= Plack::Request->new(
@_
);
ok(
$req
->uri =~ m
' @ REST request ('
.
$req
->method .
" $1)"
);
count(1);
my
$url
= $1;
my
$query
= $2;
my
$res
;
my
$s
=
$req
->content;
if
(
$req
->method =~ /^(post|put)$/i ) {
my
$mth
=
'_'
.
lc
($1);
my
$s
=
$req
->content;
ok(
$res
=
$issuer
->
$mth
(
$url
,
IO::String->new(
$s
),
(
$query
? (
query
=>
$query
) : () ),
length
=>
length
(
$s
),
type
=>
$req
->header(
'Content-Type'
),
),
' Post request'
);
count(1);
}
elsif
(
$req
->method =~ /^(get|
delete
)$/i ) {
my
$mth
=
'_'
.
lc
($1);
ok(
$res
=
$issuer
->
$mth
(
$url
,
(
$query
? (
query
=>
$query
) : () ),
accept
=>
$req
->header(
'Accept'
),
cookie
=>
$req
->header(
'Cookie'
)
),
' Execute request'
);
count(1);
}
return
$res
;
}
);
ok(
$issuer
= issuer(),
'Issuer portal'
);
$handlerOR
{issuer} = \
@Lemonldap::NG::Handler::Main::_onReload
;
switch (
'sp'
);
&Lemonldap::NG::Handler::Main::cfgNum
( 0, 0 );
ok(
$sp
= sp(),
'SP portal'
);
$handlerOR
{sp} = \
@Lemonldap::NG::Handler::Main::_onReload
;
count(2);
ok(
$res
=
$sp
->_get(
'/'
,
accept
=>
'text/html'
,
),
'Unauth SP request'
);
expectOK(
$res
);
ok(
$res
=
$sp
->_post(
'/'
, IO::String->new(
'user=dwho&password=dwho'
),
length
=> 23,
accept
=>
'text/html'
),
'Post user/password'
);
count(2);
$spId
= expectCookie(
$res
);
ok(
$res
=
$sp
->_get(
'/'
,
query
=>
'logout'
,
accept
=>
'text/html'
,
cookie
=>
"lemonldap=$spId"
),
'Ask for logout'
);
count(1);
expectOK(
$res
);
SKIP: {
count(1);
skip(
'LLNG_HASHED_SESSION_STORE is set, Auth::Proxy is unable to delete internal session'
,
1
)
if
$ENV
{LLNG_HASHED_SESSION_STORE};
ok(
$res
=
$sp
->_get(
'/'
,
cookie
=>
"lemonldap=$spId"
,
),
'Test if user is reject on IdP'
);
expectReject(
$res
);
}
clean_sessions();
done_testing( count() );
no
warnings
'redefine'
;
sub
switch {
my
$type
=
shift
;
@Lemonldap::NG::Handler::Main::_onReload
= @{
$handlerOR
{
$type
};
};
}
sub
issuer {
return
LLNG::Manager::Test->new( {
ini
=> {
domain
=>
'idp.com'
,
authentication
=>
'Demo'
,
secret
=>
'abc'
,
userDB
=>
'Same'
,
restSessionServer
=> 1,
restConfigServer
=> 1,
}
}
);
}
sub
sp {
return
LLNG::Manager::Test->new( {
ini
=> {
domain
=>
'sp.com'
,
authentication
=>
'Proxy'
,
userDB
=>
'Same'
,
secret
=>
'abc'
,
proxyUseSoap
=> 0,
whatToTrace
=>
'_whatToTrace'
,
globalStorage
=>
'Lemonldap::NG::Common::Apache::Session::REST'
,
globalStorageOptions
=> {
}
},
}
);
}