Stop reporting auth-service failures as invalid tokens - #211
Merged
Conversation
get_current_user raised HTTPException(502) for an unreachable or misbehaving authentication service inside a try whose trailing 'except Exception' rewrote everything as 401 'Authentication failed'. Since HTTPException is an Exception, those deliberate 502s were caught and flattened, so an auth service that was down — or returning 500, or an unexpected status — looked exactly like a mistyped token. That cost real diagnosis time when the AAI returned 500 for a token without a sub claim. Deliberately-raised statuses now propagate unchanged (except HTTPException: raise). An unreachable service and unexpected internal errors return 502. A response body carrying an error field is a real token rejection, so it returns 401. A genuinely invalid token still returns 401. Closes #195
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.
Closes #195
Problem
get_current_userraisedHTTPException(502)for an unreachable or misbehaving authentication service inside atrywhose trailingexcept Exceptionrewrote everything as401 "Authentication failed". SinceHTTPExceptionis anException, those deliberate 502s were caught and flattened — so an auth service that was down, returning 500, or answering an unexpected status looked exactly like a mistyped token.This cost real diagnosis time earlier: the AAI returned 500 for a token without a
subclaim, and the UI reported invalid credentials.Fix
except HTTPException: raisebefore the generic handler, so deliberately-raised statuses reach the caller unchanged.RequestException) and unexpected internal errors return502, not401.errorfield is a real token rejection →401with a clear message.401.Verified
New
tests/test_get_current_user_errors.py: auth-service 500 / unexpected status / unreachable all return 502; invalid token and error-in-body return 401; a valid token returns the user info. Full suite 1176 passed;black/flake8clean.