add Include macro test and fix Include bug

This commit is contained in:
Colin Kuskie 2006-07-28 16:11:47 +00:00
parent e0b17be5dd
commit b2d4c36080
3 changed files with 119 additions and 12 deletions

View file

@ -1,6 +1,8 @@
7.0.4
- Added a forum.lastPost.user.hasRead variable to the Message Board template.
- fix: r_printable macro and op2
- fixed a bug where the Include macro could be used to read WebGUI config
files.
7.0.3
- Fixed a problem with the 7.0.0-7.0.1 upgrade relating to internationalized

View file

@ -40,19 +40,17 @@ sub process {
my (@param, $temp, $file);
@param = @_;
my $i18n = WebGUI::International->new($session,'Macro_Include');
if ($param[0] =~ /passwd/i || $param[0] =~ /shadow/i || $param[0] =~ m!WebGUI/\w+.conf!i) {
$temp = $i18n->get('security');
} else {
$file = FileHandle->new($param[0],"r");
if ($file) {
while (<$file>) {
$temp .= $_;
}
$file->close;
} else {
$temp = $i18n->get('not found');
}
if ($param[0] =~ /passwd/i || $param[0] =~ /shadow/i || $param[0] =~ m!WebGUI/etc/\w+\.conf!i) {
return $i18n->get('security');
}
$file = FileHandle->new($param[0],"r");
if ($file) {
local $/;
$temp = $file->getline();
$file->close;
} else {
$temp = $i18n->get('not found');
}
return $temp;
}

107
t/Macro/Include.t Normal file
View file

@ -0,0 +1,107 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::Include;
use WebGUI::Session;
use WebGUI::Storage;
use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
my $i18n = WebGUI::International->new($session, 'Macro_Include');
my $configFile = WebGUI::Test->root .'/etc/'. WebGUI::Test->file;
my $spectreConf = WebGUI::Test->root . '/etc/spectre.conf';
my $confBackup = WebGUI::Test->root . '/etc/my.conf%';
my $goodFile = 'The contents of this file are accessible';
my $twoLines = "This file contains two lines of text\nThis is the second line";
my $storage = WebGUI::Storage->createTemp($session);
$storage->addFileFromScalar('goodFile', $goodFile);
$storage->addFileFromScalar('twoLines', $twoLines);
$storage->addFileFromScalar('unreadableFile', 'The contents of this file are not readable');
chmod 0111, $storage->getPath('unreadableFile');
my @testSets = (
{
file => '/etc/passwd',
output => $i18n->get('security'),
comment => q|passwd file|,
},
{
file => '/passwd/foo.txt',
output => $i18n->get('security'),
comment => q|passwd path|,
},
{
file => '/etc/shadow',
output => $i18n->get('security'),
comment => q|shadow file|,
},
{
file => '/shadow/foo.txt',
output => $i18n->get('security'),
comment => q|shadow path|,
},
{
file => $configFile,
output => $i18n->get('security'),
comment => q|WebGUI config file|,
},
{
file => $spectreConf,
output => $i18n->get('security'),
comment => q|spectre config file|,
},
{
file => $confBackup,
output => $i18n->get('security'),
comment => q|conf backup file|,
},
{
file => $storage->getPath('non-existantFile'),
output => $i18n->get('not found'),
comment => q|Non-existant file returns NOT FOUND|,
},
{
file => $storage->getPath('unreadableFile'),
output => $i18n->get('not found'),
comment => q|Unreadable file returns NOT FOUND|,
},
{
file => $storage->getPath('goodFile'),
output => $goodFile,
comment => q|Included a good file|,
},
{
file => $storage->getPath('twoLines'),
output => $twoLines,
comment => q|Included a file with two lines|,
},
);
my $numTests = scalar @testSets;
plan tests => $numTests;
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::Include::process($session, $testSet->{file});
is($output, $testSet->{output}, $testSet->{comment} );
}
END {
$storage->delete;
}