From aa27595da69ffacc85a16e401f0219967c1b7125 Mon Sep 17 00:00:00 2001 From: Vadim Belman Date: Fri, 11 May 2018 20:05:47 -0400 Subject: [PATCH] Item14237: Fixed incorrect assumption about PSGI %env It doesn't incorporate shell environment. --- UnitTestContrib/lib/Foswiki/Engine/Test.pm | 11 +++++------ UnitTestContrib/test/unit/CacheTests.pm | 4 ++-- UnitTestContrib/test/unit/ExtensionsTests.pm | 14 +++++++++----- UnitTestContrib/test/unit/RequestTests.pm | 7 ++----- core/bin/foswiki.psgi | 4 ++-- core/bin/foswiki_debug.psgi | 10 ++++++---- core/lib/Foswiki/Config.pm | 6 +++--- core/lib/Foswiki/Engine.pm | 2 +- core/lib/Foswiki/Engine/CLI.pm | 6 +++--- core/lib/Foswiki/ExtManager.pm | 7 +++---- 10 files changed, 36 insertions(+), 35 deletions(-) diff --git a/UnitTestContrib/lib/Foswiki/Engine/Test.pm b/UnitTestContrib/lib/Foswiki/Engine/Test.pm index 2ed64a4c71..6ee2c46c0d 100644 --- a/UnitTestContrib/lib/Foswiki/Engine/Test.pm +++ b/UnitTestContrib/lib/Foswiki/Engine/Test.pm @@ -204,12 +204,11 @@ Returns a hashref. sub initFromEnv { my $this = shift; my $initAttrs = $this->initialAttributes; - my $env = $this->env; my %initHash = map { my $eKey = uc( 'FOSWIKI_TEST_' . $_ ); defined( $initAttrs->{$_} ) ? ( $_ => $initAttrs->{$_} ) : ( - defined( $env->{$eKey} ) ? ( $_ => $env->{$eKey} ) + defined( $ENV{$eKey} ) ? ( $_ => $ENV{$eKey} ) : () ) } @_; @@ -402,7 +401,7 @@ around preparePath => sub { my $this = shift; # Use the standard if test value is not provided. - $this->env->{FOSWIKI_TEST_ACTION} //= $this->env->{FOSWIKI_ACTION}; + $ENV{FOSWIKI_TEST_ACTION} //= $ENV{FOSWIKI_ACTION}; return $this->initFromEnv(qw(action path_info uri)); }; @@ -423,7 +422,7 @@ around prepareQueryParameters => sub { my $this = shift; my $queryString = $this->initialAttributes->{query_string} - // $this->env->{FOSWIKI_TEST_QUERY_STRING}; + // $ENV{FOSWIKI_TEST_QUERY_STRING}; return $orig->( $this, $queryString ) if defined $queryString; return []; @@ -434,11 +433,11 @@ around prepareHeaders => sub { my $this = shift; my $headers = $orig->($this); - foreach my $header ( keys %{ $this->env } ) { + foreach my $header ( keys %ENV ) { next unless $header =~ m/^FOSWIKI_TEST_(?:HTTP|CONTENT|COOKIE)/i; ( my $field = $header ) =~ s/^FOSWIKI_TEST_//; $field =~ s/^HTTPS?_//; - $headers->{$field} = $this->env->{$header}; + $headers->{$field} = $ENV{$header}; } # Initial attributes override environment values. diff --git a/UnitTestContrib/test/unit/CacheTests.pm b/UnitTestContrib/test/unit/CacheTests.pm index c3d51c6891..8bc320f325 100644 --- a/UnitTestContrib/test/unit/CacheTests.pm +++ b/UnitTestContrib/test/unit/CacheTests.pm @@ -264,8 +264,8 @@ around set_up => sub { $this->app->cfg->data->{Cache}{Compress} = 0; $this->oldDbiDsn( $this->app->cfg->data->{Cache}{DBI}{DSN} ); $this->oldCacheDsn( $this->app->cfg->data->{Cache}{DSN} ); - delete $this->app->env->{FOSWIKI_TEST_PATH_INFO}; - delete $this->app->env->{FOSWIKI_TEST_ACTION}; + delete $ENV{FOSWIKI_TEST_PATH_INFO}; + delete $ENV{FOSWIKI_TEST_ACTION}; $this->clear_testUri; $this->clear_testPathInfo; }; diff --git a/UnitTestContrib/test/unit/ExtensionsTests.pm b/UnitTestContrib/test/unit/ExtensionsTests.pm index 53687cfc5b..18ed8bd1d1 100644 --- a/UnitTestContrib/test/unit/ExtensionsTests.pm +++ b/UnitTestContrib/test/unit/ExtensionsTests.pm @@ -51,7 +51,7 @@ around set_up => sub { 'TestExtensions' ); # Disable all extensions generated by previous tests. - $ENV{FOSWIKI_DISABLED_EXTENSIONS} = join ",", @{ $this->autoGenExt }; + _addExtToDisabled( @{ $this->autoGenExt } ); $orig->( $this, @_ ); @@ -128,10 +128,14 @@ sub _setExtDependencies { } } +sub _addExtToDisabled { + $ENV{FOSWIKI_DISABLED_EXTENSIONS} = + join( ",", ( split /,/, $ENV{FOSWIKI_DISABLED_EXTENSIONS} || '' ), @_ ); +} + sub _disableAllCurrentExtensions { my $this = shift; - $this->app->env->{FOSWIKI_DISABLED_EXTENSIONS} = - [@Foswiki::ExtManager::extModules]; + _addExtToDisabled(@Foswiki::ExtManager::extModules); } sub test_orderedList { @@ -164,7 +168,7 @@ sub test_manual_disable { my @ext = $this->_genExtModules(2); - push @{ $this->app->env->{FOSWIKI_DISABLED_EXTENSIONS} }, $ext[1]; + _addExtToDisabled( $ext[1] ); $this->reCreateFoswikiApp; @@ -187,7 +191,7 @@ sub test_depend_on_manual_disable { my @ext = $this->_genExtModules(4); - push @{ $this->app->env->{FOSWIKI_DISABLED_EXTENSIONS} }, $ext[1]; + _addExtToDisabled( $ext[1] ); $this->_setExtDependencies( $ext[3] => $ext[2], $ext[2] => $ext[1], diff --git a/UnitTestContrib/test/unit/RequestTests.pm b/UnitTestContrib/test/unit/RequestTests.pm index 164abc0537..8fbb213f9a 100644 --- a/UnitTestContrib/test/unit/RequestTests.pm +++ b/UnitTestContrib/test/unit/RequestTests.pm @@ -225,11 +225,8 @@ sub test_action { foreach (qw(view edit save upload preview rdiff)) { $req->action($_); $this->assert_str_equals( $_, $req->action, 'Wrong action value' ); - $this->assert_str_equals( - $_, - $this->app->env->{FOSWIKI_ACTION}, - 'Wrong FOSWIKI_ACTION environment' - ); + $this->assert_str_equals( $_, $ENV{FOSWIKI_ACTION}, + 'Wrong FOSWIKI_ACTION environment' ); } } diff --git a/core/bin/foswiki.psgi b/core/bin/foswiki.psgi index 9614f54fa8..7fc7533160 100644 --- a/core/bin/foswiki.psgi +++ b/core/bin/foswiki.psgi @@ -39,8 +39,8 @@ use Foswiki::App; my $app = sub { my $env = shift; - $env->{FOSWIKI_SCRIPTS} = $scriptDir unless $env->{FOSWIKI_SCRIPTS}; - $env->{FOSWIKI_LIBS} = $libDir unless $env->{FOSWIKI_LIBS}; + $ENV{FOSWIKI_SCRIPTS} = $scriptDir unless $ENV{FOSWIKI_SCRIPTS}; + $ENV{FOSWIKI_LIBS} = $libDir unless $ENV{FOSWIKI_LIBS}; return Foswiki::App->run( env => $env, ); }; diff --git a/core/bin/foswiki_debug.psgi b/core/bin/foswiki_debug.psgi index 3a972db704..6c2bfafbad 100644 --- a/core/bin/foswiki_debug.psgi +++ b/core/bin/foswiki_debug.psgi @@ -9,8 +9,8 @@ my ( $rootDir, $libDir, $scriptDir ); my ( $checkpointSub, $statusSub ); BEGIN { - $rootDir = $ENV{FOSWIKI_HOME}; - $scriptDir = $ENV{FOSWIKI_SCRIPTS}; + $rootDir = $ENV{FOSWIKI_HOME}; + $scriptDir = $ENV{FOSWIKI_SCRIPTS}; $ENV{FOSWIKI_ASSERTS} = 1; unless ($scriptDir) { @@ -37,6 +37,7 @@ BEGIN { } use Plack::Builder; use Foswiki::App; + #use Devel::Leak; #use Devel::Leak::Object; @@ -67,8 +68,9 @@ my $app = sub { &$checkpointSub if CHECKLEAK; - $env->{FOSWIKI_SCRIPTS} = $scriptDir unless $env->{FOSWIKI_SCRIPTS}; - $env->{FOSWIKI_LIBS} = $libDir unless $env->{FOSWIKI_LIBS}; + $ENV{FOSWIKI_SCRIPTS} = $scriptDir unless $ENV{FOSWIKI_SCRIPTS}; + $ENV{FOSWIKI_LIBS} = $libDir unless $ENV{FOSWIKI_LIBS}; + $ENV{FOSWIKI_DISABLED_EXTENSIONS} = "DBConfig"; my $rc = Foswiki::App->run( env => $env, ); diff --git a/core/lib/Foswiki/Config.pm b/core/lib/Foswiki/Config.pm index 8e7ebf7fc4..490d151fde 100644 --- a/core/lib/Foswiki/Config.pm +++ b/core/lib/Foswiki/Config.pm @@ -1818,8 +1818,8 @@ sub bootstrapSystemSettings { # would trigger "undefined" errors my $bin; my $script = ''; - if ( defined $env->{FOSWIKI_SCRIPTS} ) { - $bin = $env->{FOSWIKI_SCRIPTS}; + if ( defined $ENV{FOSWIKI_SCRIPTS} ) { + $bin = $ENV{FOSWIKI_SCRIPTS}; } else { eval('require FindBin'); @@ -3736,7 +3736,7 @@ to let user-defined config be used. Otherwise _'LocalSite.cfg'_ is returned. =cut sub prepareLscFile { - return $_[0]->app->env->{FOSWIKI_CONFIG} || 'LocalSite.cfg'; + return $ENV{FOSWIKI_CONFIG} || 'LocalSite.cfg'; } =begin TML diff --git a/core/lib/Foswiki/Engine.pm b/core/lib/Foswiki/Engine.pm index 3997b925f3..5fd1f272ea 100644 --- a/core/lib/Foswiki/Engine.pm +++ b/core/lib/Foswiki/Engine.pm @@ -213,7 +213,7 @@ sub start { my $env = $app->env; my $engine; $engine //= $cfg->data->{Engine}; - $engine //= $env->{FOSWIKI_ENGINE}; + $engine //= $ENV{FOSWIKI_ENGINE}; unless ( defined $engine ) { foreach my $shortName ( @{ $cfg->data->{EngineList} } ) { my $engMod = "Foswiki::Engine::$shortName"; diff --git a/core/lib/Foswiki/Engine/CLI.pm b/core/lib/Foswiki/Engine/CLI.pm index fc29eaf96d..fe0bdf0db7 100644 --- a/core/lib/Foswiki/Engine/CLI.pm +++ b/core/lib/Foswiki/Engine/CLI.pm @@ -67,7 +67,7 @@ around prepareConnection => sub { my $this = shift; return { remoteAddress => '127.0.0.1', - method => $this->env->{FOSWIKI_METHOD} // 'GET', + method => $ENV{FOSWIKI_METHOD} // 'GET', }; }; @@ -105,8 +105,8 @@ around preparePath => sub { my ($this) = @_; my $env = $this->env; my ( $action, $path_info ); - if ( $env->{FOSWIKI_ACTION} ) { - $action = $env->{FOSWIKI_ACTION}; + if ( $ENV{FOSWIKI_ACTION} ) { + $action = $ENV{FOSWIKI_ACTION}; } else { $action = ( File::Spec->splitpath($0) )[2]; diff --git a/core/lib/Foswiki/ExtManager.pm b/core/lib/Foswiki/ExtManager.pm index be228d4a01..910d5a5ea3 100644 --- a/core/lib/Foswiki/ExtManager.pm +++ b/core/lib/Foswiki/ExtManager.pm @@ -1024,14 +1024,14 @@ Initializer for =extSubDirs= attribute. sub prepareExtSubDirs { my $this = shift; - my $extLibs = $this->app->env->{FOSWIKI_EXTLIBS}; + my $extLibs = $ENV{FOSWIKI_EXTLIBS}; my @extPath; if ( defined $extLibs ) { push @extPath, split /:/, $extLibs; } else { - my $fwPath = $this->app->env->{FOSWIKI_LIBS}; + my $fwPath = $ENV{FOSWIKI_LIBS}; # If the env is not set guess by Foswiki.pm module. $fwPath //= ( File::Spec->splitpath( $INC{'Foswiki.pm'} ) )[1]; @@ -1084,13 +1084,12 @@ sub _disabled2List { sub prepareDisabledExtensions { my $this = shift; - my $env = $this->app->env; my $envVar = 'FOSWIKI_DISABLED_EXTENSIONS'; my $confKey = "DisabledExtensions"; # @disabled would contain a list of pairs of extension name and a message to # be appended to "Disable reason: " prefix. - my @disabled = $this->_disabled2List( $env->{$envVar} // '', + my @disabled = $this->_disabled2List( $ENV{$envVar} // '', "listed in environment variable $envVar" ); my %disabled;