Repository navigation
Fix three class names held in strings, and gate the shape - #1537
Merged
Merged
Conversation
Found by running the namespaced plugins against a live install rather than
reasoning about them. A class name in a PHP string is resolved as written,
from the global namespace -- the enclosing namespace is not applied and
`use` is not consulted -- so every one of these named a class that stopped
existing when ADR 0013 §2 retired the reverse aliases. None of them throw:
the predicate answers "no such class" and the caller takes its fallback.
- PluginRunner::_discoverTasks() handed a bare basename to
is_subclass_of(), so a namespaced task is not a PluginTask and the
daemon skips every plugin task, logging only "Skipping, not a
PluginTask". The same call's SECOND argument already carried a comment
recording this exact failure.
- Plugin::getManager() handed plugins.pName . 'Manager' to class_exists()
and fell back to PluginManager. installdb() then correctly reports a
manager file it cannot load, so every plugin install throws.
- OpenAPI::_permission() guarded on method_exists('Authorization', ...),
false on every call, so the published API document described the whole
REST API as needing no permission. The guard is gone rather than
qualified: the method is declared in this repository, beside the file
that was testing for it.
The first two go through FOGBase::qualify(), which leaves a plugin still in
the global namespace untouched -- so both spellings work, which is the
compatibility guarantee this branch is built on.
tests/string-class-literals-are-qualified.test.php is the general gate: a
token-driven scan for a bare class literal in method_exists(), class_exists(),
is_subclass_of() and friends, allowing classes PHP itself declares. It counts
2 with the fixes reverted. tests/plugin-namespace.test.php gains the two
plugin call sites -- getManager() executed against a fixture plugin,
_discoverTasks() anchored on its whole expression because it needs a
database.
Co-Authored-By: Claude <noreply@anthropic.com>
The release every plugin class in FOG\Plugins\<Plugin> ships in, paired with the core autoload arm that resolves it (#1535). Without this bump the change never reaches a server: the installer reads this constant to pick which plugins release to download. It rides in this pull request rather than one of its own, because the namespaced plugins need the two fixes here. On a core without them every plugin install throws and every plugin task is skipped -- so a pin bump landing first would ship a broken combination for however long it sat alone. Co-Authored-By: Claude <noreply@anthropic.com>
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.
Follow-up to #1535, found by running the namespaced plugin tree against a live install rather than reasoning about it. Three separate sites, one mistake.
A class name held in a string is resolved as written, from the global namespace. The enclosing
namespaceis not applied anduseis not consulted. Since ADR 0013 §2 retired the reverse aliases, nothing declares the global spellings any more — so each of these named a class that does not exist. None of them throw: the predicate answers "no such class" exactly as it would for a genuine absence, and the caller quietly takes its fallback.PluginRunner::_discoverTasks()is_subclass_of(basename($file, '.task.php'), …)Skipping, not a PluginTaskPlugin::getManager()class_exists(pName . 'Manager')PluginManager;installdb()then correctly reports a manager file it cannot load, so every plugin install throwsOpenAPI::_permission()method_exists('Authorization', …)The same call in
_discoverTasks()already carried a comment recording this exact failure for its second argument. It was written for one argument and not the other.The fixes
The two plugin sites go through
FOGBase::qualify(), which leaves a plugin still in the global namespace untouched — both spellings work, which is the compatibility guarantee #1535 is built on.OpenAPI::_permission()'s guard is deleted rather than qualified. It bought nothing even when it worked: the method it tests for is declared in this repository, beside the file that was testing for it. (PHPStan says the same thing once the name resolves —function.alreadyNarrowedType.)The gate
tests/string-class-literals-are-qualified.test.phpis new and general: a token-driven scan ofpackages/for a bare class literal inmethod_exists(),class_exists(),is_subclass_of(),property_exists()and friends, checking argument 0 — and argument 1 foris_subclass_of()/is_a(), which is the position that cost_discoverTasks()its tasks. A literal PHP itself declares (class_exists('PDO')) is allowed; those really are global.Token-driven rather than regex on purpose: the same text already appears inside a comment in
FOGURLRequests.php, recounting this exact bug in prose.It counts 2 with the fixes reverted and 0 now.
tests/plugin-namespace.test.phpgains the two plugin call sites —getManager()executed against a fixture plugin (the mutation returnsFOG\Managers\PluginManager, which is the reported symptom), and_discoverTasks()anchored on its whole expression, because the method itself needs a database.Verification
git checkout --.phpstanpasses clean, unscoped.getManager()+installdb()now succeed for all seven installed plugins (ldap, location, windowskey, ou, ntfy, helloworld, oidc) — this is what threw before the fix. The one real.task.phpin fog-plugins resolves:helloworldheartbeatis not aPluginTask,FOG\Plugins\Helloworld\HelloWorldHeartbeatis.Downstream
No change to
Route::$validClasses, so nothing for FogApi to sync. The OpenAPI change alters the content of the published document — every operation now carries the permission it always required — without changing which paths it describes.Also here: the
FOG_PLUGINS_VERSIONbumpv1.6.21→v1.6.22, the fog-plugins release that carries the namespaces (FOGProject/fog-plugins#33). It rides in this PR rather than one of its own because the two fixes above are its precondition — on a core without them, every plugin install throws and every plugin task is skipped. A pin bump landing first would ship that combination for however long it sat alone.