fix(panelSessionGate): correct the Lua user-path match and execute the gate in tests (Refs #963) - #967
Open
Shabbir7890 wants to merge 1 commit into
Conversation
…e gate in tests (Refs MagnaCapax#963) panel_user() used the PCRE idiom "($|/)" inside a Lua string.match, where it is the literal text "$|/" and matches no real path. The gate therefore returned nil on every request and delegated to Basic auth, so the opt-in cookie login was inert wherever enabled. Match the two real shapes explicitly: a trailing-slash prefix or the bare /user-<name>. PanelSessionGateSourceTest only asserts source strings, which is how this shipped green. Add PanelSessionGateExecutionTest, which runs the real .lua under a stubbed lighty global and asserts the decision reached (login handler resolves the user, html visitor without a session gets 302, a request with Basic creds delegates, a non-panel path never sets REMOTE_USER). The dev container gets lua5.4 so the test runs; it skips cleanly where no Lua is present.
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.
Refs #963.
This takes the pattern fix from #963 and adds the executing test the issue asks for.
The fix.
panel_user()matched"^/user%-([a-z][a-z0-9]*)($|/)". In a Lua pattern that trailing group is the literal text$|/(Lua has no alternation, and$anchors only as the final character), so it matched no real path,panel_user()returned nil for every request, and the gate delegated straight to Basic auth. I replaced it with the two shapes that actually occur:The test.
PanelSessionGateSourceTestonly matches source strings, which is exactly how this shipped green.PanelSessionGateExecutionTestruns the realpanelSessionGate.luaunder a stubbedlightyglobal and asserts the decision it reaches:/user-<name>/panelSessionLogin.phpresolves the user and setsREMOTE_USER/user-<name>form matches too)REMOTE_USERI checked it is a real guard: with the old
($|/)pattern the first two of those fail; with the fix all four pass.Running the test. It needs a Lua interpreter (any of lua5.4/lua5.3/lua5.1/lua) and skips cleanly when none is present, so it never turns a Lua-less host red. I added
lua5.4to the devDockerfileand a line tocheck-tools.sh. I couldn't push the workflow file myself (noworkflowscope on my token), so the CIbuildjob needs the same one-liner to actually run the test there rather than skip it:Validation. Built the dev image and ran the full development suite against a clean clone of the branch: 3169 tests, same 25 environmental failures as clean main (the php-xml/curl/uid-0 set from #936), no new failures.
php -lclean on the changed PHP.Scope note: this is defect 1 only. Defect 2 (the REMOTE_USER / extern-authn handoff) is written up in #963 as a lead that still needs a real-vhost check — I'd rather confirm that on an actual per-user vhost before proposing the
method => "extern"change, so it can go on top of this once verified.