Repository navigation
test(auth): pin that a 401 answer to logout resolves and signs out - #33
Merged
Merged
Conversation
The global 401 listener also ends the state, so the App tests passed whether AuthProvider.logout() resolved or rejected on a 401. Test the provider's promise directly: a 401 and a 204 resolve and leave the state anonymous (signed out, not "session ended"), a 500 rejects and keeps the user signed in.
knittingcode
added a commit
that referenced
this pull request
Oct 29, 2026
knittingcode
added a commit
that referenced
this pull request
Oct 29, 2026
knittingcode
added a commit
that referenced
this pull request
Oct 29, 2026
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
Adds
frontend/src/auth/AuthProvider.test.tsx, which testsAuthProvider.logout()directly. It pins that a 401 answer toPOST /api/v1/auth/logoutresolves and leaves the user signed out. This PR changes tests only; there is no behaviour change.Motivation and technical context
This is a follow-up from the #32 review (Low).
AuthProvider.logout()treats a 401 as "the session had already ended": it resolves and sets the state to anonymous withended: false. Any other failure rejects and keeps the user signed in.No test pinned the 401 branch:
apiRequestcalls the global unauthenticated listener, and that listener already sets the state to anonymous.logout()rethrows the 401.Implementation
frontend/src/auth/AuthProvider.test.tsxrenders theAuthProviderwith a small probe component. The probe shows the auth state and gives the test the context, so the test can await the promise thatlogout()returns. The fake API is the existingsrc/test/fakeApi.ts.There are three cases:
anonymous ended=false(signed out by the user, not "your session has ended").anonymous ended=false.authenticated. This is the contrast case for the 401 branch.Testing performed
Synced with main 1badf76 (2026-10-28)
The branch was brought up to date with a normal merge of
origin/main1badf76 (#38, #42; #39 was already in), headaefca2e5. The merge was clean, and the PR diff against main is still onlyfrontend/src/auth/AuthProvider.test.tsx.AuthProvider.tsx,AppShell.tsx,App.test.tsx, the backend logout controller,security.yaml,RequestOriginGuardand their tests are identical to main.Local checks on the merged tree (Node 24.13,
npm ci --ignore-scripts; the engine field asks for 24.15 or later):tsc --buildandeslint --max-warnings=0 .: exit 0.AuthProvider.tsx, each reverted afterwards:ended: true: only the new 401 and 204 tests fail (2 failed, 42 passed).CI run 40752031731 on
aefca2e5(workflow CI, pull_request): success. Allocator unit 288/288, allocator integration 140/140 (24 scenarios), PHPUnit unit OK (156 tests), integration OK (278 tests, 2537 assertions), 53 of 53 negative controls, backend 18/18 (BE-03 composer audit passed), Vitest 44/44 (frontend 5/5), application stack 124/124, production-like 39/39, container scan 20/20; guard 36/36, 73/73, 87/87, 221/221.Earlier sync with main 202ea9e (historical)
The branch was brought up to date with a normal merge of
origin/main202ea9e (#39), head6d729805. The merge was clean, and the PR diff against main is still onlyfrontend/src/auth/AuthProvider.test.tsx.Local checks on the merged tree (Node 24.13,
npm ci --ignore-scripts):tsc --buildandeslint --max-warnings=0 .: no errors.AuthProvider.tsx, each reverted afterwards:ended: true: only the new 401 and 204 tests fail.CI run 40669321115 on
6d729805: failure, not caused by this PR. Repository guard passed (36/36, 73/73, 46/46). Dev environment failed in Backend checks atBE-03 composer audit, because advisory PKSA-qhjm-rpqc-qkn6 (GHSA-9vw2-f4vp-x7gf) was published on 2026-10-27 forphpunit/phpunit>=13.4.0,<13.4.4. Main locks 13.4.3. The rest of that step passed: unit OK (156 tests), integration OK (278 tests, 2537 assertions), 53 of 53 negative controls, backend TOTAL 18 passed=17 failed=1. Because of that failure, the Frontend checks, Application stack, Production-like stack and Trivy steps were skipped. A green run needs the phpunit update on main first, followed by another sync.Original run (main e03d151 plus the test)
All checks ran in the dev web image (
flowcrm-1d1ca1-web, read-only mounts,--network none).On this branch:
tsc --build: TSC_OKeslint --max-warnings=0 .: ESLINT_OKvite build: BUILD_OKAgainst a deliberately broken copy:
AuthProvider.tsxwas changed so that a 401 also rethrows (one addedthrow error;after the 401 check). The rest of the source was this branch, run in a scratch copy:promise rejected "ApiProblem: unauthenticated …" instead of resolving.CI run 40192849583 on f33745b: success. It reported unit 230/230, integration 140/140, backend 18/18, Vitest 44/44 (5 files; frontend 5/5), application stack 114/114, production-like 38/38, container scan 14/14, and guard 36/36 and 73/73.
Security considerations
This PR changes tests only. The test pins the #32 rule that only a completed logout (204) or an already-ended session (401) signs the user out in the SPA. Every other failure keeps the user signed in and shows an alert.
Known limitations
backend/openapi.yamllists 204, 403, 415 and 500 for logout, not 401, but the SPA handles a 401 the same way as everywhere else.