AuthProxy seems OK (#595)
This commit is contained in:
parent
e6ecba40a5
commit
d7fca6d396
|
@ -2,6 +2,7 @@ package Lemonldap::NG::Portal::Lib::Proxy;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Mouse;
|
use Mouse;
|
||||||
|
use SOAP::Lite;
|
||||||
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_BADCREDENTIALS);
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_BADCREDENTIALS);
|
||||||
|
|
||||||
our $VERSION = '2.0.0';
|
our $VERSION = '2.0.0';
|
||||||
|
@ -23,11 +24,11 @@ sub init {
|
||||||
sub proxyQuery {
|
sub proxyQuery {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
return PE_OK if ( $req->datas->{_proxyQueryDone} );
|
return PE_OK if ( $req->datas->{_proxyQueryDone} );
|
||||||
my $soap = SOAP::Lite->proxy( $self->conf->{soapAuthService} )
|
my $soap = SOAP::Lite->proxy( $self->conf->{soapSessionService} )
|
||||||
->uri('urn:Lemonldap::NG::Common::CGI::SOAPService');
|
->uri('urn:Lemonldap::NG::Common::CGI::SOAPService');
|
||||||
my $r = $soap->getCookies( $self->{user}, $self->{password} );
|
my $r = $soap->getCookies( $req->{user}, $req->datas->{password} );
|
||||||
if ( $r->fault ) {
|
if ( $r->fault ) {
|
||||||
$req->lmLog(
|
$self->lmLog(
|
||||||
"Unable to query authentication service: "
|
"Unable to query authentication service: "
|
||||||
. $r->fault->{faultstring},
|
. $r->fault->{faultstring},
|
||||||
'error'
|
'error'
|
||||||
|
@ -37,9 +38,9 @@ sub proxyQuery {
|
||||||
my $res = $r->result();
|
my $res = $r->result();
|
||||||
|
|
||||||
# If authentication failed, display error
|
# If authentication failed, display error
|
||||||
if ( $res->{error} ) {
|
if ( $res->{errorCode} ) {
|
||||||
$self->userError( "Authentication failed for $self->{user}: "
|
$self->p->userError(
|
||||||
. $soap->error( $res->{error} )->result() );
|
"Authentication failed for $req->{user}: error $res->{errorCode}");
|
||||||
return PE_BADCREDENTIALS;
|
return PE_BADCREDENTIALS;
|
||||||
}
|
}
|
||||||
unless ( $req->datas->{_remoteId} =
|
unless ( $req->datas->{_remoteId} =
|
||||||
|
|
36
lemonldap-ng-portal/t/08-AuthProxy.t
Normal file
36
lemonldap-ng-portal/t/08-AuthProxy.t
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
use Test::More;
|
||||||
|
use strict;
|
||||||
|
use IO::String;
|
||||||
|
|
||||||
|
my $res;
|
||||||
|
|
||||||
|
SKIP: {
|
||||||
|
skip 'REMOTELLNG is not set', 10 unless ( $ENV{REMOTELLNG} );
|
||||||
|
require 't/test-lib.pm';
|
||||||
|
init(
|
||||||
|
{
|
||||||
|
logLevel => 'error',
|
||||||
|
useSafeJail => 1,
|
||||||
|
authentication => 'Proxy',
|
||||||
|
userDB => 'Proxy',
|
||||||
|
soapAuthService => $ENV{REMOTELLNG},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
ok(
|
||||||
|
$res = &client->_post(
|
||||||
|
'/',
|
||||||
|
IO::String->new('user=dwho&password=dwho'),
|
||||||
|
length => 23
|
||||||
|
),
|
||||||
|
'Auth query'
|
||||||
|
);
|
||||||
|
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
|
||||||
|
my $cookies = getCookies($res);
|
||||||
|
my $id;
|
||||||
|
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
|
||||||
|
or explain( $res, 'Set-Cookie: something' );
|
||||||
|
|
||||||
|
logout($id);
|
||||||
|
clean_sessions();
|
||||||
|
}
|
||||||
|
done_testing(10);
|
|
@ -1,19 +1,18 @@
|
||||||
use Test::More;
|
use Test::More tests => 12;
|
||||||
use strict;
|
use strict;
|
||||||
use IO::String;
|
use IO::String;
|
||||||
|
|
||||||
my $res;
|
my $res;
|
||||||
my $file = 't/notifications.db';
|
my $file = 't/notifications.db';
|
||||||
eval { unlink $file };
|
eval { unlink $file };
|
||||||
|
require 't/test-lib.pm';
|
||||||
|
|
||||||
SKIP: {
|
SKIP: {
|
||||||
eval { require DBI; require DBD::SQLite; };
|
eval { require DBI; require DBD::SQLite; };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
skip 'DBD::SQLite not found', 1;
|
skip 'DBD::SQLite not found', 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
require 't/test-lib.pm';
|
|
||||||
|
|
||||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$file");
|
my $dbh = DBI->connect("dbi:SQLite:dbname=$file");
|
||||||
$dbh->do(
|
$dbh->do(
|
||||||
'CREATE TABLE notifications (uid text,ref text,date datetime,xml text,cond text,done datetime)'
|
'CREATE TABLE notifications (uid text,ref text,date datetime,xml text,cond text,done datetime)'
|
||||||
|
@ -59,7 +58,6 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
|
||||||
my $id;
|
my $id;
|
||||||
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
|
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
|
||||||
or explain( $res, 'Set-Cookie: something' );
|
or explain( $res, 'Set-Cookie: something' );
|
||||||
count(3);
|
|
||||||
|
|
||||||
# Verify that cookie is ciphered (session unvalid)
|
# Verify that cookie is ciphered (session unvalid)
|
||||||
ok(
|
ok(
|
||||||
|
@ -72,7 +70,6 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
|
||||||
);
|
);
|
||||||
ok( $res->[0] == 401, "Session isn't valid" )
|
ok( $res->[0] == 401, "Session isn't valid" )
|
||||||
or explain( [ $res->[0], $res->[1] ], 401 );
|
or explain( [ $res->[0], $res->[1] ], 401 );
|
||||||
count(2);
|
|
||||||
|
|
||||||
# Try to validate notification without accepting it
|
# Try to validate notification without accepting it
|
||||||
my $str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
my $str = 'reference1x1=testref&url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==';
|
||||||
|
@ -88,7 +85,6 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
|
||||||
);
|
);
|
||||||
ok( $res->[0] == 200, "Don't receive redirection" )
|
ok( $res->[0] == 200, "Don't receive redirection" )
|
||||||
or explain( [ $res->[0], $res->[1] ], 200 );
|
or explain( [ $res->[0], $res->[1] ], 200 );
|
||||||
count(2);
|
|
||||||
|
|
||||||
# Try to validate notification
|
# Try to validate notification
|
||||||
$str =
|
$str =
|
||||||
|
@ -113,12 +109,10 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
while ( $sth->fetchrow_hashref ) { $i++ }
|
while ( $sth->fetchrow_hashref ) { $i++ }
|
||||||
ok( $i == 1, 'Notification was deleted' );
|
ok( $i == 1, 'Notification was deleted' );
|
||||||
count(3);
|
|
||||||
|
|
||||||
clean_sessions();
|
clean_sessions();
|
||||||
|
|
||||||
eval { unlink $file };
|
eval { unlink $file };
|
||||||
|
|
||||||
}
|
}
|
||||||
done_testing( eval { count() } );
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user