From e50948516169fd803159fc902f24e6aea0980bdf Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 23 Sep 2022 12:04:54 -0300 Subject: [PATCH] Bug 29744: (QA follow-up) Only consider PLACK_ENV for underscore When run under certain circumstances (in jenkins, for example) some ENV variables are set for convenience, like PLACK_WORKERS and PLACK_MAX_REQUESTS and is causing some tests to fail (notably, shib ones). This patch makes the regex only consider PLACK_ENV when testing for the underscore case. Tests are updated accordingly, and they are also rewritten to test for boolean values instead of empty string, or zero or one, etc. The implementation shouldn't matter as long as the boolean evaluation is correct and it is clearer for devs what to expect. Signed-off-by: Tomas Cohen Arazi --- C4/Context.pm | 2 +- t/Context.t | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 8cd7681e6c..df04c7ab66 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -1009,7 +1009,7 @@ this is a PSGI app or a CGI app, and implementing code as appropriate. sub psgi_env { my ( $self ) = @_; - return any { /^(psgi|plack)[._]/i } keys %ENV; + return any { /^(psgi\.|plack\.|PLACK_ENV$)/i } keys %ENV; } =head3 is_internal_PSGI_request diff --git a/t/Context.t b/t/Context.t index 1e351157d8..cf4a4b6036 100755 --- a/t/Context.t +++ b/t/Context.t @@ -147,32 +147,33 @@ is( C4::Context->interface( 'CRON' ), 'cron', 'interface cron uc' ); } subtest 'psgi_env and is_internal_PSGI_request' => sub { + plan tests => 11; local %ENV = ( no_plack => 1 ); - is( C4::Context->psgi_env, q{}, 'no_plack' ); + ok( !C4::Context->psgi_env, 'no_plack' ); $ENV{plackishere} = 1; - is( C4::Context->psgi_env, q{}, 'plackishere is wrong' ); + ok( !C4::Context->psgi_env, 'plackishere is wrong' ); $ENV{'plack.ishere'} = 1; - is( C4::Context->psgi_env, 1, 'plack.ishere' ); + ok( C4::Context->psgi_env, 'plack.ishere' ); delete $ENV{'plack.ishere'}; - is( C4::Context->psgi_env, q{}, 'plack.ishere was here' ); - $ENV{'plack_ishere'} = 1; - is( C4::Context->psgi_env, 1, 'plack_ishere' ); - delete $ENV{'plack_ishere'}; + ok( !C4::Context->psgi_env, 'plack.ishere was here' ); + $ENV{'plack_env'} = 1; + ok( C4::Context->psgi_env, 'plack_env' ); + delete $ENV{'plack_env'}; $ENV{'psgi_whatever'} = 1; - is( C4::Context->psgi_env, 1, 'psgi_whatever' ); + ok( !C4::Context->psgi_env, 'psgi_whatever' ); delete $ENV{'psgi_whatever'}; $ENV{'psgi.whatever'} = 1; - is( C4::Context->psgi_env, 1, 'psgi.whatever' ); + ok( C4::Context->psgi_env, 'psgi.whatever' ); delete $ENV{'psgi.whatever'}; $ENV{'PSGI.UPPERCASE'} = 1; - is( C4::Context->psgi_env, 1, 'PSGI uppercase' ); + ok( C4::Context->psgi_env, 'PSGI uppercase' ); $ENV{'REQUEST_URI'} = '/intranet/whatever'; - is( C4::Context->is_internal_PSGI_request, 0, 'intranet not considered internal in regex' ); + ok( !C4::Context->is_internal_PSGI_request, 'intranet not considered internal in regex' ); $ENV{'REQUEST_URI'} = '/api/v1/tralala'; - is( C4::Context->is_internal_PSGI_request, 1, 'api considered internal in regex' ); + ok( C4::Context->is_internal_PSGI_request, 'api considered internal in regex' ); delete $ENV{'PSGI.UPPERCASE'}; - is( C4::Context->is_internal_PSGI_request, 0, 'api but no longer PSGI' ); + ok( !C4::Context->is_internal_PSGI_request, 'api but no longer PSGI' ); }; -- 2.39.5