From d7fca6d396c49c062eede08834f98b4009e5dd86 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Tue, 7 Jun 2016 21:04:24 +0000 Subject: [PATCH] AuthProxy seems OK (#595) --- .../lib/Lemonldap/NG/Portal/Lib/Proxy.pm | 13 +++---- lemonldap-ng-portal/t/08-AuthProxy.t | 36 +++++++++++++++++++ lemonldap-ng-portal/t/11-Notifications-DBI.t | 12 ++----- 3 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 lemonldap-ng-portal/t/08-AuthProxy.t diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Proxy.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Proxy.pm index aeb6c3881..ba964b20d 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Proxy.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Proxy.pm @@ -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} = diff --git a/lemonldap-ng-portal/t/08-AuthProxy.t b/lemonldap-ng-portal/t/08-AuthProxy.t new file mode 100644 index 000000000..9ce89763a --- /dev/null +++ b/lemonldap-ng-portal/t/08-AuthProxy.t @@ -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); diff --git a/lemonldap-ng-portal/t/11-Notifications-DBI.t b/lemonldap-ng-portal/t/11-Notifications-DBI.t index 1b0f1e2a1..0d13251e1 100644 --- a/lemonldap-ng-portal/t/11-Notifications-DBI.t +++ b/lemonldap-ng-portal/t/11-Notifications-DBI.t @@ -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','{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','[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','[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','fetchrow_hashref ) { $i++ } ok( $i == 1, 'Notification was deleted' ); - count(3); clean_sessions(); eval { unlink $file }; } -done_testing( eval { count() } );