summary refs log tree commit diff
path: root/tests/handlers/test_sync.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@element.io>2024-11-08 16:41:24 +0000
committerGitHub <noreply@github.com>2024-11-08 16:41:24 +0000
commitcacd4fd7bd40465732fc302a69efa39dcb5eb118 (patch)
treea861da1d3b24a4dc7d57c028a6b7cf7a8c41e36a /tests/handlers/test_sync.py
parentFix Twisted tests with latest release (#17911) (diff)
downloadsynapse-cacd4fd7bd40465732fc302a69efa39dcb5eb118.tar.xz
Fix MSC4222 returning full state (#17915)
There was a bug that meant we would return the full state of the room on
incremental syncs when using lazy loaded members and there were no
entries in the timeline.

This was due to trying to use `state_filter or state_filter.all()` as a
short hand for handling `None` case, however `state_filter` implements
`__bool__` so if the state filter was empty it would be set to full.

c.f. MSC4222 and #17888
Diffstat (limited to 'tests/handlers/test_sync.py')
-rw-r--r--tests/handlers/test_sync.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/handlers/test_sync.py b/tests/handlers/test_sync.py

index 1960d2f0e1..9dd0e98971 100644 --- a/tests/handlers/test_sync.py +++ b/tests/handlers/test_sync.py
@@ -1262,3 +1262,35 @@ class SyncStateAfterTestCase(tests.unittest.HomeserverTestCase): ) ) self.assertEqual(state[("m.test_event", "")], second_state["event_id"]) + + def test_incremental_sync_lazy_loaded_no_timeline(self) -> None: + """Test that lazy-loading with an empty timeline doesn't return the full + state. + + There was a bug where an empty state filter would cause the DB to return + the full state, rather than an empty set. + """ + user = self.register_user("user", "password") + tok = self.login("user", "password") + + # Create a room as the user and set some custom state. + joined_room = self.helper.create_room_as(user, tok=tok) + + since_token = self.hs.get_event_sources().get_current_token() + end_stream_token = self.hs.get_event_sources().get_current_token() + + state = self.get_success( + self.sync_handler._compute_state_delta_for_incremental_sync( + room_id=joined_room, + sync_config=generate_sync_config(user, use_state_after=True), + batch=TimelineBatch( + prev_batch=end_stream_token, events=[], limited=True + ), + since_token=since_token, + end_token=end_stream_token, + members_to_fetch=set(), + timeline_state={}, + ) + ) + + self.assertEqual(state, {})