This commit is contained in:
Xavier Guimard 2018-06-21 21:35:16 +02:00
parent 7a83f4e84b
commit 4ebcae3e15
43 changed files with 238 additions and 227 deletions

View File

@ -53,9 +53,8 @@ sub load {
my ( $self, $cfgNum, $fields ) = @_;
$fields = $fields ? join( ",", @$fields ) : '*';
my $sth =
$self->_dbh->prepare( "SELECT field,value from "
. $self->{dbiTable}
. " WHERE cfgNum=?" );
$self->_dbh->prepare(
"SELECT field,value from " . $self->{dbiTable} . " WHERE cfgNum=?" );
$sth->execute($cfgNum);
my ( $res, @row );
while ( @row = $sth->fetchrow_array ) {

View File

@ -7,12 +7,12 @@ our $VERSION = '2.0.0';
sub new {
no warnings 'redefine';
my $self = bless {}, shift;
my ($conf,%args) = @_;
my ( $conf, %args ) = @_;
my %bck;
my $last;
my $show = 1;
my $root = $args{user} ? 'userLogDispatch' : 'logDispatch';
unless ( $conf->{$root.'Error'} ) {
unless ( $conf->{ $root . 'Error' } ) {
die "At least, ${root}Error must be defined in conf";
}
foreach my $l (qw(error warn notice info debug)) {

View File

@ -24,7 +24,7 @@ sub new {
if ($show) {
eval
qq'sub $_ {\$_[0]->{raven}->capture_message(\$_[1],level => "$rl")}';
die $@ if($@);
die $@ if ($@);
}
else {
eval qq'sub $_ {1}';

View File

@ -48,7 +48,8 @@ sub run {
return $class->REDIRECT;
}
}
return $class->Lemonldap::NG::Handler::Main::run( $req, $rule, $protection );
return $class->Lemonldap::NG::Handler::Main::run( $req, $rule,
$protection );
}
## @rmethod protected hash getCDAInfos(id)

View File

@ -235,7 +235,7 @@ sub sfa {
# Filter 2FA sessions if needed
$self->logger->debug("Filtering 2F sessions...");
my $all = ( keys %$res );
if ( $self->{U2FCheck} eq '2' ) {
foreach my $session ( keys %$res ) {
delete $res->{$session}
@ -262,7 +262,7 @@ sub sfa {
}
my $total = ( keys %$res );
$self->logger->debug("Session(s) left : $total / $all");
$self->logger->debug("Session(s) left : $total / $all");
if ( my $group = $req->params('groupBy') ) {
my $r;

View File

@ -20,59 +20,65 @@ sub register {
unshift @apps, $app;
# register this guy (as well as saving original code) once
if (! scalar keys %orig) {
if ( !scalar keys %orig ) {
for my $proto (@protocols) {
if (my $orig = LWP::Protocol::implementor($proto)) {
if ( my $orig = LWP::Protocol::implementor($proto) ) {
$orig{$proto} = $orig;
LWP::Protocol::implementor($proto, $class);
} else {
Carp::carp("LWP::Protocol::$proto is unavailable. Skip registering overrides for it.") if $^W;
LWP::Protocol::implementor( $proto, $class );
}
else {
Carp::carp(
"LWP::Protocol::$proto is unavailable. Skip registering overrides for it."
) if $^W;
}
}
}
if (defined wantarray) {
return LWP::Protocol::PSGI::Guard->new(sub {
$class->unregister_app($app);
});
if ( defined wantarray ) {
return LWP::Protocol::PSGI::Guard->new(
sub {
$class->unregister_app($app);
}
);
}
}
sub unregister_app {
my ($class, $app) = @_;
my ( $class, $app ) = @_;
my $i = 0;
foreach my $stored_app (@apps) {
if ($app == $stored_app) {
if ( $app == $stored_app ) {
splice @apps, $i, 1;
return;
}
$i++;
}
}
sub unregister {
my $class = shift;
for my $proto (@protocols) {
if ($orig{$proto}) {
LWP::Protocol::implementor($proto, $orig{$proto});
if ( $orig{$proto} ) {
LWP::Protocol::implementor( $proto, $orig{$proto} );
}
}
@apps = ();
}
sub request {
my($self, $request, $proxy, $arg, @rest) = @_;
my ( $self, $request, $proxy, $arg, @rest ) = @_;
if (my $app = $self->handles($request)) {
my $env = req_to_psgi $request;
if ( my $app = $self->handles($request) ) {
my $env = req_to_psgi $request;
my $response = res_from_psgi $app->app->($env);
my $content = $response->content;
my $content = $response->content;
$response->content('');
$self->collect_once($arg, $response, $content);
} else {
$orig{$self->{scheme}}->new($self->{scheme}, $self->{ua})->request($request, $proxy, $arg, @rest);
$self->collect_once( $arg, $response, $content );
}
else {
$orig{ $self->{scheme} }->new( $self->{scheme}, $self->{ua} )
->request( $request, $proxy, $arg, @rest );
}
}
@ -84,21 +90,20 @@ sub create {
}
sub handles {
my($self, $request) = @_;
my ( $self, $request ) = @_;
foreach my $app (@apps) {
if ($app->match($request)) {
if ( $app->match($request) ) {
return $app;
}
}
}
package
LWP::Protocol::PSGI::Guard;
package LWP::Protocol::PSGI::Guard;
use strict;
sub new {
my($class, $code) = @_;
my ( $class, $code ) = @_;
bless $code, $class;
}
@ -107,41 +112,47 @@ sub DESTROY {
$self->();
}
package
LWP::Protocol::PSGI::App;
package LWP::Protocol::PSGI::App;
use strict;
sub new {
my ($class, $app, %options) = @_;
my ( $class, $app, %options ) = @_;
bless { app => $app, options => \%options }, $class;
}
sub app { $_[0]->{app} }
sub app { $_[0]->{app} }
sub options { $_[0]->{options} }
sub match {
my ($self, $request) = @_;
my ( $self, $request ) = @_;
my $options = $self->options;
if ($options->{host}) {
my $matcher = $self->_matcher($options->{host});
$matcher->($request->uri->host) || $matcher->($request->uri->host_port);
} elsif ($options->{uri}) {
$self->_matcher($options->{uri})->($request->uri);
} else {
if ( $options->{host} ) {
my $matcher = $self->_matcher( $options->{host} );
$matcher->( $request->uri->host )
|| $matcher->( $request->uri->host_port );
}
elsif ( $options->{uri} ) {
$self->_matcher( $options->{uri} )->( $request->uri );
}
else {
1;
}
}
sub _matcher {
my($self, $stuff) = @_;
if (ref $stuff eq 'Regexp') {
my ( $self, $stuff ) = @_;
if ( ref $stuff eq 'Regexp' ) {
sub { $_[0] =~ $stuff };
} elsif (ref $stuff eq 'CODE') {
}
elsif ( ref $stuff eq 'CODE' ) {
$stuff;
} elsif (!ref $stuff) {
}
elsif ( !ref $stuff ) {
sub { $_[0] eq $stuff };
} else {
Carp::croak("Don't know how to match: ", ref $stuff);
}
else {
Carp::croak( "Don't know how to match: ", ref $stuff );
}
}

View File

@ -111,13 +111,13 @@ sub init {
# run() is called at each authentication, just after sessionInfo populated
sub run {
my ( $self, $req ) = @_;
my $checkLogins = $req->param('checkLogins');
$self->logger->debug("2F checkLogins set") if ($checkLogins);
# Skip 2F unless a module has been registered
return PE_OK unless ( @{ $self->sfModules } );
# Search for authorized modules for this user
my @am;
foreach my $m ( @{ $self->sfModules } ) {
@ -128,7 +128,7 @@ sub run {
push @am, $m->{m};
}
}
# If no 2F module is authorized, skipping 2F
# Note that a rule may forbid access after (GrantSession plugin)
return PE_OK unless (@am);

View File

@ -34,7 +34,7 @@ sub init {
sub run {
my ( $self, $req, $token ) = @_;
my $checkLogins = $req->param('checkLogins');
$self->logger->debug("Ext2F checkLogins set") if ($checkLogins);
@ -51,8 +51,8 @@ sub run {
$req,
'ext2fcheck',
params => {
SKIN => $self->conf->{portalSkin},
TOKEN => $token,
SKIN => $self->conf->{portalSkin},
TOKEN => $token,
CHECKLOGINS => $checkLogins
}
);

View File

@ -55,7 +55,7 @@ sub init {
sub run {
my ( $self, $req, $token ) = @_;
my $checkLogins = $req->param('checkLogins');
$self->logger->debug("REST2F checkLogins set") if ($checkLogins);
@ -89,9 +89,9 @@ sub run {
$req,
'ext2fcheck',
params => {
SKIN => $self->conf->{portalSkin},
TOKEN => $token,
TARGET => '/rest2fcheck',
SKIN => $self->conf->{portalSkin},
TOKEN => $token,
TARGET => '/rest2fcheck',
CHECKLOGINS => $checkLogins
}
);

View File

@ -213,7 +213,8 @@ sub run {
}
my ( $err, $error ) = $self->loadUser($req);
if ( $err == -1 ) {
return $self->p->sendError( $req, "U2F loading error: $error", 500 );
return $self->p->sendError( $req, "U2F loading error: $error",
500 );
}
elsif ( $err == 0 ) {
return $self->p->sendError( $req, "noU2FKeyFound" );
@ -362,7 +363,7 @@ sub loadUser {
$uk = $_->{_userKey};
my $c = $self->crypter( keyHandle => $kh, publicKey => $uk );
if ($c) {
$self->logger->debug("kh & uk -> OK");
$self->logger->debug("kh & uk -> OK");
push @crypters, $c;
}
else {

View File

@ -44,7 +44,7 @@ sub init {
sub run {
my ( $self, $req, $token ) = @_;
$self->logger->debug('Generate TOTP form');
my $checkLogins = $req->param('checkLogins');
$self->logger->debug("TOTP checkLogins set") if ($checkLogins);
@ -53,8 +53,8 @@ sub run {
$req,
'totp2fcheck',
params => {
SKIN => $self->conf->{portalSkin},
TOKEN => $token,
SKIN => $self->conf->{portalSkin},
TOKEN => $token,
CHECKLOGINS => $checkLogins
}
);

View File

@ -62,10 +62,10 @@ sub init {
sub run {
my ( $self, $req, $token, $_2fDevices ) = @_;
my $checkLogins = $req->param('checkLogins');
$self->logger->debug("Yubikey checkLogins set") if ($checkLogins);
my $yubikey = 0;
if ( $req->{sessionInfo}->{_2fDevices} ) {
$self->logger->debug("Loading 2F Devices ...");
@ -103,11 +103,11 @@ sub run {
$req,
'ext2fcheck',
params => {
SKIN => $self->conf->{portalSkin},
TOKEN => $token,
TARGET => '/yubikey2fcheck',
INPUTLOGO => 'yubikey.png',
LEGEND => 'clickOnYubikey',
SKIN => $self->conf->{portalSkin},
TOKEN => $token,
TARGET => '/yubikey2fcheck',
INPUTLOGO => 'yubikey.png',
LEGEND => 'clickOnYubikey',
CHECKLOGINS => $checkLogins
}
);

View File

@ -69,7 +69,7 @@ qr/^($saml_slo_soap_url|$saml_slo_soap_url_ret|$saml_slo_get_url|$saml_slo_get_u
my $saml_ars_url = $self->getMetaDataURL(
"samlSPSSODescriptorArtifactResolutionServiceArtifact");
$self->artRe(qr/^($saml_ars_url)(?:\?.*)?$/i);
$self->catch($self->sloAssConsumerRe);
$self->catch( $self->sloAssConsumerRe );
# Load SAML service and SAML IdP list
return ( $self->SUPER::init and $self->loadIDPs );

View File

@ -94,14 +94,15 @@ sub params {
$req->param("tab") // '' )
|| "applist";
}
$res{DISPLAY_MODULES} = $self->displayModules($req);
$res{AUTH_ERROR_TYPE} =
$req->error_type( $res{AUTH_ERROR} = $req->menuError );
# Display menu 2fRegisters link only if at least a 2F device is registered
$res{SFAManagment} = $self->p->_sfEngine->display2fRegisters($req, $req->userData);
$self->logger->debug( "Display 2fRegisters link ? ". $res{SFAManagment} );
$res{SFAManagment} =
$self->p->_sfEngine->display2fRegisters( $req, $req->userData );
$self->logger->debug( "Display 2fRegisters link ? " . $res{SFAManagment} );
return %res;
}

View File

@ -56,7 +56,7 @@ sub _redirect {
sub _verify {
my ( $self, $req ) = @_;
my $checkLogins = $req->param('checkLogins');
$self->logger->debug("checkLogins set") if ($checkLogins);

View File

@ -52,7 +52,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -51,7 +51,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -35,7 +35,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -35,7 +35,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -35,7 +35,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -35,7 +35,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -47,7 +47,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -35,7 +35,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -35,7 +35,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -58,7 +58,7 @@ ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
count(1);
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
count(1);

View File

@ -56,7 +56,7 @@ ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
count(1);
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
count(1);
@ -256,14 +256,14 @@ sub sp {
casSrvMetaDataOptions => {
idp => {
casSrvMetaDataOptionsUrl => 'http://auth.idp.com/cas',
casSrvMetaDataOptionsGateway => 0,
casSrvMetaDataOptionsGateway => 0,
}
},
casSrvMetaDataOptionsProxiedServices => {
idp => {
test => 'http://test.sp.com/',
test => 'http://test.sp.com/',
}
},
},
},
}
);

View File

@ -75,7 +75,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
# Build CAS app
ok( $sp = sp(), 'SP portal' );

View File

@ -158,8 +158,7 @@ count(1);
# Verify UTF-8
ok(
$res = $op->_get(
'/oauth2/userinfo',
query => 'access_token=' . $access_token,
'/oauth2/userinfo', query => 'access_token=' . $access_token,
),
'Get userinfo'
);

View File

@ -52,7 +52,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -64,7 +64,7 @@ LWP::Protocol::PSGI->register(
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -57,7 +57,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -71,7 +71,7 @@ count(1);
expectOK($res);
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -64,7 +64,7 @@ LWP::Protocol::PSGI->register(
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -68,7 +68,7 @@ SKIP: {
# Test SP access
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -55,7 +55,7 @@ SKIP: {
ok( $issuer = issuer(), 'Issuer portal' );
$handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'SP portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -96,7 +96,7 @@ SKIP: {
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('rp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $rp = rp( $jwks, $metadata ), 'RP portal' );
$handlerOR{rp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -78,7 +78,7 @@ SKIP: {
$handlerOR{idp} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'Proxy portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -78,7 +78,7 @@ SKIP: {
$handlerOR{idp} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('sp');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $sp = sp(), 'Proxy portal' );
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -96,7 +96,7 @@ SKIP: {
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('proxy');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $proxy = proxy( $jwks, $metadata ), 'Proxy portal' );
$handlerOR{proxy} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -96,7 +96,7 @@ SKIP: {
$handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;
switch ('proxy');
&Lemonldap::NG::Handler::Main::cfgNum(0,0);
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
ok( $proxy = proxy( $jwks, $metadata ), 'Proxy portal' );
$handlerOR{proxy} = \@Lemonldap::NG::Handler::Main::_onReload;

View File

@ -58,7 +58,7 @@ use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib');
count(2);
my ( $cli, $app );
switch('app');
switch ('app');
ok( $app = Lemonldap::NG::Handler::Server->run( $client->ini ), 'App' );
count(1);

View File

@ -20,9 +20,10 @@ my $client;
LWP::Protocol::PSGI->register(
sub {
my $req = Plack::Request->new(@_);
ok( $req->uri =~ m#http://auth.example.com(.*?)(?:\?(.*))?$#, " @ REST REQUEST @" );
ok( $req->uri =~ m#http://auth.example.com(.*?)(?:\?(.*))?$#,
" @ REST REQUEST @" );
count(1);
my $url = $1;
my $url = $1;
my $query = $2;
my $res;
switch ('portal');
@ -31,10 +32,10 @@ LWP::Protocol::PSGI->register(
my $s = $req->content;
ok(
$res = $client->$mth(
$url,
IO::String->new($s),
length => length($s),
type => $req->header('Content-Type'),
$url,
IO::String->new($s),
length => length($s),
type => $req->header('Content-Type'),
),
' Post request'
);
@ -45,10 +46,10 @@ LWP::Protocol::PSGI->register(
my $mth = '_' . lc($1);
ok(
$res = $client->$mth(
$url,
accept => $req->header('Accept'),
cookie => $req->header('Cookie'),
query => $query,
$url,
accept => $req->header('Accept'),
cookie => $req->header('Cookie'),
query => $query,
),
' Execute request'
);
@ -64,120 +65,118 @@ LWP::Protocol::PSGI->register(
}
);
$client = LLNG::Manager::Test->new(
{
ini => {
logLevel => $debug,
useSafeJail => 1,
cda => 1,
restSessionServer => 1,
logger => 'Lemonldap::NG::Common::Logger::Std',
}
$client = LLNG::Manager::Test->new(
{
ini => {
logLevel => $debug,
useSafeJail => 1,
cda => 1,
restSessionServer => 1,
logger => 'Lemonldap::NG::Common::Logger::Std',
}
);
$handlerOR{portal} = \@Lemonldap::NG::Handler::Main::_onReload;
}
);
$handlerOR{portal} = \@Lemonldap::NG::Handler::Main::_onReload;
# CDA with unauthentified user
ok(
$res = $client->_get(
'/',
query => 'url=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv',
accept => 'text/html',
),
'Unauth CDA request'
);
my ( $host, $url, $query ) = expectForm( $res, undef, undef, 'url' );
ok( $query =~ /\burl=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv\b/,
' check url value' );
# CDA with unauthentified user
ok(
$res = $client->_get(
'/',
query => 'url=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv',
accept => 'text/html',
),
'Unauth CDA request'
);
my ( $host, $url, $query ) = expectForm( $res, undef, undef, 'url' );
ok( $query =~ /\burl=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv\b/, ' check url value' );
# Authentification
$query .= '&user=dwho&password=dwho';
ok(
$res = $client->_post(
'/' => IO::String->new($query),
length => length($query),
accept => 'text/html',
),
'Post credentials'
);
# Authentification
$query .= '&user=dwho&password=dwho';
ok(
$res = $client->_post(
'/' => IO::String->new($query),
length => length($query),
accept => 'text/html',
),
'Post credentials'
);
($query) =
expectRedirection( $res,
qr#^http://test.example.org/\?(lemonldapcda=.*)$# );
($query) =
expectRedirection( $res, qr#^http://test.example.org/\?(lemonldapcda=.*)$# );
# Handler part
use_ok('Lemonldap::NG::Handler::Server');
use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib');
# Handler part
use_ok('Lemonldap::NG::Handler::Server');
use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib');
my ( $cli, $app );
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
switch ('app');
ok(
$app = Lemonldap::NG::Handler::Server->run(
{
%{ $client->ini },
globalStorage => 'Lemonldap::NG::Common::Apache::Session::REST',
globalStorageOptions =>
{ baseUrl => 'http://auth.example.com/sessions/global/' },
localSessionStorage => undef,
}
),
'App'
);
my ( $cli, $app );
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
switch ('app');
ok(
$app = Lemonldap::NG::Handler::Server->run(
{
%{ $client->ini },
globalStorage => 'Lemonldap::NG::Common::Apache::Session::REST',
globalStorageOptions =>
{ baseUrl => 'http://auth.example.com/sessions/global/' },
localSessionStorage => undef,
}
),
'App'
);
ok(
$res = $app->(
{
'HTTP_ACCEPT' => 'text/html',
'SCRIPT_NAME' => '/',
'SERVER_NAME' => '127.0.0.1',
'QUERY_STRING' => $query,
'HTTP_CACHE_CONTROL' => 'max-age=0',
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'PATH_INFO' => '/',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => "/?$query",
'X_ORIGINAL_URI' => "/?$query",
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'HTTP_USER_AGENT' =>
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox',
'REMOTE_ADDR' => '127.0.0.1',
'HTTP_HOST' => 'test.example.org',
'VHOSTTYPE' => 'CDA',
}
),
'Push cda cookie'
);
expectRedirection( $res, 'http://test.example.org/' );
my $cid = expectCookie($res);
ok(
$res = $app->(
{
'HTTP_ACCEPT' => 'text/html',
'SCRIPT_NAME' => '/',
'SERVER_NAME' => '127.0.0.1',
'QUERY_STRING' => $query,
'HTTP_CACHE_CONTROL' => 'max-age=0',
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'PATH_INFO' => '/',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => "/?$query",
'X_ORIGINAL_URI' => "/?$query",
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'HTTP_USER_AGENT' =>
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox',
'REMOTE_ADDR' => '127.0.0.1',
'HTTP_HOST' => 'test.example.org',
'VHOSTTYPE' => 'CDA',
}
),
'Push cda cookie'
);
expectRedirection( $res, 'http://test.example.org/' );
my $cid = expectCookie($res);
ok(
$res = $app->(
{
'HTTP_ACCEPT' => 'text/html',
'SCRIPT_NAME' => '/',
'SERVER_NAME' => '127.0.0.1',
'HTTP_COOKIE' => "lemonldap=$cid",
'HTTP_CACHE_CONTROL' => 'max-age=0',
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'PATH_INFO' => '/',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => "/",
'X_ORIGINAL_URI' => "/",
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'HTTP_USER_AGENT' =>
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox',
'REMOTE_ADDR' => '127.0.0.1',
'HTTP_HOST' => 'test.example.org',
'VHOSTTYPE' => 'CDA',
}
),
'Authenticated query'
);
expectOK($res);
expectAuthenticatedAs( $res, 'dwho' );
ok(
$res = $app->(
{
'HTTP_ACCEPT' => 'text/html',
'SCRIPT_NAME' => '/',
'SERVER_NAME' => '127.0.0.1',
'HTTP_COOKIE' => "lemonldap=$cid",
'HTTP_CACHE_CONTROL' => 'max-age=0',
'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'PATH_INFO' => '/',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => "/",
'X_ORIGINAL_URI' => "/",
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'HTTP_USER_AGENT' =>
'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox',
'REMOTE_ADDR' => '127.0.0.1',
'HTTP_HOST' => 'test.example.org',
'VHOSTTYPE' => 'CDA',
}
),
'Authenticated query'
);
expectOK($res);
expectAuthenticatedAs( $res, 'dwho' );
clean_sessions();

View File

@ -57,7 +57,7 @@ use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib');
count(2);
my ( $cli, $app );
switch('app');
switch ('app');
ok( $app = Lemonldap::NG::Handler::Server->run( $client->ini ), 'App' );
count(1);