summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-03-08 11:26:33 +0000
committerErik Johnston <erik@matrix.org>2019-03-08 11:26:33 +0000
commit0ff8163eae50626dc7bc07eda7638f9f5fed5b6e (patch)
tree0010d42ac188e28c2f1d442fb814f2f4cbf7fb60
parentNewsfile (diff)
downloadsynapse-0ff8163eae50626dc7bc07eda7638f9f5fed5b6e.tar.xz
Factor out soft fail checks
-rw-r--r--synapse/handlers/federation.py27
1 files changed, 22 insertions, 5 deletions
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):