Bug 29744: (QA follow-up) Add underscore test, move to OO

The underscore test comes from bug 31468.
Context methods should actually be OO.

Test plan:
Run t/Context.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2022-09-16 07:07:00 +00:00 committed by Tomas Cohen Arazi
parent 97b1bd1dae
commit 097b2afb17
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 38 additions and 3 deletions

View File

@ -1007,7 +1007,10 @@ this is a PSGI app or a CGI app, and implementing code as appropriate.
=cut
sub psgi_env { any { /(^psgi\.|^plack\.)/i } keys %ENV };
sub psgi_env {
my ( $self ) = @_;
return any { /^(psgi|plack)[._]/i } keys %ENV;
}
=head3 is_internal_PSGI_request
@ -1019,8 +1022,9 @@ app
#NOTE: This is not a very robust method but it's the best we have so far
sub is_internal_PSGI_request {
my ( $self ) = @_;
my $is_internal = 0;
if ( (__PACKAGE__->psgi_env) && ( $ENV{REQUEST_URI} !~ /^(\/intranet|\/opac)/ ) ){
if( $self->psgi_env && ( $ENV{REQUEST_URI} !~ /^(\/intranet|\/opac)/ ) ) {
$is_internal = 1;
}
return $is_internal;

View File

@ -18,7 +18,7 @@
use Modern::Perl;
use DBI;
use Test::More tests => 32;
use Test::More tests => 33;
use Test::MockModule;
use Test::Warn;
use YAML::XS;
@ -145,3 +145,34 @@ is( C4::Context->interface( 'CRON' ), 'cron', 'interface cron uc' );
$ENV{HTTPS} = 'ON';
is( C4::Context->https_enabled, 1, "ON HTTPS env returns 1");
}
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' );
$ENV{plackishere} = 1;
is( C4::Context->psgi_env, q{}, 'plackishere is wrong' );
$ENV{'plack.ishere'} = 1;
is( C4::Context->psgi_env, 1, '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'};
$ENV{'psgi_whatever'} = 1;
is( C4::Context->psgi_env, 1, 'psgi_whatever' );
delete $ENV{'psgi_whatever'};
$ENV{'psgi.whatever'} = 1;
is( C4::Context->psgi_env, 1, 'psgi.whatever' );
delete $ENV{'psgi.whatever'};
$ENV{'PSGI.UPPERCASE'} = 1;
is( C4::Context->psgi_env, 1, 'PSGI uppercase' );
$ENV{'REQUEST_URI'} = '/intranet/whatever';
is( C4::Context->is_internal_PSGI_request, 0, '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' );
delete $ENV{'PSGI.UPPERCASE'};
is( C4::Context->is_internal_PSGI_request, 0, 'api but no longer PSGI' );
};