Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Stop returning EventContext from _check_event_auth
Browse files Browse the repository at this point in the history
We now always return the same object that was passed in, so this is redundant.
  • Loading branch information
richvdh committed Jun 30, 2022
1 parent 41df503 commit 4c9ace3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 deletions.
28 changes: 8 additions & 20 deletions synapse/handlers/federation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ async def on_send_membership_event(
event.internal_metadata.send_on_behalf_of = origin

context = await self._state_handler.compute_event_context(event)
context = await self._check_event_auth(origin, event, context)
await self._check_event_auth(origin, event, context)
if context.rejected:
raise SynapseError(
403, f"{event.membership} event was rejected", Codes.FORBIDDEN
Expand Down Expand Up @@ -471,7 +471,7 @@ async def process_remote_join(
partial_state=partial_state,
)

context = await self._check_event_auth(origin, event, context)
await self._check_event_auth(origin, event, context)
if context.rejected:
raise SynapseError(400, "Join event was rejected")

Expand Down Expand Up @@ -1098,11 +1098,7 @@ async def _process_received_pdu(
event,
state_ids_before_event=state_ids,
)
context = await self._check_event_auth(
origin,
event,
context,
)
await self._check_event_auth(origin, event, context)
except AuthError as e:
# FIXME richvdh 2021/10/07 I don't think this is reachable. Let's log it
# for now
Expand Down Expand Up @@ -1478,11 +1474,8 @@ async def prep(event: EventBase) -> None:
)

async def _check_event_auth(
self,
origin: str,
event: EventBase,
context: EventContext,
) -> EventContext:
self, origin: str, event: EventBase, context: EventContext
) -> None:
"""
Checks whether an event should be rejected (for failing auth checks).
Expand All @@ -1492,9 +1485,6 @@ async def _check_event_auth(
context:
The event context.
Returns:
The updated context object.
Raises:
AuthError if we were unable to find copies of the event's auth events.
(Most other failures just cause us to set `context.rejected`.)
Expand All @@ -1509,7 +1499,7 @@ async def _check_event_auth(
logger.warning("While validating received event %r: %s", event, e)
# TODO: use a different rejected reason here?
context.rejected = RejectedReason.AUTH_ERROR
return context
return

# next, check that we have all of the event's auth events.
#
Expand All @@ -1532,7 +1522,7 @@ async def _check_event_auth(
"While checking auth of %r against auth_events: %s", event, e
)
context.rejected = RejectedReason.AUTH_ERROR
return context
return

# now check the auth rules pass against the room state before the event
# https://spec.matrix.org/v1.3/server-server-api/#checks-performed-on-receipt-of-a-pdu:
Expand All @@ -1551,7 +1541,7 @@ async def _check_event_auth(
if collections.Counter(event.auth_event_ids()) == collections.Counter(
calculated_auth_event_ids
):
return context
return

# otherwise, re-run the auth checks based on what we calculated.
calculated_auth_events = await self._store.get_events_as_list(
Expand Down Expand Up @@ -1591,8 +1581,6 @@ async def _check_event_auth(
)
context.rejected = RejectedReason.AUTH_ERROR

return context

async def _maybe_kick_guest_users(self, event: EventBase) -> None:
if event.type != EventTypes.GuestAccess:
return
Expand Down
11 changes: 2 additions & 9 deletions tests/rest/client/test_third_party_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from synapse.api.errors import SynapseError
from synapse.api.room_versions import RoomVersion
from synapse.events import EventBase
from synapse.events.snapshot import EventContext
from synapse.events.third_party_rules import load_legacy_third_party_event_rules
from synapse.rest import admin
from synapse.rest.client import account, login, profile, room
Expand Down Expand Up @@ -113,14 +112,8 @@ async def approve_all_signature_checking(

# Have this homeserver skip event auth checks. This is necessary due to
# event auth checks ensuring that events were signed by the sender's homeserver.
async def _check_event_auth(
origin: str,
event: EventBase,
context: EventContext,
*args: Any,
**kwargs: Any,
) -> EventContext:
return context
async def _check_event_auth(origin: Any, event: Any, context: Any) -> None:
pass

hs.get_federation_event_handler()._check_event_auth = _check_event_auth # type: ignore[assignment]

Expand Down
8 changes: 2 additions & 6 deletions tests/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,8 @@ def setUp(self):
self.handler = self.homeserver.get_federation_handler()
federation_event_handler = self.homeserver.get_federation_event_handler()

async def _check_event_auth(
origin,
event,
context,
):
return context
async def _check_event_auth(origin, event, context):
pass

federation_event_handler._check_event_auth = _check_event_auth
self.client = self.homeserver.get_federation_client()
Expand Down

0 comments on commit 4c9ace3

Please sign in to comment.