diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a08114..84a9678 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,4 +124,4 @@ jobs: - name: Run phpstan if: success() || failure() run: composer stan - continue-on-error: true + continue-on-error: true \ No newline at end of file diff --git a/src/Rbac/Rbac.php b/src/Rbac/Rbac.php index e86bf9c..d65eebf 100644 --- a/src/Rbac/Rbac.php +++ b/src/Rbac/Rbac.php @@ -170,7 +170,11 @@ protected function _matchPermission(array $permission, array|ArrayAccess $user, 'action' => $params['action'] ?? null, 'role' => $role, ]; - if (!$user && ($permission['bypassAuth'] ?? false) !== true) { + $bypass = $permission['bypassAuth'] ?? false; + if (is_callable($bypass)) { + $bypass = $bypass($user, $role, $request); + } + if (!$user && $bypass !== true) { return null; } foreach ($permission as $key => $value) { diff --git a/tests/TestCase/Authenticator/CookieAuthenticatorTest.php b/tests/TestCase/Authenticator/CookieAuthenticatorTest.php index b74117f..e2c1b34 100644 --- a/tests/TestCase/Authenticator/CookieAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/CookieAuthenticatorTest.php @@ -59,7 +59,6 @@ public function testPersistIdentity($setCookie, $field, array $post, array $sess 'Authentication.Password', ]); $uri = new Uri('/login'); - $uri->base = null; $request = new ServerRequest(); $request = $request->withUri($uri); diff --git a/tests/TestCase/Authenticator/TwoFactorAuthenticatorTest.php b/tests/TestCase/Authenticator/TwoFactorAuthenticatorTest.php index b72e5cf..8f07227 100644 --- a/tests/TestCase/Authenticator/TwoFactorAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/TwoFactorAuthenticatorTest.php @@ -30,7 +30,6 @@ class TwoFactorAuthenticatorTest extends TestCase public function testAuthenticateFailedNoData() { $uri = new Uri('/testpath'); - $uri->base = null; $request = new ServerRequest(); $request = $request->withUri($uri); $identifiers = new IdentifierCollection([ @@ -54,7 +53,6 @@ public function testAuthenticateFailedNoData() public function testAuthenticateFailedInvalidUrl() { $uri = new Uri('/testpath'); - $uri->base = null; $request = new ServerRequest(); $request = $request->withUri($uri); $request->getSession()->write( @@ -85,7 +83,6 @@ public function testAuthenticateFailedInvalidUrl() public function testAuthenticate() { $uri = new Uri('/testpath'); - $uri->base = null; $request = new ServerRequest(); $request = $request->withUri($uri); $request->getSession()->write( diff --git a/tests/TestCase/Controller/Component/OneTimePasswordAuthenticatorComponentTest.php b/tests/TestCase/Controller/Component/OneTimePasswordAuthenticatorComponentTest.php index 5c99e86..c951103 100644 --- a/tests/TestCase/Controller/Component/OneTimePasswordAuthenticatorComponentTest.php +++ b/tests/TestCase/Controller/Component/OneTimePasswordAuthenticatorComponentTest.php @@ -69,7 +69,8 @@ public function setUp(): void $this->request->expects($this->any())->method('is')->will($this->returnValue(true)); $this->Controller = new Controller($this->request); $this->Registry = $this->Controller->components(); - $this->Controller->OneTimePasswordAuthenticator = new OneTimePasswordAuthenticatorComponent($this->Registry); + $this->Controller->components()->set('OneTimePasswordAuthenticator', new OneTimePasswordAuthenticatorComponent($this->Registry)); + //$this->Controller->OneTimePasswordAuthenticator = new OneTimePasswordAuthenticatorComponent($this->Registry); } /** @@ -92,7 +93,8 @@ public function tearDown(): void */ public function testInitialize() { - $this->Controller->OneTimePasswordAuthenticator = new OneTimePasswordAuthenticatorComponent($this->Registry); + //$this->Controller->OneTimePasswordAuthenticator = new OneTimePasswordAuthenticatorComponent($this->Registry); + $this->Controller->components()->set('OneTimePasswordAuthenticator', new OneTimePasswordAuthenticatorComponent($this->Registry)); $this->assertInstanceOf(OneTimePasswordAuthenticatorComponent::class, $this->Controller->OneTimePasswordAuthenticator); } diff --git a/tests/TestCase/Rbac/RbacTest.php b/tests/TestCase/Rbac/RbacTest.php index 27338da..7b0814b 100644 --- a/tests/TestCase/Rbac/RbacTest.php +++ b/tests/TestCase/Rbac/RbacTest.php @@ -19,6 +19,7 @@ use CakeDC\Auth\Rbac\Rules\Owner; use CakeDC\Auth\Test\App\Auth\Rule\SampleRule; use Exception; +use PHPUnit\Framework\Attributes\DataProvider; use Psr\Log\LogLevel; use ReflectionClass; use RuntimeException; @@ -183,12 +184,13 @@ public function testAuthorize($permissions, $user, $requestParams, $expected) $this->assertSame($expected, $result); } - public function providerAuthorize() + public static function providerAuthorize() { - $trueRuleMock = $this->getMockBuilder(Owner::class) + $testCase = new static(RbacTest::class); + $trueRuleMock = $testCase->getMockBuilder(Owner::class) ->onlyMethods(['allowed']) ->getMock(); - $trueRuleMock->expects($this->any()) + $trueRuleMock->expects($testCase->any()) ->method('allowed') ->willReturn(true); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 757761e..fb2ad8f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -92,7 +92,7 @@ 'default' => [ 'engine' => 'File', ], - '_cake_core_' => [ + '_cake_translations_' => [ 'className' => 'File', 'prefix' => 'users_myapp_cake_core_', 'path' => CACHE . 'persistent/',