Navigation Menu

Skip to content

Commit

Permalink
Item13743: Allow files to be installed in data & pub root
Browse files Browse the repository at this point in the history
Thanks to MaikGlatki for the debugging and a suggested fix.

This checkin adds these conditions to the unit tests, and isn't directly
sensitive to the filename.   Also addresses a possible issue where an
extension could override .htpasswd or .htaccess files.
  • Loading branch information
gac410 committed Sep 25, 2015
1 parent b710b2a commit 38831ba
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 21 deletions.
65 changes: 59 additions & 6 deletions UnitTestContrib/test/unit/ExtensionInstallerTests.pm
Expand Up @@ -171,11 +171,25 @@ sub test_Util_mapTarget {
$Foswiki::cfg{TrashWebName} = $this->{trash_web};
$Foswiki::cfg{UsersWebName} = 'Main';

# Verify file in root of pub

my $file = 'pub/rootfile.gif';
my $results =
Foswiki::Configure::Package::_mapTarget( "/var/www/foswiki/", "$file" );
$this->assert_str_equals( "$this->{rootdir}pub/rootfile.gif", $results );

# Verify file in root of data

$file = 'data/mime.types';
$results =
Foswiki::Configure::Package::_mapTarget( "/var/www/foswiki/", "$file" );
$this->assert_str_equals( "$this->{rootdir}data/mime.types", $results );

# Remap system web

$Foswiki::cfg{SystemWebName} = 'Fizbin';
my $file = 'pub/System/System/MyAtt.gif';
my $results =
$file = 'pub/System/System/MyAtt.gif';
$results =
Foswiki::Configure::Package::_mapTarget( "/var/www/foswiki/", "$file" );
$this->assert_str_equals( "$this->{rootdir}pub/Fizbin/System/MyAtt.gif",
$results );
Expand Down Expand Up @@ -986,9 +1000,13 @@ our $VERSION = '2.1';
__DATA__
<<<< MANIFEST >>>>
bin/shbtest1,0755,1a9a1da563535b2dad241d8571acd170,
data/mimedata,0644,1a9a1da563535b2dad241d8571acd170,
data/.htpasswd,0644,1a9a1da563535b2dad241d8571acd170,
data/Sandbox/TestTopic1.txt,0644,1a9a1da563535b2dad241d8571acd170,Documentation (noci)
data/Sandbox/TestTopic43.txt,0644,4dcabc1c8044e816f3c3d1a071ba1bc5,Documentation
data/Sandbox/Subweb/TestTopic43.txt,0644,4dcabc1c8044e816f3c3d1a071ba1bc5,Documentation
pub/pubfile,0644,1a9a1da563535b2dad241d8571acd170,
pub/.htaccess,0644,1a9a1da563535b2dad241d8571acd170,
pub/Sandbox/TestTopic1/file.att,0664,ede33d5e092a0cb2fa00d9146eed5f9a, (noci)
pub/Sandbox/TestTopic43/file.att,0664,1a9a1da563535b2dad241d8571acd170,
pub/Sandbox/TestTopic43/file2.att,0664,ede33d5e092a0cb2fa00d9146eed5f9a,
Expand Down Expand Up @@ -1061,6 +1079,23 @@ sub _makePackage {
my $foot = ($alt) ? $INSTALL_ONLYIF : $INSTALL_FOOT;
print $fh $foot;
close($fh) or die "Couldn't close: $!\n";

_makefile( "$tempdir/pub", "pubfile", <<'DONE');
Blah blah
Test file data
DONE
_makefile( "$tempdir/pub", ".htaccess", <<'DONE');
Blah blah
Test file data
DONE
_makefile( "$tempdir/data", "mimedata", <<'DONE');
Blah blah
Test file data
DONE
_makefile( "$tempdir/data", ".htpasswd", <<'DONE');
Blah blah
Test file data
DONE
_makefile( "$tempdir/data/Sandbox", "TestTopic1.txt", <<'DONE');
%META:TOPICINFO{author="BaseUserMapping_333" comment="reprev" date="1267729185" format="1.1" reprev="1.1" version="1.1"}%
Test rev 132412341234
Expand Down Expand Up @@ -1229,6 +1264,13 @@ DONE
$this->assert( $pkg->install($reporter) );
$this->sniff();

$this->sniff(
warnings =>
'Extension installer will not install data/.htpasswd. Server configuraiton file.',
warnings =>
'Extension installer will not install pub/.htaccess. Server configuraiton file.',
);

$this->sniff(
notes =>
"Installed: bin/shbtest1 as $Foswiki::cfg{ScriptDir}/shbtest1",
Expand All @@ -1238,6 +1280,7 @@ DONE
"Installed: data/Sandbox/TestTopic1.txt as $Foswiki::cfg{DataDir}/$Foswiki::cfg{SandboxWebName}/TestTopic1.txt",
notes =>
"Installed: data/Sandbox/TestTopic43.txt as $Foswiki::cfg{DataDir}/$Foswiki::cfg{SandboxWebName}/TestTopic43.txt",
notes => "Installed: data/mimedata as $Foswiki::cfg{DataDir}/mimedata",
notes =>
"Installed: pub/Sandbox/Subweb/TestTopic43/file3.att as $Foswiki::cfg{PubDir}/$Foswiki::cfg{SandboxWebName}/Subweb/TestTopic43/file3.att",
notes =>
Expand All @@ -1248,6 +1291,7 @@ DONE
"Installed: pub/Sandbox/TestTopic43/file.att as $Foswiki::cfg{PubDir}/$Foswiki::cfg{SandboxWebName}/TestTopic43/file.att",
notes =>
"Installed: pub/Sandbox/TestTopic43/file2.att as $Foswiki::cfg{PubDir}/$Foswiki::cfg{SandboxWebName}/TestTopic43/file2.att",
notes => "Installed: pub/pubfile as $Foswiki::cfg{PubDir}/pubfile",
notes =>
"Installed: tools/shbtest2 as $Foswiki::cfg{ToolsDir}/shbtest2",
notes =>
Expand All @@ -1256,14 +1300,15 @@ DONE

my @mfiles = $pkg->_listFiles();
$this->assert_num_equals(
10,
12,
scalar @mfiles,
'Unexpected number of files in manifest'
); # 5 files in manifest

my @ifiles = $pkg->_listFiles('1');

$this->assert_num_equals(
10,
12,
scalar @ifiles,
'Unexpected number of files installed'
); # and 5 files installed
Expand Down Expand Up @@ -1293,7 +1338,6 @@ DONE
# Install a 2nd time - files should be created when checkin is requested.
#
_makePackage( $tempdir, $extension );

my $pkg2 = Foswiki::Configure::Package->new(
root => $root,
module => 'MyPlugin',
Expand All @@ -1307,6 +1351,13 @@ DONE
$this->assert( $pkg2->install($reporter) );
$this->sniff();

$this->sniff(
warnings =>
'Extension installer will not install data/.htpasswd. Server configuraiton file.',
warnings =>
'Extension installer will not install pub/.htaccess. Server configuraiton file.',
);

$this->sniff(
notes =>
"Installed: bin/shbtest1 as $Foswiki::cfg{ScriptDir}/shbtest1",
Expand All @@ -1322,10 +1373,12 @@ DONE
"Attached: pub/Sandbox/TestTopic43/file.att to $this->{sandbox_web}/TestTopic43",
notes =>
"Attached: pub/Sandbox/TestTopic43/file2.att to $this->{sandbox_web}/TestTopic43",
notes => "Installed: data/mimedata as $Foswiki::cfg{DataDir}/mimedata",
notes =>
"Installed: pub/Sandbox/Subweb/TestTopic43/subdir-1.2.3/file4.att as $Foswiki::cfg{PubDir}/$Foswiki::cfg{SandboxWebName}/Subweb/TestTopic43/subdir-1.2.3/file4.att",
notes =>
"Installed: pub/Sandbox/TestTopic1/file.att as $Foswiki::cfg{PubDir}/$Foswiki::cfg{SandboxWebName}/TestTopic1/file.att",
notes => "Installed: pub/pubfile as $Foswiki::cfg{PubDir}/pubfile",
notes =>
"Installed: tools/shbtest2 as $Foswiki::cfg{ToolsDir}/shbtest2",
notes =>
Expand All @@ -1335,7 +1388,7 @@ DONE
my @ifiles2 = $pkg2->_listFiles('1');

$this->assert_num_equals(
15,
17,
scalar @ifiles2,
'Unexpected number of files installed on 2nd install: ' . @ifiles2
); # + 3 rcs files after checkin
Expand Down
57 changes: 42 additions & 15 deletions core/lib/Foswiki/Configure/Package.pm
Expand Up @@ -886,10 +886,13 @@ sub _install {

# Move or copy the file.

next unless ( -f "$dir/$file" ); # Exists as a file.
unless ( -f "$dir/$file" ) { # Exists as a file.
$reporter->WARN("Source missing $dir/$file - Skipping file");
next;
}

my $installed = $manifest->{$file}->{I}
|| ''; # Set to 1 if file already installed
|| ''; # Set to 1 if file already installed
next if ($installed);
$manifest->{$file}->{I} =
1; # Set this to installed (assuming it all works)
Expand All @@ -903,7 +906,8 @@ sub _install {
# work in CLI environment, so we are forced to skip this and just
# copy the file directly.
if (
$file =~ m/^data/ # File for the data directory
$file =~ m/^data/ # File for the data directory
&& $file =~ m/^data\/(.*)\/(\w+).txt$/ # and is a topic
&& $Foswiki::Plugins::SESSION
&& (
-e "$target,v" # rcs history file exists
Expand All @@ -920,7 +924,8 @@ sub _install {
)
)
{
my ( $web, $topic ) = $file =~ m/^data\/(.*)\/(\w+).txt$/;
my $web = $1;
my $topic = $2;
my ( $tweb, $ttopic ) = _getMappedWebTopic($file);

#SMELL Should not try to check in if target web is missing?
Expand Down Expand Up @@ -1600,43 +1605,65 @@ sub _parseManifest {
}
$file =~ s/^"(.+)"$/$1/;

my $tweb = '';
my $ttopic = '';
my $tattach = '';
my $tweb = '';
my $ttopic = '';
my $tattach = '';
my $canCheckin = 0;

# DO NOT Let the Extensions installer save over .htpasswd or modify the server installation.
if ( $file =~ m/\/\.ht(?:access|passwd)$/ ) {
$reporter->WARN(
"Extension installer will not install $file. Server configuration file."
);
return;
}

if ( $file =~ m/^data\/.*/ ) {
( $tweb, $ttopic ) = $file =~ m/^data\/(.*)\/(.*?).txt$/;
unless ( defined $tweb
if ( $file =~ m/^data\/.*/ && $file =~ m/^data\/(.*)\/(.*?).txt$/ ) {
$tweb = $1;
$ttopic = $2;
if ( defined $tweb
&& defined $ttopic
&& length($tweb) > 0
&& length($ttopic) > 0 )
{
$canCheckin = 1;
}
else {
$reporter->WARN("$file is not a topic - file will be bypassed");
}
}
if ( $file =~ m/^pub\/.*/ ) {
( $tweb, $ttopic, $tattach ) = $file =~ m/^pub\/(.*)\/(.*?)\/([^\/]+)$/;
unless ( defined $tweb
if ( $file =~ m/^pub\/.*/ && $file =~ m/^pub\/(.*)\/(.*?)\/([^\/]+)$/ ) {
$tweb = $1;
$ttopic = $2;
$tattach = $3;
if ( defined $tweb
&& defined $ttopic
&& defined $tattach
&& length($tweb) > 0
&& length($ttopic) > 0
&& length($tattach) > 0 )
{
$canCheckin = 1;
}
else {
$reporter->WARN(
"Unable to identify attachment $file name or location"
. " - file will be bypassed" );
return;
}
}

$this->{_manifest}->{$file}->{ci} = ( $desc =~ s/\(noci\)// ? 0 : 1 );
$this->{_manifest}->{$file}->{ci} =
( ( !$canCheckin || $desc =~ s/\(noci\)// ) ? 0 : 1 );
$this->{_manifest}->{$file}->{perms} = $perms;
$this->{_manifest}->{$file}->{md5} = $md5 || '';
$this->{_manifest}->{$file}->{md5} = $md5 || '';

# SMELL: The {topic} field isn't used by Package. But it should be.
$this->{_manifest}->{$file}->{topic} = "$tweb\t$ttopic\t$tattach";
$this->{_manifest}->{$file}->{desc} = $desc;
$this->{_manifest}->{ATTACH}->{"$tweb/$ttopic"}->{$tattach} = $file
if $tattach;

}

# Parse the manifest line into the manifest hash.
Expand Down

0 comments on commit 38831ba

Please sign in to comment.