-
Notifications
You must be signed in to change notification settings - Fork 549
fix(webhooks): address Zaimwa9 feedback - use response.ok and add 2xx tests #7996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,11 +47,11 @@ def test(self, request: Request) -> Response: | |
| else WebhookType.ENVIRONMENT | ||
| ) | ||
| response = send_test_request_to_webhook(webhook_url, secret, webhook_type) | ||
| if response.status_code != 200: | ||
| if not response.ok: | ||
| return Response( | ||
| { | ||
| "detail": "Webhook returned invalid status", | ||
| "body": "Please check the webhook endpoint to validate it returns a 200 OK.", | ||
| "detail": "Webhook returned error status", | ||
| "body": f"Webhook returned HTTP {response.status_code}.", | ||
|
Comment on lines
+50
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: python - <<'PY'
from requests import Response
for code in (201, 301, 400):
response = Response()
response.status_code = code
print(code, response.ok)
PYRepository: Flagsmith/flagsmith Length of output: 185 🏁 Script executed: #!/bin/bash
set -euo pipefail
file="api/webhooks/views.py"
wc -l "$file"
printf '\n--- outline ---\n'
ast-grep outline "$file" --view expanded || true
printf '\n--- relevant lines ---\n'
sed -n '1,120p' "$file" | cat -nRepository: Flagsmith/flagsmith Length of output: 3526 🏁 Script executed: #!/bin/bash
set -euo pipefail
file="api/webhooks/webhooks.py"
wc -l "$file"
printf '\n--- outline ---\n'
ast-grep outline "$file" --view expanded || true
printf '\n--- relevant lines ---\n'
sed -n '1,200p' "$file" | cat -nRepository: Flagsmith/flagsmith Length of output: 9376 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '300,340p' api/webhooks/webhooks.py | cat -nRepository: Flagsmith/flagsmith Length of output: 1822 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '315,335p' api/webhooks/webhooks.py | cat -nRepository: Flagsmith/flagsmith Length of output: 1024 Use an explicit 2xx check here.
Source: MCP tools |
||
| "status": response.status_code, | ||
| }, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Flagsmith/flagsmith
Length of output: 50376
🏁 Script executed:
Repository: Flagsmith/flagsmith
Length of output: 4832
Set
.okexplicitly on the mocked webhook responses.MagicMockmakes.oktruthy by default, so the non-2xx cases still take the success branch and never exercise the error-response assertions. Use a realrequests.Responseor set.ok = Falsefor those cases.🧰 Tools
🪛 ast-grep (0.44.1)
[info] 426-426: use jsonify instead of json.dumps for JSON output
Context: json.dumps(data)
Note: [CWE-116] Improper Encoding or Escaping of Output.
(use-jsonify)
[warning] 409-409: Do not make http calls without encryption
Context: "http://test.webhook.com"
Note: [CWE-319] Cleartext Transmission of Sensitive Information.
(requests-http)