Skip to content

Commit

Permalink
Item14237: Fixed incorrect assumption about PSGI %env
Browse files Browse the repository at this point in the history
It doesn't incorporate shell environment.
  • Loading branch information
vrurg committed May 12, 2018
1 parent b1b1e3e commit aa27595
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 35 deletions.
11 changes: 5 additions & 6 deletions UnitTestContrib/lib/Foswiki/Engine/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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} )
: ()
)
} @_;
Expand Down Expand Up @@ -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));
};

Expand All @@ -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 [];
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions UnitTestContrib/test/unit/CacheTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 9 additions & 5 deletions UnitTestContrib/test/unit/ExtensionsTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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, @_ );

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand All @@ -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],
Expand Down
7 changes: 2 additions & 5 deletions UnitTestContrib/test/unit/RequestTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/bin/foswiki.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -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, );
};
Expand Down
10 changes: 6 additions & 4 deletions core/bin/foswiki_debug.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -37,6 +37,7 @@ BEGIN {
}
use Plack::Builder;
use Foswiki::App;

#use Devel::Leak;
#use Devel::Leak::Object;

Expand Down Expand Up @@ -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, );

Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Engine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Engine/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
};

Expand Down Expand Up @@ -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];
Expand Down
7 changes: 3 additions & 4 deletions core/lib/Foswiki/ExtManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit aa27595

Please sign in to comment.