-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CVE-2021-28661] Add a CanViewPermissionChecker if permission checker…
… is null
- Loading branch information
1 parent
90570dc
commit 1696145
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace SilverStripe\GraphQL\Tests\Permission; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Permission\PermissionCheckerAware; | ||
use SilverStripe\GraphQL\Permission\QueryPermissionChecker; | ||
use SilverStripe\Security\Member; | ||
use SilverStripe\ORM\Filterable; | ||
use SilverStripe\Core\Injector\Injector; | ||
|
||
class PermissionCheckerAwareTest extends SapphireTest | ||
{ | ||
public function testCanViewPermissionCheckerAddedIfNull() | ||
{ | ||
$scaffolder = new class() { | ||
use PermissionCheckerAware; | ||
}; | ||
$checker = $scaffolder->getPermissionChecker(); | ||
$defaultChecker = Injector::inst()->get(QueryPermissionChecker::class . '.default'); | ||
$this->assertNotNull($checker); | ||
$this->assertSame(get_class($defaultChecker), get_class($checker)); | ||
} | ||
|
||
public function testDefaultCanViewPermissionCheckerNotAddedIfSet() | ||
{ | ||
$scaffolder = new class() { | ||
use PermissionCheckerAware; | ||
}; | ||
$nonChecker = new class () implements QueryPermissionChecker { | ||
public function applyToList(Filterable $list, Member $member = null) | ||
{ | ||
return $list; | ||
} | ||
|
||
public function checkItem($item, Member $member = null) | ||
{ | ||
return true; | ||
} | ||
|
||
public function testMe() | ||
{ | ||
return true; | ||
} | ||
}; | ||
$scaffolder->setPermissionChecker($nonChecker); | ||
$checker = $scaffolder->getPermissionChecker(); | ||
$this->assertNotNull($checker); | ||
$this->assertTrue(method_exists($checker, 'testMe')); | ||
} | ||
} |