Skip to content

Commit eb2e113

Browse files
Reject boolean session timestamp values
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 1475690 commit eb2e113

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

hyperbrowser/models/session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ def parse_timestamp(cls, value: Optional[Union[str, int]]) -> Optional[int]:
144144
"""Convert string timestamps to integers."""
145145
if value is None:
146146
return None
147+
if isinstance(value, bool):
148+
raise ValueError(
149+
"timestamp values must be integers or plain numeric strings"
150+
)
147151
if type(value) is str:
148152
return int(value)
149153
if isinstance(value, str):

tests/test_session_models.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,25 @@ class _TimestampString(str):
3838
ValidationError, match="timestamp string values must be plain strings"
3939
):
4040
Session.model_validate(payload)
41+
42+
43+
def test_session_model_rejects_boolean_timestamps():
44+
payload = _build_session_payload()
45+
payload["startTime"] = True
46+
47+
with pytest.raises(
48+
ValidationError,
49+
match="timestamp values must be integers or plain numeric strings",
50+
):
51+
Session.model_validate(payload)
52+
53+
54+
def test_session_model_preserves_integer_timestamps():
55+
payload = _build_session_payload()
56+
payload["startTime"] = 1735689600
57+
payload["endTime"] = 1735689660
58+
59+
model = Session.model_validate(payload)
60+
61+
assert model.start_time == 1735689600
62+
assert model.end_time == 1735689660

0 commit comments

Comments
 (0)