From fe61086721b2848d343a67c9261773b7bd83e565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gonz=C3=A1lez?= Date: Thu, 1 Aug 2019 11:42:31 +0100 Subject: [PATCH 1/4] #47 fix callable plugin name --- src/Rbac/Rbac.php | 2 +- tests/TestCase/Rbac/RbacTest.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Rbac/Rbac.php b/src/Rbac/Rbac.php index 3c013f0..6e51013 100644 --- a/src/Rbac/Rbac.php +++ b/src/Rbac/Rbac.php @@ -171,7 +171,7 @@ protected function _matchPermission(array $permission, array $user, $role, Serve $key = ltrim($key, '*'); } - if (is_callable($value)) { + if (!is_string($value) && is_callable($value)) { $return = (bool)call_user_func($value, $user, $role, $request); } elseif ($value instanceof Rule) { $return = (bool)$value->allowed($user, $role, $request); diff --git a/tests/TestCase/Rbac/RbacTest.php b/tests/TestCase/Rbac/RbacTest.php index d04c4ed..1c21fe7 100644 --- a/tests/TestCase/Rbac/RbacTest.php +++ b/tests/TestCase/Rbac/RbacTest.php @@ -1099,6 +1099,29 @@ function () { //expected false, ], + 'plugin-name-matches-callable-function' => [ + //permissions + [[ + 'plugin' => 'Ord', + 'controller' => 'Tests', + 'action' => 'test', + 'role' => 'admin', + ]], + //user + [ + 'id' => 1, + 'username' => 'luke', + 'role' => 'admin', + ], + //request + [ + 'plugin' => 'Ord', + 'controller' => 'Tests', + 'action' => 'test' + ], + //expected + true, + ], ]; } From 3638d31cd2b62ce45e923b53705a1cd9cf056c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gonz=C3=A1lez?= Date: Thu, 1 Aug 2019 11:43:38 +0100 Subject: [PATCH 2/4] #47-fix-callable-plugin-name fix cs --- src/Authentication/AuthenticationService.php | 1 + .../DefaultTwoFactorAuthenticationChecker.php | 1 + src/Social/Mapper/AbstractMapper.php | 1 + src/Test/BaseTraitTest.php | 10 +++++++--- src/Traits/ReCaptchaTrait.php | 1 + .../TestCase/Authenticator/CookieAuthenticatorTest.php | 1 + tests/TestCase/Policy/RbacPolicyTest.php | 1 + tests/TestCase/Policy/SuperuserPolicyTest.php | 1 + tests/TestCase/Social/Service/ServiceFactoryTest.php | 1 + 9 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Authentication/AuthenticationService.php b/src/Authentication/AuthenticationService.php index 8af40ed..a871609 100644 --- a/src/Authentication/AuthenticationService.php +++ b/src/Authentication/AuthenticationService.php @@ -31,6 +31,7 @@ class AuthenticationService extends BaseService * @var Failure[] */ protected $failures = []; + /** * Proceed to google verify action after a valid result result * diff --git a/src/Authentication/DefaultTwoFactorAuthenticationChecker.php b/src/Authentication/DefaultTwoFactorAuthenticationChecker.php index 5f99933..e80860c 100644 --- a/src/Authentication/DefaultTwoFactorAuthenticationChecker.php +++ b/src/Authentication/DefaultTwoFactorAuthenticationChecker.php @@ -32,6 +32,7 @@ public function __construct($enableKey = null) $this->enabledKey = $enableKey; } } + /** * Check if two factor authentication is enabled * diff --git a/src/Social/Mapper/AbstractMapper.php b/src/Social/Mapper/AbstractMapper.php index f4cd467..c06de45 100644 --- a/src/Social/Mapper/AbstractMapper.php +++ b/src/Social/Mapper/AbstractMapper.php @@ -62,6 +62,7 @@ public function __construct($mapFields = null) } $this->_mapFields = array_merge($this->_defaultMapFields, $this->_mapFields); } + /** * Invoke method * diff --git a/src/Test/BaseTraitTest.php b/src/Test/BaseTraitTest.php index 751aa84..79aade0 100644 --- a/src/Test/BaseTraitTest.php +++ b/src/Test/BaseTraitTest.php @@ -53,10 +53,15 @@ protected function _isVerboseOrDebug() protected function _testPermissions($url, $username, $method, $ajax, $responseCode, $responseContains) { - if ($this->_isVerboseOrDebug()) { + if ($this->_isVerboseOrDebug()) { (new ConsoleIo())->info(__( "\nUrl: {0} Username: {1} Method: {2} Ajax?: {3} Response Code: {4} Response Contains: {5} ", - $url, $username, $method, $ajax, $responseCode, $responseContains + $url, + $username, + $method, + $ajax, + $responseCode, + $responseContains ), 0); } $this->loginAsUserName($username); @@ -101,6 +106,5 @@ public function testPermissions($csv) $this->_testPermissions($url, $username, $method, $ajax, $responseCode, $responseContains); $this->tearDown(); } - } } diff --git a/src/Traits/ReCaptchaTrait.php b/src/Traits/ReCaptchaTrait.php index 41aba59..4160895 100644 --- a/src/Traits/ReCaptchaTrait.php +++ b/src/Traits/ReCaptchaTrait.php @@ -36,6 +36,7 @@ public function validateReCaptchaFromRequest($request) $request->clientIp() ); } + /** * Validates reCaptcha response * diff --git a/tests/TestCase/Authenticator/CookieAuthenticatorTest.php b/tests/TestCase/Authenticator/CookieAuthenticatorTest.php index a3639ba..5095e73 100644 --- a/tests/TestCase/Authenticator/CookieAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/CookieAuthenticatorTest.php @@ -36,6 +36,7 @@ public function dataProviderPersistIdentity() [false, 'my_remember', [], ['remember_me' => 1]], ]; } + /** * testPersistIdentity * diff --git a/tests/TestCase/Policy/RbacPolicyTest.php b/tests/TestCase/Policy/RbacPolicyTest.php index ab0a80f..eb7c1e5 100644 --- a/tests/TestCase/Policy/RbacPolicyTest.php +++ b/tests/TestCase/Policy/RbacPolicyTest.php @@ -112,6 +112,7 @@ public function testGetRbacUseObject() $actual = $policy->getRbac($request); $this->assertSame($rbac, $actual); } + /** * Test getRbac method */ diff --git a/tests/TestCase/Policy/SuperuserPolicyTest.php b/tests/TestCase/Policy/SuperuserPolicyTest.php index 3d74ad6..2c8a57b 100644 --- a/tests/TestCase/Policy/SuperuserPolicyTest.php +++ b/tests/TestCase/Policy/SuperuserPolicyTest.php @@ -36,6 +36,7 @@ public function dataProviderCanAccess() [[], false, ['superuser_field' => 'is_master']], ]; } + /** * Test canAccess method * diff --git a/tests/TestCase/Social/Service/ServiceFactoryTest.php b/tests/TestCase/Social/Service/ServiceFactoryTest.php index 4c53b1c..d59ccee 100644 --- a/tests/TestCase/Social/Service/ServiceFactoryTest.php +++ b/tests/TestCase/Social/Service/ServiceFactoryTest.php @@ -26,6 +26,7 @@ class ServiceFactoryTest extends TestCase * @var ServiceFactory */ public $Factory; + /** * Setup the test case, backup the static object values so they can be restored. * Specifically backs up the contents of Configure and paths in App if they have From 2b764560d256bb467ddb7597fdf19f0db042c09d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gonz=C3=A1lez?= Date: Thu, 1 Aug 2019 11:43:40 +0100 Subject: [PATCH 3/4] fix cs --- src/Test/BaseTraitTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Test/BaseTraitTest.php b/src/Test/BaseTraitTest.php index 79aade0..774c74e 100644 --- a/src/Test/BaseTraitTest.php +++ b/src/Test/BaseTraitTest.php @@ -52,7 +52,6 @@ protected function _isVerboseOrDebug() */ protected function _testPermissions($url, $username, $method, $ajax, $responseCode, $responseContains) { - if ($this->_isVerboseOrDebug()) { (new ConsoleIo())->info(__( "\nUrl: {0} Username: {1} Method: {2} Ajax?: {3} Response Code: {4} Response Contains: {5} ", From ed5bdac018c60918c924e1d29c36b74e881ccd67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gonz=C3=A1lez?= Date: Tue, 20 Aug 2019 09:32:56 +0100 Subject: [PATCH 4/4] #47-fix-callable-plugin-name add missing route --- tests/config/routes.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/config/routes.php b/tests/config/routes.php index c455986..e8275a7 100644 --- a/tests/config/routes.php +++ b/tests/config/routes.php @@ -72,6 +72,11 @@ 'controller' => 'Tests', 'action' => 'one', ]); + $routes->connect('/ord/tests/test', [ + 'plugin' => 'Ord', + 'controller' => 'Tests', + 'action' => 'test', + ]); $routes->fallbacks(\Cake\Routing\Route\DashedRoute::class);