0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-16 06:51:46 +01:00

Run lint fix

This commit is contained in:
Tulir Asokan 2020-08-13 13:49:47 +03:00
parent ce02e755c1
commit a77a254b31
3 changed files with 40 additions and 17 deletions

View file

@ -50,11 +50,11 @@ from synapse.api.errors import (
)
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion, RoomVersions
from synapse.crypto.event_signing import compute_event_signature
from synapse.federation.federation_base import FederationBase, event_from_pdu_json
from synapse.event_auth import auth_types_for_event
from synapse.events import EventBase
from synapse.events.snapshot import EventContext
from synapse.events.validator import EventValidator
from synapse.federation.federation_base import FederationBase, event_from_pdu_json
from synapse.handlers._base import BaseHandler
from synapse.logging.context import (
make_deferred_yieldable,
@ -680,7 +680,9 @@ class FederationHandler(BaseHandler, FederationBase):
_forwarded_key = "net.maunium.msc2730.forwarded"
async def _validate_forwarded_event(self, event: EventBase) -> Tuple[bool, Optional[str]]:
async def _validate_forwarded_event(
self, event: EventBase
) -> Tuple[bool, Optional[str]]:
try:
source_evt_dict = {**event.content[self._forwarded_key]}
room_version_identifier = source_evt_dict["unsigned"]["room_version"]
@ -734,7 +736,11 @@ class FederationHandler(BaseHandler, FederationBase):
logger.debug("[%s %s] Processing event: %s", room_id, event_id, event)
if not event.is_state() and not event.redacts and self._forwarded_key in event.content:
if (
not event.is_state()
and not event.redacts
and self._forwarded_key in event.content
):
valid, event_id = await self._validate_forwarded_event(event)
event.unsigned[self._forwarded_key] = {
"valid": valid,

View file

@ -37,6 +37,7 @@ from synapse.rest.client.v2_alpha import (
capabilities,
devices,
filter,
forward_event,
groups,
keys,
notifications,
@ -47,7 +48,6 @@ from synapse.rest.client.v2_alpha import (
register,
relations,
report_event,
forward_event,
room_keys,
room_upgrade_rest_servlet,
sendtodevice,

View file

@ -16,7 +16,7 @@
import logging
from synapse.api.errors import Codes, SynapseError, AuthError
from synapse.api.errors import AuthError, Codes, SynapseError
from synapse.http.servlet import RestServlet, parse_integer
from synapse.logging.opentracing import set_tag
@ -31,8 +31,10 @@ class RoomEventForwardServlet(RestServlet):
"""
PATTERNS = client_patterns(
("/net.maunium.msc2730/rooms/(?P<room_id>[^/]*)/event/(?P<event_id>[^/]*)"
"/forward/(?P<target_room_id>[^/]*)/(?P<txn_id>.*)"),
(
"/net.maunium.msc2730/rooms/(?P<room_id>[^/]*)/event/(?P<event_id>[^/]*)"
"/forward/(?P<target_room_id>[^/]*)/(?P<txn_id>.*)"
),
releases=(), # This is an unstable feature
)
@ -59,14 +61,23 @@ class RoomEventForwardServlet(RestServlet):
raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND)
if event.is_state():
raise SynapseError(401, "State events cannot be forwarded.",
errcode=self._err_not_forwardable)
raise SynapseError(
401,
"State events cannot be forwarded.",
errcode=self._err_not_forwardable,
)
elif event.redacts:
raise SynapseError(401, "Redaction events cannot be forwarded.",
errcode=self._err_not_forwardable)
raise SynapseError(
401,
"Redaction events cannot be forwarded.",
errcode=self._err_not_forwardable,
)
elif event.internal_metadata.is_redacted():
raise SynapseError(401, "Redacted events cannot be forwarded.",
errcode=self._err_not_forwardable)
raise SynapseError(
401,
"Redacted events cannot be forwarded.",
errcode=self._err_not_forwardable,
)
event_id = event.event_id
event_dict = event.get_dict()
@ -81,8 +92,11 @@ class RoomEventForwardServlet(RestServlet):
is_valid_forward = False
if has_forward_meta and not is_valid_forward:
raise SynapseError(401, "Event contains invalid forward metadata.",
errcode=self._err_not_forwardable)
raise SynapseError(
401,
"Event contains invalid forward metadata.",
errcode=self._err_not_forwardable,
)
elif not has_forward_meta:
content[self._data_key] = event_dict
room_version = await self.store.get_room_version(event.room_id)
@ -101,13 +115,16 @@ class RoomEventForwardServlet(RestServlet):
"valid": True,
"event_id": event_id,
}
}
},
}
if b"ts" in request.args and requester.app_service:
forwarded_event_dict["origin_server_ts"] = parse_integer(request, "ts", 0)
forwarded_event, _ = await self.event_creation_handler.create_and_send_nonmember_event(
(
forwarded_event,
_,
) = await self.event_creation_handler.create_and_send_nonmember_event(
requester, forwarded_event_dict, txn_id=txn_id
)