component AP gateway: parse body immediately on POST request:
the body is parsed immediately during a `POST` request: this avoids duplication of code, and allows to check the body data before continuing (will be used to filter some requests in a future patch).
This commit is contained in:
parent
d6f710bd0b
commit
4d14a623fc
1 changed files with 41 additions and 32 deletions
|
|
@ -629,7 +629,7 @@ class TestActivityPubGateway:
|
|||
ap_gateway,
|
||||
type_: Optional[str] = None,
|
||||
url: Optional[str] = None,
|
||||
doc: Optional[Any] = None,
|
||||
data: Optional[dict] = None,
|
||||
query_data: Optional[dict] = None,
|
||||
signing_actor: Optional[str] = None,
|
||||
) -> Dict[str, Any]:
|
||||
|
|
@ -637,8 +637,7 @@ class TestActivityPubGateway:
|
|||
|
||||
@param type_: one of the AP query type (e.g. "outbox")
|
||||
@param url: URL to query (mutually exclusif with type_)
|
||||
@param doc: if set, a document to embed in content of the request (will be
|
||||
converted to JSON)
|
||||
@param data: object used as body of the request
|
||||
@param query_data: query data as returned by parse.parse_qs
|
||||
@return dict with kw params to use
|
||||
"""
|
||||
|
|
@ -661,12 +660,11 @@ class TestActivityPubGateway:
|
|||
request = Request(MagicMock())
|
||||
request.path = path.encode()
|
||||
request.uri = uri.encode()
|
||||
if doc is not None:
|
||||
request.content = io.BytesIO(json.dumps(doc).encode())
|
||||
|
||||
ap_url = parse.urljoin(f"https://{ap_gateway.public_url}", path)
|
||||
kwargs = {
|
||||
"request": request,
|
||||
"data": data,
|
||||
"account_jid": test_jid,
|
||||
"node": None,
|
||||
"ap_account": test_jid.full(),
|
||||
|
|
@ -1510,7 +1508,7 @@ class TestActivityPubGateway:
|
|||
with patch.object(ap_gateway._p, "sendItems") as sendItems:
|
||||
await ap_gateway.server.resource.APInboxRequest(
|
||||
**self.ap_request_params(
|
||||
ap_gateway, "inbox", doc=like, signing_actor=TEST_AP_ACTOR_ID
|
||||
ap_gateway, "inbox", data=like, signing_actor=TEST_AP_ACTOR_ID
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -1614,7 +1612,7 @@ class TestActivityPubGateway:
|
|||
with patch.object(ap_gateway._p, "sendItems") as sendItems:
|
||||
await ap_gateway.server.resource.APInboxRequest(
|
||||
**self.ap_request_params(
|
||||
ap_gateway, "inbox", doc=like, signing_actor=TEST_AP_ACTOR_ID
|
||||
ap_gateway, "inbox", data=like, signing_actor=TEST_AP_ACTOR_ID
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue