BEGIN {
require
't/test-lib.pm'
;
}
my
$debug
=
'error'
;
my
(
$issuer
,
$sp
,
$res
,
$spId
);
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
;
if
(
$req
->method =~ /^(post|put)$/i ) {
my
$mth
=
'_'
.
lc
($1);
my
$s
=
$req
->content;
ok(
$res
=
$issuer
->
$mth
(
$url
,
IO::String->new(
$s
),
length
=>
length
(
$s
),
type
=>
$req
->header(
'Content-Type'
),
),
' Post request'
);
count(1);
expectOK(
$res
);
}
elsif
(
$req
->method =~ /^(get|
delete
)$/i ) {
my
$mth
=
'_'
.
lc
($1);
ok(
$res
=
$issuer
->
$mth
(
$url
,
accept
=>
$req
->header(
'Accept'
),
cookie
=>
$req
->header(
'Cookie'
),
query
=>
$query
,
),
' Execute request'
);
ok( (
$res
->[0] == 200 or
$res
->[0] == 400 ),
' Response is 200 or 400'
)
or explain(
$res
->[0],
'200 or 400'
);
count(2);
}
pass(
' @ END OF REST REQUEST'
);
count(1);
return
$res
;
}
);
$issuer
= register(
'issuer'
, \
&issuer
);
$sp
= register(
'sp'
, \
&sp
);
ok(
$res
=
$sp
->_get(
'/'
,
accept
=>
'text/html'
,
),
'Unauth SP request'
);
expectOK(
$res
);
ok(
$res
=
$sp
->_post(
'/'
, IO::String->new(
'user=french&password=french'
),
length
=> 27,
accept
=>
'text/html'
),
'Post user/password'
);
count(2);
$spId
= expectCookie(
$res
);
ok(
$res
=
$sp
->_get(
'/'
,
cookie
=>
"lemonldap=$spId"
),
'Auth test'
);
count(1);
expectOK(
$res
);
switch (
'issuer'
);
ok(
$res
=
$issuer
->_get(
"/sessions/global/$spId"
),
'Session content'
);
expectOK(
$res
);
ok(
$res
=
eval
{ JSON::from_json(
$res
->[2]->[0] ) },
' GET JSON'
)
or
print
STDERR $@;
ok(
$res
->{_session_id} eq
$spId
,
' Good ID'
)
or explain(
$res
,
"_session_id => $spId"
);
ok(
$res
->{array} =~ /;/,
'Mulivalued attribute found'
)
or explain(
$res
,
"Multivalued attribute"
);
count(4);
ok(
$res
=
$issuer
->_get(
"/sessions/global/$spId/[_session_id,uid,cn]"
),
'Some session keys'
);
expectOK(
$res
);
ok(
$res
=
eval
{ JSON::from_json(
$res
->[2]->[0] ) },
' GET JSON'
)
or
print
STDERR $@;
ok(
$res
->{_session_id} eq
$spId
,
' Good ID'
)
or explain(
$res
,
"_session_id => $spId"
);
ok(
$res
->{uid} eq
'french'
,
' Uid is french'
)
or explain(
$res
,
'uid => french'
);
count(4);
switch (
'sp'
);
ok(
$res
=
$sp
->_get(
'/'
,
query
=>
'logout'
,
accept
=>
'text/html'
,
cookie
=>
"lemonldap=$spId"
),
'Ask for logout'
);
count(1);
expectOK(
$res
);
ok(
$res
=
$sp
->_get(
'/'
,
cookie
=>
"lemonldap=$spId"
,
),
'Test if user is reject on IdP'
);
count(1);
expectReject(
$res
);
clean_sessions();
done_testing( count() );
sub
issuer {
return
LLNG::Manager::Test->new(
{
ini
=> {
logLevel
=>
$debug
,
domain
=>
'idp.com'
,
authentication
=>
'Demo'
,
userDB
=>
'Same'
,
restSessionServer
=> 1,
}
}
);
}
sub
sp {
return
LLNG::Manager::Test->new(
{
ini
=> {
logLevel
=>
$debug
,
domain
=>
'sp.com'
,
authentication
=>
'Demo'
,
userDB
=>
'Same'
,
globalStorage
=>
'Lemonldap::NG::Common::Apache::Session::REST'
,
globalStorageOptions
=> {
},
persistentStorage
=>
'Lemonldap::NG::Common::Apache::Session::REST'
,
persistentStorageOptions
=> {
},
},
}
);
}