Skip to content

Commit 0a328cf

Browse files
committed
fix(webhook): enforce dict payload and strict bool per CodeRabbit review
data now requires dict[str, Any] and livemode requires StrictBool so malformed payloads raise InvalidRequestError instead of silently coercing (e.g. a JSON-encoded "false" string, or an array/scalar data payload).
1 parent e3567a4 commit 0a328cf

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/shade/models/webhook.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from enum import Enum
1717
from typing import Any
1818

19-
from pydantic import Field
19+
from pydantic import Field, StrictBool
2020

2121
from .base import ShadeObject
2222

@@ -83,6 +83,6 @@ class WebhookEvent(ShadeObject):
8383

8484
id: str
8585
type: str
86-
data: Any
86+
data: dict[str, Any]
8787
created_at: datetime = Field(alias="createdAt")
88-
livemode: bool
88+
livemode: StrictBool

tests/test_webhook_event.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def test_data_stays_a_raw_dict():
4444
assert event.data["status"] == "completed"
4545

4646

47-
def test_data_accepts_non_dict_payloads_unchanged():
48-
event = WebhookEvent.from_dict(_api_response(data=["a", "b"]))
49-
assert event.data == ["a", "b"]
47+
def test_non_dict_data_raises():
48+
with pytest.raises(InvalidRequestError):
49+
WebhookEvent.from_dict(_api_response(data=["a", "b"]))
5050

5151

5252
def test_payload_is_not_mutated():
@@ -88,9 +88,9 @@ def test_livemode_reflects_payload(livemode, expected):
8888
assert event.livemode is expected
8989

9090

91-
def test_livemode_coerced_from_json_falsy_value():
92-
event = WebhookEvent.from_dict(_api_response(livemode="false"))
93-
assert event.livemode is False
91+
def test_livemode_string_value_raises():
92+
with pytest.raises(InvalidRequestError):
93+
WebhookEvent.from_dict(_api_response(livemode="false"))
9494

9595

9696
@pytest.mark.parametrize("field", ["id", "type", "data", "createdAt", "livemode"])

0 commit comments

Comments
 (0)