fix: enforce VIP content boundary and PATCH updates

This commit is contained in:
AHMED
2026-10-09 16:27:49 +03:00
parent 61aea8d83e
commit 87e653cc96
9 changed files with 103 additions and 8 deletions
+2 -2
View File
@@ -126,7 +126,7 @@ class AgentApi:
except HTTPError as error:
return error.code, error.read(), error.headers.get("content-type", "")
except (TimeoutError, URLError) as error:
if method in ("POST", "PUT"):
if method in ("POST", "PATCH"):
raise AmbiguousWrite(f"agent API {method} outcome is unknown") from error
raise
@@ -176,7 +176,7 @@ class AgentApi:
probe = self._probe(body)
if probe:
self.body_probes[slug] = probe
status, raw, _ = self._request("PUT", f"/api/agent/posts/{quote(slug)}", body)
status, raw, _ = self._request("PATCH", f"/api/agent/posts/{quote(slug)}", body)
if status != 200:
raise RuntimeError(f"agent API update failed ({status})")
return self._decode(status, raw)
+1 -1
View File
@@ -193,7 +193,7 @@ class PublisherTests(unittest.TestCase):
self.assertEqual(api.create_calls, [])
self.assertEqual(len(api.update_calls), 1)
def test_republish_puts_existing_slug_and_never_posts(self):
def test_republish_updates_existing_slug_and_never_posts(self):
record = {
"id": 7, "title": "Old", "slug": "existing-guide", "status": "published",
"access": "vip", "category": "أدوات", "publishedAt": "2026-10-09T09:00:00Z",
+8
View File
@@ -42,10 +42,12 @@ class FakeAgentApi(AgentApi):
def __init__(self):
super().__init__("test-key")
self.responses = []
self.requests = []
self.public = (200, b"page")
self.rsc = (200, b"rsc")
def _request(self, method, path, body=None, *, anonymous=False):
self.requests.append((method, path, body, anonymous))
if self.responses:
return self.responses.pop(0)
return 200, b"{}", "application/json"
@@ -80,6 +82,12 @@ class RuntimeTests(unittest.TestCase):
self.assertEqual(api.create(body)["slug"], "guide")
self.assertEqual(api.body_probes["guide"], "distinctive protected body sentence")
def test_agent_api_updates_with_patch(self):
api = FakeAgentApi()
api.responses = [(200, json.dumps({"slug": "guide"}).encode(), "application/json")]
self.assertEqual(api.update("guide", {"publish": True})["slug"], "guide")
self.assertEqual(api.requests[0][0:2], ("PATCH", "/api/agent/posts/guide"))
@patch("runtime.time.sleep", return_value=None)
def test_vip_verification_rejects_body_leak(self, _sleep):
api = FakeAgentApi()