fix(sentry): keep scope validation alive when Sentry returns an empty error body - #6814
Closed
L4XB wants to merge 1 commit into
Closed
fix(sentry): keep scope validation alive when Sentry returns an empty error body#6814L4XB wants to merge 1 commit into
L4XB wants to merge 1 commit into
Conversation
… error body validate_scopes called response.json() on every failed request. Sentry answers the deprecated /plugins/webhooks/ endpoint with a 404 and an empty text/html body, so the JSONDecodeError escaped, the whole validation failed and every scope showed "Not checked" even though the provider was connected and pulling alerts. Read the failure detail through one helper that falls back to "HTTP <code>" when the body is not JSON or carries no detail, and use it at all four sites so a single bad response only marks its own scope.
Author
|
Closing as superseded: #6813 landed the production fix for #6812 first, and its The half that is still missing is the tests — #6813 merged without any, and there is no test file for this provider on |
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 #6812.
What happened
SentryProvider.validate_scopes()calledresponse.json()on every non-OK response. Sentry answers the deprecated/plugins/webhooks/endpoint used for theproject:writecheck with a 404 and an emptytext/htmlbody, soresponse.json()raisedJSONDecodeError, the exception escapedvalidate_scopes, and the UI showed "Failed to revalidate scopes" with every scope on "Not checked" even though the provider was connected and pulling alerts.Change
A small helper
_scope_failure_detail(response)readsdetailfrom a JSON body when there is one and otherwise falls back toHTTP <status>; the four failure sites (event:readwith and without a configured project,project:read,project:write) use it. A single bad response now marks only its own scope, and a JSON error withoutdetailreports the status instead of storingNone.Not changed: the
/plugins/webhooks/endpoint itself. Whether theproject:writecheck should move to a non-legacy endpoint is a separate question; with this fix it degrades to"HTTP 404"for that scope instead of breaking the others.Tests
New
tests/test_sentry_provider.pybuilds aSentryProviderfrom aProviderConfigand patchesrequests.get/requests.postwith realrequests.Responseobjects, so.okand.json()behave as on the wire:text/htmlbody on the webhook POST →{"event:read": True, "project:read": True, "project:write": "HTTP 404"}detail→ the detail text is reported as beforedetail→"HTTP 401"for every scope