From 3096fdaf72bdfa1d083feb6538d4e69a48b35cff Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Thu, 16 Dec 2021 12:14:23 +0100 Subject: [PATCH] Fix unit test for relaystate (#2671) --- lemonldap-ng-portal/t/30-SAML-RelayState.t | 48 +++++++++++----------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/lemonldap-ng-portal/t/30-SAML-RelayState.t b/lemonldap-ng-portal/t/30-SAML-RelayState.t index 19b96c98f..a4ff86c6e 100644 --- a/lemonldap-ng-portal/t/30-SAML-RelayState.t +++ b/lemonldap-ng-portal/t/30-SAML-RelayState.t @@ -1,4 +1,3 @@ -use Lemonldap::NG::Portal::Lib::SAML; use lib 'inc'; use Test::More; use strict; @@ -9,8 +8,6 @@ use MIME::Base64; use URI; use URI::QueryParam; -my $saml = Lemonldap::NG::Portal::Lib::SAML->new(); - BEGIN { require 't/test-lib.pm'; require 't/saml-lib.pm'; @@ -29,12 +26,14 @@ LWP::Protocol::PSGI->register( return [ 500, [], [] ]; } ); +our $saml; SKIP: { - eval "use Lasso"; + eval "use Lasso; use Lemonldap::NG::Portal::Lib::SAML;"; if ($@) { - skip 'Lasso not found', $maintests; + skip 'Lasso not found'; } + $saml = Lemonldap::NG::Portal::Lib::SAML->new(); # Initialization my $issuer = register( 'issuer', \&issuer ); @@ -71,31 +70,30 @@ SKIP: { '{"url": "http://test/%22"}', "Correct html encoding of special characters in RelayState" ); + + sub getAuthnRequest { + my ($method) = @_; + + my $server = Lasso::Server::new_from_buffers( + samlProxyMetaDataXML( "proxy", $method ), + saml_key_proxy_private_sig(), + undef, undef + ); + $server->add_provider_from_buffer( 2, + samlIDPMetaDataXML( "idp", $method ) ); + + my $login = Lasso::Login->new($server); + my $method = $saml->getHttpMethod($method); + $login->init_authn_request("http://auth.idp.com/saml/metadata"); + $login->msg_relayState('{"url": "http://test/%22"}'); + $login->build_authn_request_msg(); + return $login; + } } clean_sessions(); done_testing(); -sub getAuthnRequest { - my ($method) = @_; - - my $server = Lasso::Server::new_from_buffers( - samlProxyMetaDataXML( "proxy", $method ), - saml_key_proxy_private_sig(), - undef, undef - ); - $server->add_provider_from_buffer( Lasso::Constants::PROVIDER_ROLE_IDP, - samlIDPMetaDataXML( "idp", $method ) - ); - - my $login = Lasso::Login->new($server); - my $method = $saml->getHttpMethod($method); - $login->init_authn_request("http://auth.idp.com/saml/metadata"); - $login->msg_relayState('{"url": "http://test/%22"}'); - $login->build_authn_request_msg(); - return $login; -} - sub issuer { return LLNG::Manager::Test->new( { ini => {