Skip to content

Commit e26325a

Browse files
committed
Harden diff-scan processing sentinel
1 parent 9409baa commit e26325a

5 files changed

Lines changed: 22 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "socketdev"
7-
version = "3.4.0"
7+
version = "3.4.1"
88
requires-python = ">= 3.9"
99
dependencies = [
1010
'requests',

socketdev/diffscans/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ def get(self, org_slug: str, diff_scan_id: str, params: Optional[Dict[str, Any]]
4848
if response.status_code == 200:
4949
return response.json()
5050
if response.status_code == 202:
51-
result = {"status": "processing", "id": diff_scan_id}
51+
result = {}
5252
try:
5353
body = response.json()
5454
if isinstance(body, dict):
5555
result.update(body)
5656
except ValueError:
5757
pass
58+
# HTTP 202 always means the requested diff is still processing.
59+
# Keep any additional response fields, but make the polling
60+
# sentinel and requested resource ID authoritative for callers.
61+
result.update({"status": "processing", "id": diff_scan_id})
5862
return result
5963
log.error(f"Error fetching diff scan: {response.status_code}, message: {response.text}")
6064
return {}

socketdev/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.4.0"
1+
__version__ = "3.4.1"

tests/unit/test_all_endpoints_unit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ def test_diffscans_get_processing_empty_body_unit(self):
152152

153153
self.assertEqual(result, {"status": "processing", "id": "diff-123"})
154154

155+
def test_diffscans_get_processing_sentinel_wins_unit(self):
156+
"""Test a 202 body cannot override the SDK's polling sentinel or requested ID."""
157+
self._mock_response(
158+
{"status": "pending", "id": "wrong-id", "retry_after": 5},
159+
202,
160+
)
161+
162+
result = self.sdk.diffscans.get("test-org", "diff-123", params={"cached": "true"})
163+
164+
self.assertEqual(
165+
result,
166+
{"status": "processing", "id": "diff-123", "retry_after": 5},
167+
)
168+
155169
def test_diffscans_create_from_ids_unit(self):
156170
"""Test diffscans creation from scan IDs."""
157171
expected_data = {"id": "new-diff-scan", "status": "queued"}

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)