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

@ -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

@ -25,16 +25,21 @@ sub register {
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;
}
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 {
return LWP::Protocol::PSGI::Guard->new(
sub {
$class->unregister_app($app);
});
}
);
}
}
@ -51,7 +56,6 @@ sub unregister_app {
}
}
sub unregister {
my $class = shift;
for my $proto (@protocols) {
@ -71,8 +75,10 @@ sub request {
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);
}
else {
$orig{ $self->{scheme} }->new( $self->{scheme}, $self->{ua} )
->request( $request, $proxy, $arg, @rest );
}
}
@ -93,8 +99,7 @@ sub handles {
}
}
package
LWP::Protocol::PSGI::Guard;
package LWP::Protocol::PSGI::Guard;
use strict;
sub new {
@ -107,8 +112,7 @@ sub DESTROY {
$self->();
}
package
LWP::Protocol::PSGI::App;
package LWP::Protocol::PSGI::App;
use strict;
sub new {
@ -118,16 +122,20 @@ sub new {
sub app { $_[0]->{app} }
sub options { $_[0]->{options} }
sub match {
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}) {
$matcher->( $request->uri->host )
|| $matcher->( $request->uri->host_port );
}
elsif ( $options->{uri} ) {
$self->_matcher( $options->{uri} )->( $request->uri );
} else {
}
else {
1;
}
}
@ -136,11 +144,14 @@ sub _matcher {
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 {
}
else {
Carp::croak( "Don't know how to match: ", ref $stuff );
}
}

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" );

View File

@ -100,7 +100,8 @@ sub params {
$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);
$res{SFAManagment} =
$self->p->_sfEngine->display2fRegisters( $req, $req->userData );
$self->logger->debug( "Display 2fRegisters link ? " . $res{SFAManagment} );
return %res;

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

@ -20,7 +20,8 @@ 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 $query = $2;
@ -87,8 +88,7 @@ LWP::Protocol::PSGI->register(
'Unauth CDA request'
);
my ( $host, $url, $query ) = expectForm( $res, undef, undef, 'url' );
ok( $query =~ /\burl=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv\b/,
' check url value' );
ok( $query =~ /\burl=aHR0cDovL3Rlc3QuZXhhbXBsZS5vcmcv\b/, ' check url value' );
# Authentification
$query .= '&user=dwho&password=dwho';
@ -102,8 +102,7 @@ LWP::Protocol::PSGI->register(
);
($query) =
expectRedirection( $res,
qr#^http://test.example.org/\?(lemonldapcda=.*)$# );
expectRedirection( $res, qr#^http://test.example.org/\?(lemonldapcda=.*)$# );
# Handler part
use_ok('Lemonldap::NG::Handler::Server');