use Test::More; use strict; use IO::String; use MIME::Base64; BEGIN { require 't/test-lib.pm'; } my $maintests = 13; my $debug = 'debug'; my ( $issuer, $sp, $res ); my %handlerOR = ( issuer => [], sp => [] ); SKIP: { eval "use AuthCAS"; if ($@) { skip 'AuthCAS 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' ); ok( $res->[0] == 302, 'Return code is 302' ) or explain( $res->[0], 302 ); ok( $sp->getRedirection($res) eq 'http://auth.idp.com/cas/login?service=http://auth.sp.com/', 'Redirection points to IdP' ) or explain( $res->[1], 'location => http://auth.idp.com/cas/login?service=http://auth.sp.com/' ); # Query IdP switch ('issuer'); ok( $res = $issuer->_get( '/cas/login', query => 'service=http://auth.sp.com/', accept => 'text/html' ), 'Query CAS server' ); ok( $res->[0] == 200, 'Return code is 200' ) or explain( $res->[0], 200 ); # Try to authenticate to IdP my $body = $res->[2]->[0]; $body =~ s/^.*?//s; $body =~ s#.*$##s; my %fields = ( $body =~ /getHeader( $res, 'Content-Type' ) =~ m#^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(4); 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', issuerDBCASActivation => 1, casAttr => 'uid', casAttributes => { cn => 'cn', uid => 'uid', }, casAccessControlPolicy => 'none', } } ); } sub sp { return LLNG::Manager::Test->new( { ini => { logLevel => $debug, domain => 'sp.com', portal => 'http://auth.sp.com', authentication => 'CAS', userDB => 'Null', issuerDBCASActivation => 0, CASurl => 'http://auth.idp.com/cas', CASCAFile => 't/caFile.pem', }, } ); }