From 643b247f48f81bd72e322ed9e715908cb9ae45ad Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Mon, 22 Jan 2024 22:12:01 +0100 Subject: [PATCH 1/4] Reset handler shared variables when switching handler --- lemonldap-ng-portal/t/test-lib.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lemonldap-ng-portal/t/test-lib.pm b/lemonldap-ng-portal/t/test-lib.pm index 58ba5e7618..897e4fbcdb 100644 --- a/lemonldap-ng-portal/t/test-lib.pm +++ b/lemonldap-ng-portal/t/test-lib.pm @@ -702,6 +702,7 @@ sub tempdb { } my %handlerOR; +my %handlerTSHV; =head4 register @@ -714,10 +715,24 @@ sub register { my ( $type, $constructor ) = @_; my $obj; @Lemonldap::NG::Handler::Main::_onReload = (); + $Lemonldap::NG::Handler::Main::_tshv = { + tsv => {}, + cfgNum => 0, + cfgDate => 0, + lastCheck => 0, + checkTime => 600, + confAcc => {}, + logger => {}, + userLogger => {}, + lmConf => {}, + localConfig => {}, + }; + &Lemonldap::NG::Handler::Main::cfgNum( 0, 0 ); ok( $obj = $constructor->(), 'Register $type' ); count(1); - $handlerOR{$type} = \@Lemonldap::NG::Handler::Main::_onReload; + $handlerOR{$type} = \@Lemonldap::NG::Handler::Main::_onReload; + $handlerTSHV{$type} = $Lemonldap::NG::Handler::Main::_tshv; return $obj; } @@ -734,6 +749,8 @@ sub switch { @Lemonldap::NG::Handler::Main::_onReload = @{ $handlerOR{$type}; }; + + $Lemonldap::NG::Handler::Main::_tshv = $handlerTSHV{$type}; } =head4 encodeUrl( $url ); -- GitLab From f661a8b7da422b9b5db0151024ceb252c0ddb62f Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Mon, 22 Jan 2024 22:30:45 +0100 Subject: [PATCH 2/4] Fix CAS unit test --- lemonldap-ng-portal/t/31-Auth-and-issuer-CAS-Logout-20.t | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lemonldap-ng-portal/t/31-Auth-and-issuer-CAS-Logout-20.t b/lemonldap-ng-portal/t/31-Auth-and-issuer-CAS-Logout-20.t index 459e5fe3c3..62a23c254e 100644 --- a/lemonldap-ng-portal/t/31-Auth-and-issuer-CAS-Logout-20.t +++ b/lemonldap-ng-portal/t/31-Auth-and-issuer-CAS-Logout-20.t @@ -61,6 +61,7 @@ $issuer = register( 'issuer', \&issuer ); $sp = register( 'sp', \&sp ); # Simple SP access +switch ('sp'); ok( $res = $sp->_get( '/', accept => 'text/html', @@ -188,9 +189,9 @@ sub issuer { casAttributes => { cn => 'cn', uid => 'uid', }, casAccessControlPolicy => 'none', multiValuesSeparator => ';', - "locationRules" => { - "test1.idp.com" => { - "default" => "accept" + casAppMetaDataOptions => { + myapp => { + casAppMetaDataOptionsService => "http://test1.idp.com", }, }, } -- GitLab From b5fb0db5e7862848f5d75d25444af65a9ad14636 Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Mon, 22 Jan 2024 22:44:17 +0100 Subject: [PATCH 3/4] Fix SOAP/REST config tests --- lemonldap-ng-portal/t/35-REST-config-backend.t | 3 +++ lemonldap-ng-portal/t/35-SOAP-config-backend.t | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lemonldap-ng-portal/t/35-REST-config-backend.t b/lemonldap-ng-portal/t/35-REST-config-backend.t index 0478fb9523..c46f11dc76 100644 --- a/lemonldap-ng-portal/t/35-REST-config-backend.t +++ b/lemonldap-ng-portal/t/35-REST-config-backend.t @@ -20,11 +20,13 @@ LWP::Protocol::PSGI->register( $req->uri =~ m#http://auth.idp.com(.*?)(?:\?(.*))?$#, ' @ REST request (' . $req->method . " $1)" ); + switch ('issuer'); count(1); my $url = $1; my $query = $2; my $res; my $s = $req->content; + if ( $req->method =~ /^(post|put)$/i ) { my $mth = '_' . lc($1); my $s = $req->content; @@ -58,6 +60,7 @@ LWP::Protocol::PSGI->register( } pass(' @ END OF REST REQUEST'); count(1); + switch ('sp'); return $res; } ); diff --git a/lemonldap-ng-portal/t/35-SOAP-config-backend.t b/lemonldap-ng-portal/t/35-SOAP-config-backend.t index 06d1fc7489..9008aa5682 100644 --- a/lemonldap-ng-portal/t/35-SOAP-config-backend.t +++ b/lemonldap-ng-portal/t/35-SOAP-config-backend.t @@ -24,6 +24,7 @@ LWP::Protocol::PSGI->register( my $res; my $s = $req->content; my $client = ( $host eq 'idp' ? $issuer : $sp ); + switch ( ( $host eq 'idp' ? 'issuer' : 'sp' ) ); ok( $res = $client->_post( $url, @@ -42,6 +43,7 @@ LWP::Protocol::PSGI->register( or explain( $res->[1], 'Content-Type => application/xml' ); pass(' @ END OF SOAP REQUEST @'); count(4); + switch ( ( $host eq 'idp' ? 'sp' : 'issuer' ) ); return $res; } ); -- GitLab From 4de9db68b627a10f2c3bd2604395a49e1dea0cb7 Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Mon, 22 Jan 2024 22:47:36 +0100 Subject: [PATCH 4/4] Unit test for handler switching --- lemonldap-ng-portal/t/00-Switch.t | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 lemonldap-ng-portal/t/00-Switch.t diff --git a/lemonldap-ng-portal/t/00-Switch.t b/lemonldap-ng-portal/t/00-Switch.t new file mode 100644 index 0000000000..7a4cb15a1e --- /dev/null +++ b/lemonldap-ng-portal/t/00-Switch.t @@ -0,0 +1,51 @@ +use warnings; +use Test::More; +use strict; +use IO::String; +use MIME::Base64; +use URI; +use URI::QueryParam; + +require 't/test-lib.pm'; + +my $res; + +my $client = register( + 'client1', + sub { + LLNG::Manager::Test->new( { + ini => { + portal => 'https://auth.example.com/', + } + } + ); + } +); + +my $client2 = register( + 'client2', + sub { + LLNG::Manager::Test->new( { + ini => { + portal => 'https://auth.example2.com/', + } + } + ); + } +); + +switch ("client1"); +is( Lemonldap::NG::Handler::Main->tsv->{portal}->(), + 'https://auth.example.com/' ); +switch ("client2"); +is( Lemonldap::NG::Handler::Main->tsv->{portal}->(), + 'https://auth.example2.com/' ); +switch ("client1"); +is( Lemonldap::NG::Handler::Main->tsv->{portal}->(), + 'https://auth.example.com/' ); +switch ("client2"); +is( Lemonldap::NG::Handler::Main->tsv->{portal}->(), + 'https://auth.example2.com/' ); +count(4); + +done_testing( count() ); -- GitLab