Repository navigation
Fix extension loading and integer role handling on CakePHP 5 - #124
Merged
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two issues break the plugin on CakePHP 5:
Extension loading.
Service::_loadExtensions()andAction::_loadExtensions()still read the CakePHP 4 shape returned byObjectRegistry::normalizeArray()($properties['class']/$properties['className']). Since CakePHP 5,normalizeArray()returns aname => configmap and only setsclassNamefor plugin-prefixed names, so:ObjectRegistry::load(): Argument #1 ($name) must be of type string, null given(
src/Service/Service.php:925);UserFormatting) fails thesame way (
src/Service/Action/Action.php:397).Integer roles.
ApiRbac::checkPermissions()passes the role straight tothe RBAC rules, but
CakeDC\Auth\Rbac\Rules\Rule::allowed()types it asstring. Apps that store the role as an integer group id getRule::allowed(): Argument #2 ($role) must be of type string, int given(
src/Rbac/ApiRbac.php:194).Changes
Service::_loadExtensions(): iteratenormalizeArray()as$name => $configand call
$registry->load($name, $config).Action::_loadExtensions(): call$registry->load($name, $properties), whichworks for both plugin-prefixed and app extensions.
ApiRbac::checkPermissions(): cast the role tostringbefore it is matchedand passed to the rules.
Tests
tests/TestCase/Service/ExtensionLoadingTest.php: a service with a configuredextension and an action with a plugin-less app extension both load without a
TypeError.tests/TestCase/Rbac/ApiRbacTest.php(+RoleCapturingRule): an integer roleis passed to the rule as a string.
All three tests fail on the current
12.x-cake5.0with theTypeErrors above andpass with the fix. Full suite:
OK (130 tests, 503 assertions).Notes
_matchPermission()keeps its untyped$role; the cast incheckPermissions()covers both the permission matching and the rule call.13.x-cake5.4in a separate PR.