From 3d1cc3f499d1d694a25a6efc5eb0a08a53c76551 Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Thu, 3 Jun 2021 16:29:57 +0200 Subject: [PATCH] Unit test for #2534 --- lemonldap-ng-portal/t/66-CDA-wildcard.t | 115 ++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 lemonldap-ng-portal/t/66-CDA-wildcard.t diff --git a/lemonldap-ng-portal/t/66-CDA-wildcard.t b/lemonldap-ng-portal/t/66-CDA-wildcard.t new file mode 100644 index 000000000..8927b91a9 --- /dev/null +++ b/lemonldap-ng-portal/t/66-CDA-wildcard.t @@ -0,0 +1,115 @@ +use Test::More; +use strict; +use IO::String; + +use Lemonldap::NG::Portal::Main::Constants qw( + PE_FIRSTACCESS +); + +require 't/test-lib.pm'; + +my $res; + +my $client = LLNG::Manager::Test->new( { + ini => { + logLevel => 'error', + useSafeJail => 1, + cda => 1, + logger => 'Lemonldap::NG::Common::Logger::Std', + } + } +); + +# CDA with unauthentified user +ok( + $res = $client->_get( + '/', + query => 'url=' . encodeUrl('http://cda.example.llng/'), + accept => 'text/html', + ), + 'Unauth CDA request' +); +my ( $host, $url, $query ) = expectForm( $res, undef, undef, 'url' ); +count(1); + +# Authentification +$query .= '&user=dwho&password=dwho'; +ok( + $res = $client->_post( + '/' => IO::String->new($query), + length => length($query), + accept => 'text/html', + ), + 'Post credentials' +); +count(1); + +($query) = + expectRedirection( $res, qr#^http://cda.example.llng/\?(lemonldapcda=.*)$# ); + +# Handler part +use_ok('Lemonldap::NG::Handler::Server'); +use_ok('Lemonldap::NG::Common::PSGI::Cli::Lib'); +count(2); + +my ( $cli, $app ); +ok( $app = Lemonldap::NG::Handler::Server->run( $client->ini ), 'App' ); +count(1); + +ok( + $res = $app->( { + 'HTTP_ACCEPT' => 'text/html', + 'SCRIPT_NAME' => '/', + 'SERVER_NAME' => '127.0.0.1', + 'QUERY_STRING' => $query, + 'HTTP_CACHE_CONTROL' => 'max-age=0', + 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', + 'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'REQUEST_URI' => "/?$query", + 'X_ORIGINAL_URI' => "/?$query", + 'SERVER_PORT' => '80', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + 'HTTP_USER_AGENT' => + 'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox', + 'REMOTE_ADDR' => '127.0.0.1', + 'HTTP_HOST' => 'cda.example.llng', + 'VHOSTTYPE' => 'CDA', + } + ), + 'Push cda cookie' +); +count(1); +expectRedirection( $res, 'http://cda.example.llng/' ); +my $cid = expectCookie($res); + +ok( + $res = $app->( { + 'HTTP_ACCEPT' => 'text/html', + 'SCRIPT_NAME' => '/', + 'SERVER_NAME' => '127.0.0.1', + 'HTTP_COOKIE' => "lemonldap=$cid", + 'HTTP_CACHE_CONTROL' => 'max-age=0', + 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', + 'PATH_INFO' => '/', + 'REQUEST_METHOD' => 'GET', + 'REQUEST_URI' => "/", + 'X_ORIGINAL_URI' => "/", + 'SERVER_PORT' => '80', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + 'HTTP_USER_AGENT' => + 'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox', + 'REMOTE_ADDR' => '127.0.0.1', + 'HTTP_HOST' => 'cda.example.llng', + 'VHOSTTYPE' => 'CDA', + } + ), + 'Authenticated query' +); +count(1); +expectOK($res); +expectAuthenticatedAs( $res, 'dwho' ); + +clean_sessions(); + +done_testing( count() );