Improve tests (#595)
This commit is contained in:
parent
5369f46024
commit
13fde85acb
|
@ -316,7 +316,7 @@ sub deleteSession {
|
|||
|
||||
$self->lmLog( "SOAP request to delete session $id", 'debug' );
|
||||
|
||||
return $self->p->_deleteSession($session);
|
||||
return $self->p->_deleteSession( $req, $session );
|
||||
}
|
||||
|
||||
# Returns key from all sessions
|
||||
|
|
|
@ -16,6 +16,7 @@ switch ('sp');
|
|||
|
||||
ok( $sp = sp(), 'SP portal' );
|
||||
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::Reload::_onReload;
|
||||
count(2);
|
||||
|
||||
# Simple SP access
|
||||
ok(
|
||||
|
@ -35,6 +36,7 @@ ok(
|
|||
),
|
||||
'Post user/password'
|
||||
);
|
||||
count(2);
|
||||
expectRedirection( $res, 'http://auth.sp.com' );
|
||||
$spId = expectCookie($res);
|
||||
|
||||
|
@ -159,7 +161,7 @@ ok(
|
|||
count(1);
|
||||
expectOK($res);
|
||||
|
||||
# Test if logout is done
|
||||
# Test if user is reject on IdP
|
||||
ok(
|
||||
$res = $sp->_get(
|
||||
'/', cookie => "lemonldap=$spId",
|
||||
|
@ -169,7 +171,6 @@ ok(
|
|||
count(1);
|
||||
expectReject($res);
|
||||
|
||||
count(4);
|
||||
clean_sessions();
|
||||
done_testing( count() );
|
||||
|
||||
|
@ -178,15 +179,19 @@ no warnings 'redefine';
|
|||
|
||||
sub LWP::UserAgent::request {
|
||||
my ( $self, $req ) = @_;
|
||||
ok( $req->uri =~ m#http://auth.idp.com(.*)#, " REST request (uri: $1)" );
|
||||
ok(
|
||||
$req->uri =~ m#http://auth.idp.com(.*)#,
|
||||
' @ REST request (' . $req->method . " $1)"
|
||||
);
|
||||
count(1);
|
||||
my $url = $1;
|
||||
my $res;
|
||||
my $s = $req->content;
|
||||
if ( $req->method =~ /^post$/i ) {
|
||||
my $s = $req->content;
|
||||
if ( $req->method =~ /^(post|put)$/i ) {
|
||||
my $mth = '_' . lc($1);
|
||||
my $s = $req->content;
|
||||
ok(
|
||||
$res = $issuer->_post(
|
||||
$res = $issuer->$mth(
|
||||
$url,
|
||||
IO::String->new($s),
|
||||
length => length($s),
|
||||
|
@ -198,9 +203,10 @@ sub LWP::UserAgent::request {
|
|||
expectOK($res);
|
||||
$idpId = expectCookie($res);
|
||||
}
|
||||
else {
|
||||
elsif ( $req->method =~ /^(get|delete)$/i ) {
|
||||
my $mth = '_' . lc($1);
|
||||
ok(
|
||||
$res = $issuer->_get(
|
||||
$res = $issuer->$mth(
|
||||
$url,
|
||||
accept => $req->header('Accept'),
|
||||
cookie => $req->header('Cookie')
|
||||
|
@ -221,6 +227,8 @@ sub LWP::UserAgent::request {
|
|||
$httpResp->header( $name, shift( @{ $res->[1] } ) );
|
||||
}
|
||||
$httpResp->content( join( '', @{ $res->[2] } ) );
|
||||
pass(' @ END OF REST REQUEST');
|
||||
count(1);
|
||||
return $httpResp;
|
||||
}
|
||||
|
||||
|
@ -243,7 +251,6 @@ sub issuer {
|
|||
userDB => 'Demo',
|
||||
restSessionServer => 1,
|
||||
restConfigServer => 1,
|
||||
whatToTrace => '_whatToTrace',
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -44,7 +44,36 @@ SKIP: {
|
|||
'Post user/password'
|
||||
);
|
||||
expectRedirection( $res, 'http://auth.sp.com' );
|
||||
expectCookie($res);
|
||||
my $spId = expectCookie($res);
|
||||
|
||||
# Test if we're authenticated
|
||||
ok( $res = $sp->_get( '/', cookie => "lemonldap=$spId" ),
|
||||
'Try to get menu' );
|
||||
count(1);
|
||||
expectOK($res);
|
||||
|
||||
# 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);
|
||||
}
|
||||
|
||||
count($maintests);
|
||||
|
@ -56,7 +85,7 @@ no warnings 'redefine';
|
|||
|
||||
sub LWP::UserAgent::request {
|
||||
my ( $self, $req ) = @_;
|
||||
ok( $req->uri =~ m#http://auth.((?:id|s)p).com(.*)#, 'SOAP request' );
|
||||
ok( $req->uri =~ m#http://auth.((?:id|s)p).com(.*)#, ' @ SOAP REQUEST @' );
|
||||
my $host = $1;
|
||||
my $url = $2;
|
||||
my $res;
|
||||
|
@ -72,11 +101,11 @@ sub LWP::UserAgent::request {
|
|||
HTTP_SOAPACTION => $req->header('Soapaction'),
|
||||
},
|
||||
),
|
||||
'Execute request'
|
||||
' Execute request'
|
||||
);
|
||||
expectOK($res);
|
||||
ok( getHeader( $res, 'Content-Type' ) =~ m#^(?:text|application)/xml#,
|
||||
'Content is XML' )
|
||||
' Content is XML' )
|
||||
or explain( $res->[1], 'Content-Type => application/xml' );
|
||||
my $httpResp = HTTP::Response->new( $res->[0], 'OK' );
|
||||
|
||||
|
@ -84,7 +113,8 @@ sub LWP::UserAgent::request {
|
|||
$httpResp->header( $name, shift( @{ $res->[1] } ) );
|
||||
}
|
||||
$httpResp->content( join( '', @{ $res->[2] } ) );
|
||||
count(3);
|
||||
pass(' @ END OF SOAP REQUEST @');
|
||||
count(4);
|
||||
return $httpResp;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,10 @@ no warnings 'redefine';
|
|||
|
||||
sub LWP::UserAgent::request {
|
||||
my ( $self, $req ) = @_;
|
||||
ok( $req->uri =~ m#http://auth.idp.com(.*)#, " REST request (uri: $1)" );
|
||||
ok(
|
||||
$req->uri =~ m#http://auth.idp.com(.*)#,
|
||||
' @ REST request (' . $req->method . " $1)"
|
||||
);
|
||||
count(1);
|
||||
my $url = $1;
|
||||
my $res;
|
||||
|
@ -137,6 +140,8 @@ sub LWP::UserAgent::request {
|
|||
$httpResp->header( $name, shift( @{ $res->[1] } ) );
|
||||
}
|
||||
$httpResp->content( join( '', @{ $res->[2] } ) );
|
||||
pass(' @ END OF REST REQUEST');
|
||||
count(1);
|
||||
return $httpResp;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,36 @@ SKIP: {
|
|||
'Post user/password'
|
||||
);
|
||||
expectRedirection( $res, 'http://auth.sp.com' );
|
||||
expectCookie($res);
|
||||
my $spId = expectCookie($res);
|
||||
|
||||
# Test if we're authenticated
|
||||
ok( $res = $sp->_get( '/', cookie => "lemonldap=$spId" ),
|
||||
'Try to get menu' );
|
||||
count(1);
|
||||
expectOK($res);
|
||||
|
||||
# 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);
|
||||
}
|
||||
|
||||
count($maintests);
|
||||
|
@ -56,7 +85,7 @@ no warnings 'redefine';
|
|||
|
||||
sub LWP::UserAgent::request {
|
||||
my ( $self, $req ) = @_;
|
||||
ok( $req->uri =~ m#http://auth.((?:id|s)p).com(.*)#, 'SOAP request' );
|
||||
ok( $req->uri =~ m#http://auth.((?:id|s)p).com(.*)#, ' @ SOAP REQUEST @' );
|
||||
my $host = $1;
|
||||
my $url = $2;
|
||||
my $res;
|
||||
|
@ -72,11 +101,11 @@ sub LWP::UserAgent::request {
|
|||
HTTP_SOAPACTION => $req->header('Soapaction'),
|
||||
},
|
||||
),
|
||||
'Execute request'
|
||||
' Execute request'
|
||||
);
|
||||
expectOK($res);
|
||||
ok( getHeader( $res, 'Content-Type' ) =~ m#^(?:text|application)/xml#,
|
||||
'Content is XML' )
|
||||
' Content is XML' )
|
||||
or explain( $res->[1], 'Content-Type => application/xml' );
|
||||
my $httpResp = HTTP::Response->new( $res->[0], 'OK' );
|
||||
|
||||
|
@ -84,7 +113,8 @@ sub LWP::UserAgent::request {
|
|||
$httpResp->header( $name, shift( @{ $res->[1] } ) );
|
||||
}
|
||||
$httpResp->content( join( '', @{ $res->[2] } ) );
|
||||
count(3);
|
||||
pass(' @ END OF SOAP REQUEST @');
|
||||
count(4);
|
||||
return $httpResp;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user