Add test for session SOAP (#595)
This commit is contained in:
parent
8cd810a1ce
commit
42a2d8cb86
|
@ -357,6 +357,7 @@ t/32-Auth-and-issuer-OIDC-implicit.t
|
|||
t/33-Auth-and-issuer-OpenID2.t
|
||||
t/34-Auth-Proxy-and-REST-Server.t
|
||||
t/34-Auth-Proxy-and-SOAP-Server.t
|
||||
t/35-SOAP-sessions-with-SOAP-server.t
|
||||
t/40-Notifications-DBI.t
|
||||
t/41-Register-Demo.t
|
||||
t/50-IssuerGet.t
|
||||
|
|
|
@ -93,7 +93,7 @@ sub unauthAdminSessions {
|
|||
return $self->dispatch_to(
|
||||
$req,
|
||||
qw(getCookies getAttributes isAuthorizedURI getMenuApplications
|
||||
newSession deleteSession get_key_from_all_sessions)
|
||||
newSession setAttributes deleteSession get_key_from_all_sessions)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -213,8 +213,9 @@ sub getAttributes {
|
|||
push @tmp, SOAP::Data->name( error => 1 )->type('int');
|
||||
}
|
||||
else {
|
||||
$self->p->userInfo( "SOAP attributes request for "
|
||||
. $session->data->{ $self->conf->{whatToTrace} } );
|
||||
my $wtt = $session->data->{ $self->conf->{whatToTrace} };
|
||||
$self->p->userInfo(
|
||||
"SOAP attributes request for " . ( $wtt ? $wtt : $id ) );
|
||||
push @tmp, SOAP::Data->name( error => 0 )->type('int');
|
||||
push @tmp,
|
||||
SOAP::Data->name( attributes =>
|
||||
|
@ -290,18 +291,15 @@ sub newSession {
|
|||
return 0;
|
||||
}
|
||||
|
||||
$args ||= {};
|
||||
my $infos = {};
|
||||
%$infos = %$args;
|
||||
$infos->{_utime} = time();
|
||||
|
||||
$session->update($infos);
|
||||
|
||||
$self->lmLog(
|
||||
"SOAP request to store "
|
||||
. $session->id . " ("
|
||||
. $session->data->{ $self->conf->{whatToTrace} } . ")",
|
||||
'debug'
|
||||
);
|
||||
$self->lmLog( "SOAP request create a new session (" . $session->id . ")",
|
||||
'debug' );
|
||||
|
||||
return SOAP::Data->name( attributes => _buildSoapHash( $session->data ) );
|
||||
}
|
||||
|
|
130
lemonldap-ng-portal/t/35-SOAP-sessions-with-SOAP-server.t
Normal file
130
lemonldap-ng-portal/t/35-SOAP-sessions-with-SOAP-server.t
Normal file
|
@ -0,0 +1,130 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use IO::String;
|
||||
|
||||
BEGIN {
|
||||
require 't/test-lib.pm';
|
||||
}
|
||||
|
||||
my $maintests = 4;
|
||||
my $debug = 'error';
|
||||
my ( $issuer, $sp, $res );
|
||||
my %handlerOR = ( issuer => [], sp => [] );
|
||||
|
||||
SKIP: {
|
||||
eval 'use SOAP::Lite';
|
||||
if ($@) {
|
||||
skip 'SOAP::Lite not found', $maintests;
|
||||
}
|
||||
|
||||
ok( $issuer = issuer(), 'Issuer portal' );
|
||||
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::Reload::_onReload;
|
||||
switch ('sp');
|
||||
|
||||
ok( $sp = sp(), 'SP portal' );
|
||||
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::Reload::_onReload;
|
||||
|
||||
# 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' );
|
||||
expectCookie($res);
|
||||
}
|
||||
|
||||
count($maintests);
|
||||
clean_sessions();
|
||||
done_testing( count() );
|
||||
|
||||
# Redefine LWP methods for tests
|
||||
no warnings 'redefine';
|
||||
|
||||
sub LWP::UserAgent::request {
|
||||
my ( $self, $req ) = @_;
|
||||
ok( $req->uri =~ m#http://auth.((?:id|s)p).com(.*)#, 'SOAP request' );
|
||||
my $host = $1;
|
||||
my $url = $2;
|
||||
my $res;
|
||||
my $s = $req->content;
|
||||
my $client = ( $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' );
|
||||
my $httpResp = HTTP::Response->new( $res->[0], 'OK' );
|
||||
|
||||
while ( my $name = shift @{ $res->[1] } ) {
|
||||
$httpResp->header( $name, shift( @{ $res->[1] } ) );
|
||||
}
|
||||
$httpResp->content( join( '', @{ $res->[2] } ) );
|
||||
count(3);
|
||||
return $httpResp;
|
||||
}
|
||||
|
||||
sub switch {
|
||||
my $type = shift;
|
||||
@Lemonldap::NG::Handler::Main::Reload::_onReload = @{
|
||||
$handlerOR{$type};
|
||||
};
|
||||
}
|
||||
|
||||
sub issuer {
|
||||
return LLNG::Manager::Test->new(
|
||||
{
|
||||
ini => {
|
||||
logLevel => $debug,
|
||||
templatesDir => 'site/htdocs/static',
|
||||
domain => 'idp.com',
|
||||
portal => 'http://auth.idp.com',
|
||||
authentication => 'Demo',
|
||||
userDB => 'Demo',
|
||||
soapSessionServer => 1,
|
||||
whatToTrace => 'cn',
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
sub sp {
|
||||
return LLNG::Manager::Test->new(
|
||||
{
|
||||
ini => {
|
||||
logLevel => $debug,
|
||||
domain => 'sp.com',
|
||||
portal => 'http://auth.sp.com',
|
||||
authentication => 'Demo',
|
||||
userDB => 'Demo',
|
||||
globalStorage => 'Lemonldap::NG::Common::Apache::Session::SOAP',
|
||||
globalStorageOptions =>
|
||||
{ proxy => 'http://auth.idp.com/adminSessions' },
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user