AuthProxy seems OK (#595)

This commit is contained in:
Xavier Guimard 2016-06-07 21:04:24 +00:00
parent e6ecba40a5
commit d7fca6d396
3 changed files with 46 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package Lemonldap::NG::Portal::Lib::Proxy;
use strict;
use Mouse;
use SOAP::Lite;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_BADCREDENTIALS);
our $VERSION = '2.0.0';
@ -23,11 +24,11 @@ sub init {
sub proxyQuery {
my ( $self, $req ) = @_;
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');
my $r = $soap->getCookies( $self->{user}, $self->{password} );
my $r = $soap->getCookies( $req->{user}, $req->datas->{password} );
if ( $r->fault ) {
$req->lmLog(
$self->lmLog(
"Unable to query authentication service: "
. $r->fault->{faultstring},
'error'
@ -37,9 +38,9 @@ sub proxyQuery {
my $res = $r->result();
# If authentication failed, display error
if ( $res->{error} ) {
$self->userError( "Authentication failed for $self->{user}: "
. $soap->error( $res->{error} )->result() );
if ( $res->{errorCode} ) {
$self->p->userError(
"Authentication failed for $req->{user}: error $res->{errorCode}");
return PE_BADCREDENTIALS;
}
unless ( $req->datas->{_remoteId} =

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

View File

@ -1,19 +1,18 @@
use Test::More;
use Test::More tests => 12;
use strict;
use IO::String;
my $res;
my $file = 't/notifications.db';
eval { unlink $file };
require 't/test-lib.pm';
SKIP: {
eval { require DBI; require DBD::SQLite; };
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");
$dbh->do(
'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;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
count(3);
# Verify that cookie is ciphered (session unvalid)
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" )
or explain( [ $res->[0], $res->[1] ], 401 );
count(2);
# Try to validate notification without accepting it
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" )
or explain( [ $res->[0], $res->[1] ], 200 );
count(2);
# Try to validate notification
$str =
@ -113,12 +109,10 @@ qq{INSERT INTO notifications VALUES ('dwho','testref','2016-05-30 00:00:00','<?x
my $i = 0;
while ( $sth->fetchrow_hashref ) { $i++ }
ok( $i == 1, 'Notification was deleted' );
count(3);
clean_sessions();
eval { unlink $file };
}
done_testing( eval { count() } );