Skip to content

Commit

Permalink
Item14237: Adapted missed SecurityTests to the v3 test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed May 14, 2018
1 parent f6cbd82 commit b99be21
Showing 1 changed file with 27 additions and 64 deletions.
91 changes: 27 additions & 64 deletions UnitTestContrib/test/unit/SecurityTests.pm
Original file line number Diff line number Diff line change
@@ -1,51 +1,28 @@
package SecurityTests;
use FoswikiFnTestCase();
use Foswiki::UI::Attach();
our @ISA = qw( FoswikiFnTestCase );

# use strict;

my $session; # Foswiki instance
#use Foswiki::UI::Attach();

sub new {
my $self = shift()->SUPER::new(@_);

return $self;
}
use Foswiki::Class;
extends qw(FoswikiFnTestCase);
our @ISA = qw( FoswikiFnTestCase );

sub set_up {
my $this = shift;
$this->SUPER::set_up();
$session = undef;
}
# use strict;

sub create_session {
my $this = shift;
my $query_opts = shift;

# a simple query using attach
my $query = new Unit::Request($query_opts);
$query->path_info("/$this->{test_web}/$this->{test_topic}");
$query->action("attach");

# Create a Foswiki instance
$session =
$this->createNewFoswikiSession( $this->{test_user_login}, $query );

return $session;
}

sub tear_down {
my $this = shift; # the Test::Unit::TestCase object

if ($session) {

# FoswikiFnTestCase does most of this
1;
}

# This will automatically restore the state of $Foswiki::cfg
$this->SUPER::tear_down();
my $this = shift;
my $reqOpts = shift;

# Create a Foswiki app
$this->createNewFoswikiApp(
requestParams => { initializer => $reqOpts, },
engineParams => {
initialAttributes => {
path_info => "/" . $this->test_web . "/" . $this->test_topic,
action => "attach",
user => $this->test_user_login,
},
}
);
}

sub test_setup {
Expand All @@ -56,23 +33,16 @@ sub test_setup {
my $this = shift;

$this->create_session( { filename => ["goober"] } );
my $query = $this->{request};
my $query = $this->app->request;

$this->assert_str_equals( "attach", $query->action() );
$this->assert_str_equals( "filename=goober", $query->queryString() );
$this->assert_str_equals( "attach", $query->action );
$this->assert_str_equals( "filename=goober", $query->queryString );
$this->assert_str_equals( "goober", scalar( $query->param('filename') ) );

# print $query->url(-query => 1), "\n";

my ( $respText, $result, $stdout, $stderr ) = $this->captureWithKey(
attach => sub {
no strict 'refs';
Foswiki::UI::Attach::attach( $this->{session} );
use strict 'refs';
$Foswiki::engine->finalize( $this->{session}{response},
$this->{session}{request} );
}
);
my ( $respText, $result, $stdout, $stderr ) =
$this->captureWithKey( attach => sub { $this->app->handleRequest }, );

# print $respText, "\n";

Expand All @@ -87,19 +57,12 @@ sub test_attach_filename_xss {
# send filename="><sCrIpT>alert(66562)</sCrIpT>
$this->create_session(
{ filename => ['"><sCrIpT>alert(66562)</sCrIpT>'] } );
my $query = $this->{request};
my $query = $this->app->request;

# print $query->url(-query => 1), "\n";

my ( $respText, $result, $stdout, $stderr ) = $this->captureWithKey(
attach => sub {
no strict 'refs';
Foswiki::UI::Attach::attach( $this->{session} );
use strict 'refs';
$Foswiki::engine->finalize( $this->{session}{response},
$this->{session}{request} );
}
);
my ( $respText, $result, $stdout, $stderr ) =
$this->captureWithKey( attach => sub { $this->app->handleRequest; } );

# print $respText, "\n";

Expand Down

0 comments on commit b99be21

Please sign in to comment.