Standardize middleware error responses; handle unprovisioned users and expired sessions#362
Merged
Merged
Conversation
…dd case for unprovisioned users and session expiration
Middleware now returns a standardized JSON error body instead of the plaintext "unauthorized". Update the no-auth /users/current assertion to match on the JSON code field.
7 tasks
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.
Rehome of #360 onto an in-repo branch so Snyk/CI run. Original work and credit: @tarratsco (Onix Tarrats Calderon); his commit is preserved as-authored.
What this does
Middleware now returns a single standardized JSON error shape (
{ "error": ..., "code": ... }) on every rejection, replacing the prior plaintexthttp.Errorresponses. This lets the frontend interceptor branch on a stablecoderather than parsing status alone (see ztmf-ui#403).Rejection cases are now distinguished:
UNAUTHORIZED("your session has expired")ACCOUNT_NOT_PROVISIONED(terminal "contact your administrator", no retry loop)FORBIDDEN_ORIGINPreviously a not-found user and a DB error both collapsed into 401, which the frontend could not tell apart from an expired session.
Changes layered on top of the original PR
test(emberfall): the no-auth 401 assertion on/users/currentwas matching the old plaintextunauthorizedbody; updated it to match the new JSONcodefield. (The original fork PR could not run the E2E suite because Snyk/CI org secrets are unavailable on forks, so this drift was not caught there.)Testing
make test-unit(auth package): pass, 8/8 including the newTestMiddlewarecasesmake test-e2e(isolated ephemeral DB): pass, 118/118Closes #360