Skip to content

Commit

Permalink
Item13897: Working AccessControlTests and AdminOnlyAccessControlTests
Browse files Browse the repository at this point in the history
- Adapted UI::Oops

- Implementing exception handling by Foswiki::App::handlerRequest.

- Foswiki::Exception::transmute got a new argument – $enforce.

- Converted Foswiki::OopsException
  • Loading branch information
vrurg committed May 24, 2016
1 parent 4deb63d commit 5f383d3
Show file tree
Hide file tree
Showing 20 changed files with 357 additions and 225 deletions.
60 changes: 36 additions & 24 deletions TopicUserMappingContrib/lib/Foswiki/Users/TopicUserMapping.pm
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ See baseclass for documentation

sub eachGroup {
my ($this) = @_;
_getListOfGroups($this);
$this->_getListOfGroups;
return new Foswiki::ListIterator( list => \@{ $this->groupsList } );
}

Expand Down Expand Up @@ -1659,39 +1659,51 @@ sub _getListOfGroups {
my $this = shift;
my $reset = shift;

my $app = $this->app;

ASSERT( $this->isa('Foswiki::Users::TopicUserMapping') ) if DEBUG;

if ( !$this->groupsList || $reset ) {
my $users = $this->app->users;
my $users = $app->users;
$this->groupsList( [] );

#create a MetaCache _before_ we do silly things with the app's users
$this->app->search->metacache();
$app->search->metacache();

# Temporarily set the user to admin, otherwise it cannot see groups
# where %USERSWEB% is protected from view
# SMELL XXXMOO Broken: this has to be done differently!
# SMELL Broken: this has to be done differently!
#local $this->app->{user} = $Foswiki::cfg{SuperAdminGroup};

$this->app->search->searchWeb(
_callback => \&_collateGroups,
_cbdata => {
list => $this->groupsList,
users => $users
},
web => $Foswiki::cfg{UsersWebName},
topic => "*Group",
scope => 'topic',
search => '1',
type => 'query',
nosummary => 'on',
nosearch => 'on',
noheader => 'on',
nototal => 'on',
noempty => 'on',
format => '$topic',
separator => '',
);
my $curUser = $app->user;

try {
$app->user( $app->cfg->data->{SuperAdminGroup} );
$app->search->searchWeb(
_callback => \&_collateGroups,
_cbdata => {
list => $this->groupsList,
users => $users
},
web => $Foswiki::cfg{UsersWebName},
topic => "*Group",
scope => 'topic',
search => '1',
type => 'query',
nosummary => 'on',
nosearch => 'on',
noheader => 'on',
nototal => 'on',
noempty => 'on',
format => '$topic',
separator => '',
);
}
catch {
Foswiki::Exception::Fatal->rethrow($_);
}
finally {
$app->user($curUser);
};
}
return $this->groupsList;
}
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/lib/Unit/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sub setUrl {

#print STDERR "\t setting $param, ".join(',', @{$params{$param}})."\n";
}
$this->path_info( Foswiki::Sandbox::untaintUnchecked($path) );
$this->pathInfo( Foswiki::Sandbox::untaintUnchecked($path) );

#print STDERR "pathinfo = $path\n";
}
Expand Down
7 changes: 1 addition & 6 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,7 @@ sub runOne {
# exceptions with stacktrace for simplified error tracing.
local $SIG{__DIE__} = sub {
my $e = shift;
if ( ref($e) && $e->isa('Foswiki::Exception') ) {
$e->rethrow;
}
else {
Foswiki::Exception::Fatal->rethrow($e);
}
Foswiki::Exception::Fatal->rethrow($e);
}
if DEBUG;
$tester->set_up($test);
Expand Down
11 changes: 2 additions & 9 deletions UnitTestContrib/test/unit/AccessControlTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ around set_up => sub {
my $users_web = $this->users_web;
($topicObject) =
Foswiki::Func::readTopic( $users_web, "ReservoirDogsGroup" );
my $curUser = $this->app->user;
$topicObject->text(<<"THIS");
* Set GROUP = MrWhite, $users_web.MrBlue
* Set ALLOWTOPICVIEW = $users_web.ReservoirDogsGroup
Expand Down Expand Up @@ -135,6 +136,7 @@ sub PERMITTED {
# Test that explicitly defined users are denied topic view
sub test_denytopic {
my $this = shift;

my ($topicObject) =
Foswiki::Func::readTopic( $this->test_web, $this->test_topic );
my $users_web = $this->users_web;
Expand Down Expand Up @@ -880,15 +882,6 @@ THIS
undef $topicObject;

# Request the page with the full UI
#my $query = Unit::Request->new(
# initializer => {
# webName => [ $this->test_web ],
# topicName => ["$test_topic"],
# }
#);
#$query->path_info( "/" . $this->test_web . "/$test_topic" );
#$query->method('GET');
#$query->action('view');
my $viewUrl = $cfg->getScriptUrl( 0, 'view', $this->test_web, $test_topic );

#$query->uri("$viewUrl");
Expand Down
Loading

0 comments on commit 5f383d3

Please sign in to comment.