Commit de04cfc4 authored by Yadd's avatar Yadd
Browse files

Clean test output (#595)

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