From 0ff8163eae50626dc7bc07eda7638f9f5fed5b6e Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 8 Mar 2019 11:26:33 +0000 Subject: Factor out soft fail checks --- synapse/handlers/federation.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'synapse') diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index a75abe8e91..9eaf2d3e18 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -1847,6 +1847,28 @@ class FederationHandler(BaseHandler): context.rejected = RejectedReason.AUTH_ERROR + if not context.rejected: + yield self._check_for_soft_fail(event, state, backfilled) + + if event.type == EventTypes.GuestAccess and not context.rejected: + yield self.maybe_kick_guest_users(event) + + defer.returnValue(context) + + @defer.inlineCallbacks + def _check_for_soft_fail(self, event, state, backfilled): + """Checks if we should soft fail the event, if so marks the event as + such. + + Args: + event (FrozenEvent) + state (dict|None): The state at the event if we don't have all the + event's prev events + backfilled (bool): Whether the event is from backfill + + Returns: + Deferred + """ # For new (non-backfilled and non-outlier) events we check if the event # passes auth based on the current state. If it doesn't then we # "soft-fail" the event. @@ -1918,11 +1940,6 @@ class FederationHandler(BaseHandler): ) event.internal_metadata.soft_failed = True - if event.type == EventTypes.GuestAccess and not context.rejected: - yield self.maybe_kick_guest_users(event) - - defer.returnValue(context) - @defer.inlineCallbacks def on_query_auth(self, origin, event_id, room_id, remote_auth_chain, rejects, missing): -- cgit 1.4.1