Skip to content

Commit

Permalink
Item9318: Unit test for Func::saveAttachment
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@8167 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Jul 14, 2010
1 parent dbcd4ea commit a9c1c46
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions UnitTestContrib/test/unit/FuncTests.pm
Expand Up @@ -398,6 +398,47 @@ sub test_attachments {

}

sub test_noauth_attachment {
my $this = shift;
use Foswiki::AccessControlException;
$Foswiki::cfg{EnableHierarchicalWebs} = 1;

my $data = "\0b\1l\2a\3h\4b\5l\6a\7h";
my $name1 = 'blahblahblah.gif';
my $topic = "BlahBlahBlah";

my $stream;
$this->assert(open($stream,">$this->{tmpdatafile}"));
binmode($stream);
print $stream $data;
close($stream);

$this->assert(open($stream, "<$this->{tmpdatafile}"));
binmode($stream);

Foswiki::Func::saveTopicText( $this->{test_web}, $topic," \n * Set ALLOWTOPICCHANGE = SomeUser\n" );

try {
my $e = Foswiki::Func::saveAttachment(
$this->{test_web}, $topic, $name1,
{
dontlog => 1,
comment => 'Feasgar Bha',
stream => $stream,
filepath => '/local/file',
filesize => 999,
filedate => 0,
} );
$this->assert(0, "saveAttachment worked for unauthorized user");

} catch Foswiki::AccessControlException with {
my $e = shift;
$this->assert_matches( qr/^AccessControlException: Access to CHANGE TemporaryFuncTestWebFunc.BlahBlahBlah for BaseUserMapping_666 is denied.*/, $e, "Unexpected error $e");
};
}



sub test_subweb_attachments {
my $this = shift;
$Foswiki::cfg{EnableHierarchicalWebs} = 1;
Expand Down

0 comments on commit a9c1c46

Please sign in to comment.