Commit de04cfc4 authored by Yadd's avatar Yadd
Browse files

Clean test output (#595)

parent 3e81f56a
......@@ -8,52 +8,49 @@ BEGIN {
}
my $debug = 'error';
my ( $issuer, $sp, $res );
my %handlerOR = ( issuer => [], sp => [] );
my ( $op, $rp, $res );
my %handlerOR = ( op => [], rp => [] );
# Initialization
ok( $issuer = issuer(), 'OP portal' );
ok( $op = op(), 'OP portal' );
ok(
$res = $issuer->_get('/oauth2/jwks'),
'Get JWKS, endpoint /oauth2/jwks'
);
ok( $res = $op->_get('/oauth2/jwks'), 'Get JWKS, endpoint /oauth2/jwks' );
my $jwks = $res->[2]->[0];
ok(
$res = $issuer->_get('/.well-known/openid-configuration'),
$res = $op->_get('/.well-known/openid-configuration'),
'Get metadata, endpoint /.well-known/openid-configuration'
);
my $metadata = $res->[2]->[0];
count(3);
switch ('sp');
ok( $sp = sp( $jwks, $metadata ), 'RP portal' );
switch ('rp');
ok( $rp = rp( $jwks, $metadata ), 'RP portal' );
count(1);
# Query RP for auth
ok( $res = $sp->_get( '/', accept => 'text/html' ), 'Unauth SP request' );
ok( $res = $rp->_get( '/', accept => 'text/html' ), 'Unauth SP request' );
count(1);
my ( $url, $query ) =
expectRedirection( $res, qr#http://auth.op.com(/oauth2/authorize)\?(.*)$# );
# Push request to OP
switch ('issuer');
ok( $res = $issuer->_get( $url, query => $query, accept => 'text/html' ),
"Push request to OP, endpoint $url" );
switch ('op');
ok( $res = $op->_get( $url, query => $query, accept => 'text/html' ),
"Push request to OP, endpoint $url" );
count(1);
expectOK($res);
# Try to authenticate to IdP
$query = "user=dwho&password=dwho&$query";
ok(
$res = $issuer->_post(
$res = $op->_post(
$url,
IO::String->new($query),
accept => 'text/html',
length => length($query),
),
"Post authentication, endpoint $url"
"Post authentication, endpoint $url"
);
count(1);
my $idpId = expectCookie($res);
......@@ -61,35 +58,36 @@ my ( $host, $tmp );
( $host, $tmp, $query ) = expectForm( $res, '#', undef, 'confirm' );
ok(
$res = $issuer->_post(
$res = $op->_post(
$url,
IO::String->new($query),
accept => 'text/html',
cookie => "lemonldap=$idpId",
length => length($query),
),
"Post confirmation, endpoint $url"
"Post confirmation, endpoint $url"
);
count(1);
($query) = expectRedirection( $res, qr#^http://auth.rp.com/?\?(.*)$# );
# Push OP response to RP
switch ('sp');
switch ('rp');
ok( $res = $sp->_get( '/', query => $query, accept => 'text/html' ),
ok( $res = $rp->_get( '/', query => $query, accept => 'text/html' ),
'Call openidconnectcallback on RP' );
count(1);
my $spId = expectCookie($res);
switch('issuer');
ok($res=$issuer->_get('/oauth2/checksession',accept=>'text.html'),'Check session, endpoint /oauth2/checksession');
switch ('op');
ok( $res = $op->_get( '/oauth2/checksession', accept => 'text.html' ),
'Check session, endpoint /oauth2/checksession' );
count(1);
# Logout initiated by RP
switch ('sp');
switch ('rp');
ok(
$res = $sp->_get(
$res = $rp->_get(
'/',
query => 'logout',
cookie => "lemonldap=$spId",
......@@ -102,35 +100,35 @@ count(1);
qr#http://auth.op.com(/oauth2/logout)\?(post_logout_redirect_uri=.+)$# );
# Push logout to OP
switch ('issuer');
switch ('op');
ok(
$res = $issuer->_get(
$res = $op->_get(
$url,
query => $query,
cookie => "lemonldap=$idpId",
accept => 'text/html'
),
"Push logout request to OP, endpoint $url"
"Push logout request to OP, endpoint $url"
);
count(1);
( $host, $tmp, $query ) = expectForm( $res, '#', undef, 'confirm' );
ok(
$res = $issuer->_post(
$res = $op->_post(
$url, IO::String->new($query),
length => length($query),
cookie => "lemonldap=$idpId",
),
"Confirm logout, endpoint $url"
"Confirm logout, endpoint $url"
);
count(1);
# Test if logout is done
switch ('issuer');
switch ('op');
ok(
$res = $issuer->_get(
$res = $op->_get(
'/', cookie => "lemonldap=$idpId",
),
'Test if user is reject on IdP'
......@@ -138,9 +136,9 @@ ok(
count(1);
expectReject($res);
switch ('sp');
switch ('rp');
ok(
$res = $sp->_get(
$res = $rp->_get(
'/',
accept => 'text/html',
cookie =>
......@@ -167,12 +165,12 @@ sub LWP::UserAgent::request {
my ( $res, $client );
count(1);
if ( $host eq 'op' ) {
pass(" Request from RP to OP, endpoint $url");
$client = $issuer;
pass(" Request from RP to OP, endpoint $url");
$client = $op;
}
elsif ( $host eq 'rp' ) {
pass(' Request from OP to RP');
$client = $sp;
$client = $rp;
}
else {
fail(' Aborting REST request (external)');
......@@ -223,7 +221,7 @@ sub switch {
};
}
sub issuer {
sub op {
return LLNG::Manager::Test->new(
{
ini => {
......@@ -318,7 +316,7 @@ GQIDAQAB
);
}
sub sp {
sub rp {
my ( $jwks, $metadata ) = @_;
return LLNG::Manager::Test->new(
{
......
......@@ -46,19 +46,19 @@ sub clean_sessions {
sub expectRedirection {
my ( $res, $location ) = @_;
ok( $res->[0] == 302, 'Get redirection' )
ok( $res->[0] == 302, ' Get redirection' )
or explain( $res->[0], 302 );
count(1);
if ( ref $location ) {
my @match;
@match = ( getRedirection($res) =~ $location );
ok( @match, 'Location header found' )
ok( @match, ' Location header found' )
or explain( $res->[1], "Location match: " . Dumper($location) );
count(1);
return @match;
}
else {
ok( getRedirection($res) eq $location, "Location is $location" )
ok( getRedirection($res) eq $location, " Location is $location" )
or explain( $res->[1], "Location => $location" );
count(1);
}
......@@ -67,7 +67,7 @@ count(1);
sub expectAutoPost {
my @r = expectForm(@_);
my $method = pop @r;
ok ( $method =~ /^post$/i, 'Method is POST' ) or explain (\@r,'POST');
ok ( $method =~ /^post$/i, ' Method is POST' ) or explain (\@r,'POST');
count(1);
return @r;
}
......@@ -80,7 +80,7 @@ sub expectForm {
ok(
$res->[2]->[0] =~
m@<form.+?action="(?:http://([^/]+)(/.*?)?|(#))".+method="(post|get)"@is,
'Page contains a form'
' Page contains a form'
)
)
{
......@@ -91,21 +91,21 @@ sub expectForm {
}
if ($hostRe) {
if ( ref $hostRe ) {
ok( $host =~ $hostRe, 'Host match' )
ok( $host =~ $hostRe, ' Host match' )
or explain( $host, $hostRe );
}
else {
ok( $host eq $hostRe, 'Host match' )
ok( $host eq $hostRe, ' Host match' )
or explain( $host, $hostRe );
}
count(1);
}
if ($uriRe) {
if ( ref $uriRe ) {
ok( $uri =~ $uriRe, 'URI match' ) or explain( $uri, $uriRe );
ok( $uri =~ $uriRe, ' URI match' ) or explain( $uri, $uriRe );
}
else {
ok( $uri eq $uriRe, 'URI match' ) or explain( $uri, $uriRe );
ok( $uri eq $uriRe, ' URI match' ) or explain( $uri, $uriRe );
}
count(1);
}
......@@ -115,7 +115,7 @@ sub expectForm {
map { "$_=" . uri_escape( uri_unescape( $fields{$_} ) ) }
keys(%fields) );
foreach my $f (@requiredFields) {
ok( defined $fields{$f}, qq{Field "$f" is defined} );
ok( defined $fields{$f}, qq{ Field "$f" is defined} );
count(1);
}
return ( $host, $uri, $query, $method );
......@@ -127,26 +127,26 @@ sub expectForm {
sub expectAuthenticatedAs {
my ( $res, $user ) = @_;
ok( getHeader( $res, 'Lm-Remote-User' ) eq $user, "Authenticated as $user" )
ok( getHeader( $res, 'Lm-Remote-User' ) eq $user, " Authenticated as $user" )
or explain( $res->[1], "Lm-Remote-User => $user" );
count(1);
}
sub expectOK {
my ($res) = @_;
ok( $res->[0] == 200, 'HTTP code is 200' ) or explain( $res, 200 );
ok( $res->[0] == 200, ' HTTP code is 200' ) or explain( $res, 200 );
count(1);
}
sub expectBadRequest {
my ($res) = @_;
ok( $res->[0] == 400, 'HTTP code is 400' ) or explain( $res->[0], 400 );
ok( $res->[0] == 400, ' HTTP code is 400' ) or explain( $res->[0], 400 );
count(1);
}
sub expectReject {
my ($res) = @_;
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res->[0], 401 );
ok( $res->[0] == 401, ' Response is 401' ) or explain( $res->[0], 401 );
count(1);
}
......@@ -155,7 +155,7 @@ sub expectCookie {
$cookieName ||= 'lemonldap';
my $cookies = getCookies($res);
my $id;
ok( defined( $id = $cookies->{$cookieName} ), "Get cookie $cookieName" )
ok( defined( $id = $cookies->{$cookieName} ), " Get cookie $cookieName" )
or explain( $res->[1], "Set-Cookie: $cookieName=something" );
count(1);
return $id;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment