Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,12 @@ def _parse_int(value: Any, field: str) -> int:
if isinstance(value, str):
clean = value.strip()
if clean and clean.lstrip("+-").isdigit():
return int(clean)
try:
return int(clean)
except ValueError as exc:
raise HTTPException(
status_code=400, detail=f"{field} must be an integer"
) from exc
raise HTTPException(status_code=400, detail=f"{field} must be an integer")


Expand Down
20 changes: 17 additions & 3 deletions tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def test_admin_bounty_api_rejects_fractional_integer_fields(
headers={"x-mergework-admin-token": "admin-token-for-tests"},
json={**payload, "max_awards": 1.5},
)
oversized_issue = client.post(
oversized_integer_issue = client.post(
"/api/v1/bounties",
headers={"x-mergework-admin-token": "admin-token-for-tests"},
json={
Expand All @@ -248,13 +248,27 @@ def test_admin_bounty_api_rejects_fractional_integer_fields(
"issue_url": f"https://github.com/ramimbo/mergework/issues/{2**63}",
},
)
oversized_string_issue = client.post(
"/api/v1/bounties",
headers={"x-mergework-admin-token": "admin-token-for-tests"},
json={**payload, "issue_number": "9" * 5000},
)
oversized_string_awards = client.post(
"/api/v1/bounties",
headers={"x-mergework-admin-token": "admin-token-for-tests"},
json={**payload, "max_awards": "9" * 5000},
)

assert fractional_issue.status_code == 400
assert fractional_issue.json()["detail"] == "issue_number must be an integer"
assert fractional_awards.status_code == 400
assert fractional_awards.json()["detail"] == "max_awards must be an integer"
assert oversized_issue.status_code == 400
assert oversized_issue.json()["detail"] == "issue_number is too large"
assert oversized_integer_issue.status_code == 400
assert oversized_integer_issue.json()["detail"] == "issue_number is too large"
assert oversized_string_issue.status_code == 400
assert oversized_string_issue.json()["detail"] == "issue_number must be an integer"
assert oversized_string_awards.status_code == 400
assert oversized_string_awards.json()["detail"] == "max_awards must be an integer"


def test_admin_webhook_events_api_lists_and_filters_processing_outcomes(
Expand Down
Loading