|
|
|
@ -20,9 +20,10 @@ my $client; |
|
|
|
|
LWP::Protocol::PSGI->register( |
|
|
|
|
sub { |
|
|
|
|
my $req = Plack::Request->new(@_); |
|
|
|
|
ok( $req->uri =~ m#http://auth.example.com(.*?)(?:\?(.*))?$#, " @ REST REQUEST @" ); |
|
|
|
|
ok( $req->uri =~ m#http://auth.example.com(.*?)(?:\?(.*))?$#, |
|
|
|
|
" @ REST REQUEST @" ); |
|
|
|
|
count(1); |
|
|
|
|
my $url = $1; |
|
|
|
|
my $url = $1; |
|
|
|
|
my $query = $2; |
|
|
|
|
my $res; |
|
|
|
|
switch ('portal'); |
|
|
|
@ -31,10 +32,10 @@ LWP::Protocol::PSGI->register( |
|
|
|
|
my $s = $req->content; |
|
|
|
|
ok( |
|
|
|
|
$res = $client->$mth( |
|
|
|
|
$url, |
|
|
|
|
IO::String->new($s), |
|
|
|
|
length => length($s), |
|
|
|
|
type => $req->header('Content-Type'), |
|
|
|
|
$url, |
|
|
|
|
IO::String->new($s), |
|
|
|
|
length => length($s), |
|
|
|
|
type => $req->header('Content-Type'), |
|
|
|
|
), |
|
|
|
|
' Post request' |
|
|
|
|
); |
|
|
|
@ -45,10 +46,10 @@ LWP::Protocol::PSGI->register( |
|
|
|
|
my $mth = '_' . lc($1); |
|
|
|
|
ok( |
|
|
|
|
$res = $client->$mth( |
|
|
|
|
$url, |
|
|
|
|
accept => $req->header('Accept'), |
|
|
|
|
cookie => $req->header('Cookie'), |
|
|
|
|
query => $query, |
|
|
|
|
$url, |
|
|
|
|
accept => $req->header('Accept'), |
|
|
|
|
cookie => $req->header('Cookie'), |
|
|
|
|
query => $query, |
|
|
|
|
), |
|
|
|
|
' Execute request' |
|
|
|
|
); |
|
|
|
@ -64,120 +65,118 @@ LWP::Protocol::PSGI->register( |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$client = LLNG::Manager::Test->new( |
|
|
|
|
{ |
|
|
|
|
ini => { |
|
|
|
|
logLevel => $debug, |
|
|
|
|
useSafeJail => 1, |
|
|
|
|
cda => 1, |
|
|
|
|
restSessionServer => 1, |
|
|
|
|
logger => 'Lemonldap::NG::Common::Logger::Std', |
|
|
|
|
} |
|
|
|
|
$client = LLNG::Manager::Test->new( |
|
|
|
|
{ |
|
|
|
|
ini => { |
|
|
|
|
logLevel => $debug, |
|
|
|
|
useSafeJail => 1, |
|
|
|
|
cda => 1, |
|
|
|
|
restSessionServer => 1, |
|
|
|
|
logger => 'Lemonldap::NG::Common::Logger::Std', |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
$handlerOR{portal} = \@Lemonldap::NG::Handler::Main::_onReload; |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
$handlerOR{portal} = \@Lemonldap::NG::Handler::Main::_onReload; |
|
|
|
|
|
|
|
|
|
# CDA with unauthentified user |
|
|
|
|
ok( |
|
|
|
|
$res = $client->_get( |
|
|
|
|
'/', |
|
|
|
|
query => 'url=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv', |
|
|
|
|
accept => 'text/html', |
|
|
|
|
), |
|
|
|
|
'Unauth CDA request' |
|
|
|
|
); |
|
|
|
|
my ( $host, $url, $query ) = expectForm( $res, undef, undef, 'url' ); |
|
|
|
|
ok( $query =~ /\burl=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv\b/, |
|
|
|
|
' check url value' ); |
|
|
|
|
# CDA with unauthentified user |
|
|
|
|
ok( |
|
|
|
|
$res = $client->_get( |
|
|
|
|
'/', |
|
|
|
|
query => 'url=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv', |
|
|
|
|
accept => 'text/html', |
|
|
|
|
), |
|
|
|
|
'Unauth CDA request' |
|
|
|
|
); |
|
|
|
|
my ( $host, $url, $query ) = expectForm( $res, undef, undef, 'url' ); |
|
|
|
|
ok( $query =~ /\burl=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv\b/, ' check url value' ); |
|
|
|
|
|
|
|
|
|
# Authentification |
|
|
|
|
$query .= '&user=dwho&password=dwho'; |
|
|
|
|
ok( |
|
|
|
|
$res = $client->_post( |
|
|
|
|
'/' => IO::String->new($query), |
|
|
|
|
length => length($query), |
|
|
|
|
accept => 'text/html', |
|
|
|
|
), |
|
|
|
|
'Post credentials' |
|
|
|
|
); |
|
|
|
|
# Authentification |
|
|
|
|
$query .= '&user=dwho&password=dwho'; |
|
|
|
|
ok( |
|
|
|
|
$res = $client->_post( |
|
|
|
|
'/' => IO::String->new($query), |
|
|
|
|
length => length($query), |
|
|
|
|
accept => 'text/html', |
|
|
|
|
), |
|
|
|
|
'Post credentials' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
($query) = |
|
|
|
|
expectRedirection( $res, |
|
|
|
|
qr#^http://test.example.org/\?(lemonldapcda=.*)$# ); |
|
|
|
|
($query) = |
|
|
|
|
expectRedirection( $res, qr#^http://test.example.org/\?(lemonldapcda=.*)$# ); |
|
|
|
|
|
|
|
|
|
# Handler part |
|
|
|
|
use_ok('Lemonldap::NG::Handler::Server'); |
|
|
|
|
use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib'); |
|
|
|
|
# Handler part |
|
|
|
|
use_ok('Lemonldap::NG::Handler::Server'); |
|
|
|
|
use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib'); |
|
|
|
|
|
|
|
|
|
my ( $cli, $app ); |
|
|
|
|
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 ); |
|
|
|
|
switch ('app'); |
|
|
|
|
ok( |
|
|
|
|
$app = Lemonldap::NG::Handler::Server->run( |
|
|
|
|
{ |
|
|
|
|
%{ $client->ini }, |
|
|
|
|
globalStorage => 'Lemonldap::NG::Common::Apache::Session::REST', |
|
|
|
|
globalStorageOptions => |
|
|
|
|
{ baseUrl => 'http://auth.example.com/sessions/global/' }, |
|
|
|
|
localSessionStorage => undef, |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
'App' |
|
|
|
|
); |
|
|
|
|
my ( $cli, $app ); |
|
|
|
|
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 ); |
|
|
|
|
switch ('app'); |
|
|
|
|
ok( |
|
|
|
|
$app = Lemonldap::NG::Handler::Server->run( |
|
|
|
|
{ |
|
|
|
|
%{ $client->ini }, |
|
|
|
|
globalStorage => 'Lemonldap::NG::Common::Apache::Session::REST', |
|
|
|
|
globalStorageOptions => |
|
|
|
|
{ baseUrl => 'http://auth.example.com/sessions/global/' }, |
|
|
|
|
localSessionStorage => undef, |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
'App' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
ok( |
|
|
|
|
$res = $app->( |
|
|
|
|
{ |
|
|
|
|
'HTTP_ACCEPT' => 'text/html', |
|
|
|
|
'SCRIPT_NAME' => '/', |
|
|
|
|
'SERVER_NAME' => '127.0.0.1', |
|
|
|
|
'QUERY_STRING' => $query, |
|
|
|
|
'HTTP_CACHE_CONTROL' => 'max-age=0', |
|
|
|
|
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', |
|
|
|
|
'PATH_INFO' => '/', |
|
|
|
|
'REQUEST_METHOD' => 'GET', |
|
|
|
|
'REQUEST_URI' => "/?$query", |
|
|
|
|
'X_ORIGINAL_URI' => "/?$query", |
|
|
|
|
'SERVER_PORT' => '80', |
|
|
|
|
'SERVER_PROTOCOL' => 'HTTP/1.1', |
|
|
|
|
'HTTP_USER_AGENT' => |
|
|
|
|
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox', |
|
|
|
|
'REMOTE_ADDR' => '127.0.0.1', |
|
|
|
|
'HTTP_HOST' => 'test.example.org', |
|
|
|
|
'VHOSTTYPE' => 'CDA', |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
'Push cda cookie' |
|
|
|
|
); |
|
|
|
|
expectRedirection( $res, 'http://test.example.org/' ); |
|
|
|
|
my $cid = expectCookie($res); |
|
|
|
|
ok( |
|
|
|
|
$res = $app->( |
|
|
|
|
{ |
|
|
|
|
'HTTP_ACCEPT' => 'text/html', |
|
|
|
|
'SCRIPT_NAME' => '/', |
|
|
|
|
'SERVER_NAME' => '127.0.0.1', |
|
|
|
|
'QUERY_STRING' => $query, |
|
|
|
|
'HTTP_CACHE_CONTROL' => 'max-age=0', |
|
|
|
|
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', |
|
|
|
|
'PATH_INFO' => '/', |
|
|
|
|
'REQUEST_METHOD' => 'GET', |
|
|
|
|
'REQUEST_URI' => "/?$query", |
|
|
|
|
'X_ORIGINAL_URI' => "/?$query", |
|
|
|
|
'SERVER_PORT' => '80', |
|
|
|
|
'SERVER_PROTOCOL' => 'HTTP/1.1', |
|
|
|
|
'HTTP_USER_AGENT' => |
|
|
|
|
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox', |
|
|
|
|
'REMOTE_ADDR' => '127.0.0.1', |
|
|
|
|
'HTTP_HOST' => 'test.example.org', |
|
|
|
|
'VHOSTTYPE' => 'CDA', |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
'Push cda cookie' |
|
|
|
|
); |
|
|
|
|
expectRedirection( $res, 'http://test.example.org/' ); |
|
|
|
|
my $cid = expectCookie($res); |
|
|
|
|
|
|
|
|
|
ok( |
|
|
|
|
$res = $app->( |
|
|
|
|
{ |
|
|
|
|
'HTTP_ACCEPT' => 'text/html', |
|
|
|
|
'SCRIPT_NAME' => '/', |
|
|
|
|
'SERVER_NAME' => '127.0.0.1', |
|
|
|
|
'HTTP_COOKIE' => "lemonldap=$cid", |
|
|
|
|
'HTTP_CACHE_CONTROL' => 'max-age=0', |
|
|
|
|
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', |
|
|
|
|
'PATH_INFO' => '/', |
|
|
|
|
'REQUEST_METHOD' => 'GET', |
|
|
|
|
'REQUEST_URI' => "/", |
|
|
|
|
'X_ORIGINAL_URI' => "/", |
|
|
|
|
'SERVER_PORT' => '80', |
|
|
|
|
'SERVER_PROTOCOL' => 'HTTP/1.1', |
|
|
|
|
'HTTP_USER_AGENT' => |
|
|
|
|
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox', |
|
|
|
|
'REMOTE_ADDR' => '127.0.0.1', |
|
|
|
|
'HTTP_HOST' => 'test.example.org', |
|
|
|
|
'VHOSTTYPE' => 'CDA', |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
'Authenticated query' |
|
|
|
|
); |
|
|
|
|
expectOK($res); |
|
|
|
|
expectAuthenticatedAs( $res, 'dwho' ); |
|
|
|
|
ok( |
|
|
|
|
$res = $app->( |
|
|
|
|
{ |
|
|
|
|
'HTTP_ACCEPT' => 'text/html', |
|
|
|
|
'SCRIPT_NAME' => '/', |
|
|
|
|
'SERVER_NAME' => '127.0.0.1', |
|
|
|
|
'HTTP_COOKIE' => "lemonldap=$cid", |
|
|
|
|
'HTTP_CACHE_CONTROL' => 'max-age=0', |
|
|
|
|
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', |
|
|
|
|
'PATH_INFO' => '/', |
|
|
|
|
'REQUEST_METHOD' => 'GET', |
|
|
|
|
'REQUEST_URI' => "/", |
|
|
|
|
'X_ORIGINAL_URI' => "/", |
|
|
|
|
'SERVER_PORT' => '80', |
|
|
|
|
'SERVER_PROTOCOL' => 'HTTP/1.1', |
|
|
|
|
'HTTP_USER_AGENT' => |
|
|
|
|
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox', |
|
|
|
|
'REMOTE_ADDR' => '127.0.0.1', |
|
|
|
|
'HTTP_HOST' => 'test.example.org', |
|
|
|
|
'VHOSTTYPE' => 'CDA', |
|
|
|
|
} |
|
|
|
|
), |
|
|
|
|
'Authenticated query' |
|
|
|
|
); |
|
|
|
|
expectOK($res); |
|
|
|
|
expectAuthenticatedAs( $res, 'dwho' ); |
|
|
|
|
|
|
|
|
|
clean_sessions(); |
|
|
|
|
|
|
|
|
|