Skip to content

Commit

Permalink
Item9347: isRedirectSafe tests must control the config
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@8217 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Jul 18, 2010
1 parent 9f134f8 commit d8f36db
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion UnitTestContrib/test/unit/ResponseTests.pm
Expand Up @@ -8,6 +8,14 @@ use Assert;

use Foswiki::Response;

sub set_up {
my $this = shift;
$this->SUPER::set_up();
$Foswiki::cfg{AllowRedirectUrl} = 0;
$Foswiki::cfg{DefaultUrlHost} = 'http://wiki.server';
$Foswiki::cfg{PermittedRedirectHostUrls} = 'http://other.wiki';
}

sub test_empty_new {
my ($this) = @_;
my $res = Foswiki::Response->new();
Expand Down Expand Up @@ -268,11 +276,11 @@ sub test_isRedirectSafe {
my ($this) = @_;

$this->assert(not Foswiki::_isRedirectSafe('http://slashdot.org'));
$this->assert(Foswiki::_isRedirectSafe('/relative'));

#$Foswiki::cfg{DefaultUrlHost} based
my $baseUrlMissingSlash = $Foswiki::cfg{DefaultUrlHost};


#http://wiki.server.com (missing trailing slash)
$baseUrlMissingSlash =~ s/(.*)\/$/$1/;
my $url = $baseUrlMissingSlash;
Expand All @@ -281,6 +289,21 @@ sub test_isRedirectSafe {
$this->assert(Foswiki::_isRedirectSafe($url));
$url = $baseUrlMissingSlash.'#header';
$this->assert(Foswiki::_isRedirectSafe($url));

$Foswiki::cfg{DefaultUrlHost} = 'http://wiki.server';
$Foswiki::cfg{PermittedRedirectHostUrls} =
'http://wiki.other,http://other.wiki';

$this->assert(Foswiki::_isRedirectSafe('/wiki.server'));
$this->assert(Foswiki::_isRedirectSafe('http://wiki.server'));
$this->assert(Foswiki::_isRedirectSafe('http://wiki.server/'));
$this->assert(Foswiki::_isRedirectSafe('http://other.wiki'));
$this->assert(Foswiki::_isRedirectSafe('http://other.wiki/'));
$this->assert(Foswiki::_isRedirectSafe('http://wiki.other'));
$this->assert(Foswiki::_isRedirectSafe('http://wiki.other/'));
$this->assert(not Foswiki::_isRedirectSafe('http://slashdot.org'));
$this->assert(not Foswiki::_isRedirectSafe('http://slashdot.org/'));

return;
}

Expand Down

0 comments on commit d8f36db

Please sign in to comment.