send 400 response to Cinder for some webhook validation errors#23175
send 400 response to Cinder for some webhook validation errors#23175eviljeff merged 2 commits intomozilla:masterfrom
Conversation
I did that, but still received a 200 with I guess I should have used a non-reviewer tools job this time around ? The condition for that is above the one validating the enforcement actions. Edit: yes, that was it. |
yes - I forgot that check comes before the enforcement actions validation. You can just change the |
I got a 201 here,
I got a 500: |
diox
left a comment
There was a problem hiding this comment.
The logic seems fine, just slightly concerned about the disconnect between your STR and my results
well, I didn't test it in that sequence, I just thought up how to test in the least steps... and missed some, apparently! 😬 The 500 would be because the previous request succeeded (201) when it shouldn't have, so actually created the decision. It is a little concerning, but as this patch doesn't change any of the logic around when exceptions are raised - just if they're returned as 200 or 400 - it shouldn't regress anything. |
Fixes: mozilla/addons#14825
Description
Changes what http response code we return for validation errors - i.e. when we can't/won't process the payload.
Context
settings.CINDER_UNIQUE_IDSis because our stage Cinder instance is enabled for addons-dev, addons stage, and also any local testing integration (e.g. pull request testing) so it's quite possible that a given cinder job, decision, or entity id is not valid in a payload simply because it doesn't originate from the same environment that the webhook is registered for. There is no way of filtering webhook responses at the Cinder level either - you either listen for all decisions originating from all environments or none, for example. So we don't want to return a 400 because that would pollute the logs with too many false positives. In Cinder prod the only registered webhook (right now...) is for AMO prod, so those same errors are returned as 400.Doesn't change any functionality - neither 200 or 400 are retried - but will mean that genuine errors will show up as 400 in the Cinder webhook logs (
/settings/webhooks), so we can identify actual errors that may be bugs more easily.This patch doesn't change how we log the errors, or change any of the error handling (e.g. so we re-raise to Sentry), but that could be a follow-up.
Testing
To test you need to replay (and fake) some webhook requests - it's easier if the custom auth is commented out. There are 10 cases where errors are returned - and 4 of those act differently depending on whether it's a prod or non-prod environment - and its probably not practical to test every case for the PR.
A case where a 200 would always be expected:
A case where a 400 would always be expected:
['not-an-amo-action'])A case where a 200 would be expected in a dev env, and 400 in a prod env:
source->job->idto some other id.CINDER_UNIQUE_IDSset toTruein local settingsChecklist
#ISSUENUMat the top of your PR to an existing open issue in the mozilla/addons repository.