fix: preserve failure cause in CliLoginTokenAuthenticator - #53
Open
turegjorup wants to merge 1 commit into
Open
Conversation
onAuthenticationFailure() discarded the cause entirely, and the CacheException/TokenNotFoundException catch in authenticate() had no variable, so the underlying failure was unrecoverable from logs. Both now chain the cause via previous, mirroring OpenIdLoginAuthenticator. Also documents the CustomUserMessageAuthenticationException that authenticate() already throws; its absence made PHPStan read the tests' catch blocks as dead.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #53 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 62 62
===========================================
Files 9 9
Lines 282 282
===========================================
Hits 282 282
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
CliLoginTokenAuthenticatordiscarded the cause of every CLI login failure.onAuthenticationFailure()threw a bareAuthenticationException('Error occurred validating login token')with no message and noprevious, and theCacheException|TokenNotFoundExceptioncatch inauthenticate()had no variable at all — so a cache outage was indistinguishable from an expired token in the logs.Both now chain the cause via
previous, mirroring the fix applied toOpenIdLoginAuthenticatorin #52. Symfony's security component still renders only the safe message key to the user.This is the sibling half of #52: the two authenticators had drifted, and only one of them was fixed.
Files Changed
src/Security/CliLoginTokenAuthenticator.php- chainpreviousinonAuthenticationFailure(); give theCacheException|TokenNotFoundExceptioncatch a variable and pass it asprevious; document theCustomUserMessageAuthenticationExceptionthatauthenticate()already throwstests/Security/CliLoginTokenAuthenticatorTest.php- assert the chained cause on both catch paths and ononAuthenticationFailure(), including that the cause's code is preservedCHANGELOG.md- entry under[Unreleased]/ FixedNote on the docblock:
authenticate()declared only@throws UsernameDoesNotExistException, so PHPStan read the tests' newcatch (CustomUserMessageAuthenticationException)blocks as dead code. The docblock was incomplete — the method throws that type directly in its own body — so the fix is to document it rather than add acatch.neverThrownignore. This followsLoginController::login(), which already documents its framework concretes.Test Plan
task test:coverage— all tests pass, coverage stays at 100% (9/9 classes, 27/27 methods, 261/261 lines)task test:mutation— 115/115 mutants killed, Covered Code MSI 100% (threshold 95)task analyze:php— PHPStan max level + custom exception-contract rules: no errors; the new throw satisfiesWrappedExceptionChainsPrevious, and no new ignores were addedtask test:matrix— PHP 8.3/8.4/8.5 × prefer-lowest/prefer-stable: all 6 combinations passtask lint:php,lint:markdown,lint:yaml,composer validate --strict,composer audit— all clean