Compare commits

...

3 Commits

Author SHA1 Message Date
Erik Johnston
e4d5c124d6 Add test 2024-05-07 09:38:15 +01:00
Erik Johnston
9b38d6826d Newsfile 2024-05-02 11:06:36 +01:00
Erik Johnston
578a87e2c0 Fix bug where push rules would be empty in /sync
Fixes #16987
2024-05-02 11:06:36 +01:00
3 changed files with 37 additions and 13 deletions

1
changelog.d/17142.bugfix Normal file
View File

@@ -0,0 +1 @@
Fix bug where push rules would be empty in `/sync` for some accounts. Introduced in v1.93.0.

View File

@@ -1945,23 +1945,19 @@ class SyncHandler:
) )
if push_rules_changed: if push_rules_changed:
global_account_data = { global_account_data = dict(global_account_data)
AccountDataTypes.PUSH_RULES: await self._push_rules_handler.push_rules_for_user( global_account_data[AccountDataTypes.PUSH_RULES] = (
sync_config.user await self._push_rules_handler.push_rules_for_user(sync_config.user)
), )
**global_account_data,
}
else: else:
all_global_account_data = await self.store.get_global_account_data_for_user( all_global_account_data = await self.store.get_global_account_data_for_user(
user_id user_id
) )
global_account_data = { global_account_data = dict(all_global_account_data)
AccountDataTypes.PUSH_RULES: await self._push_rules_handler.push_rules_for_user( global_account_data[AccountDataTypes.PUSH_RULES] = (
sync_config.user await self._push_rules_handler.push_rules_for_user(sync_config.user)
), )
**all_global_account_data,
}
account_data_for_user = ( account_data_for_user = (
await sync_config.filter_collection.filter_global_account_data( await sync_config.filter_collection.filter_global_account_data(

View File

@@ -24,7 +24,7 @@ from parameterized import parameterized
from twisted.test.proto_helpers import MemoryReactor from twisted.test.proto_helpers import MemoryReactor
from synapse.api.constants import EventTypes, JoinRules from synapse.api.constants import AccountDataTypes, EventTypes, JoinRules
from synapse.api.errors import Codes, ResourceLimitError from synapse.api.errors import Codes, ResourceLimitError
from synapse.api.filtering import FilterCollection, Filtering from synapse.api.filtering import FilterCollection, Filtering
from synapse.api.room_versions import RoomVersion, RoomVersions from synapse.api.room_versions import RoomVersion, RoomVersions
@@ -846,6 +846,33 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
self.assertIn(private_call_event.event_id, priv_event_ids) self.assertIn(private_call_event.event_id, priv_event_ids)
def test_push_rules_with_bad_account_data(self) -> None:
"""Some old accounts have managed to set a `m.push_rules` account data,
which we should ignore in /sync response.
"""
user = self.register_user("alice", "password")
# Insert the bad account data.
self.get_success(
self.store.add_account_data_for_user(user, AccountDataTypes.PUSH_RULES, {})
)
sync_result: SyncResult = self.get_success(
self.sync_handler.wait_for_sync_for_user(
create_requester(user), generate_sync_config(user)
)
)
for account_dict in sync_result.account_data:
if account_dict["type"] == AccountDataTypes.PUSH_RULES:
# We should have lots of push rules here, rather than the bad
# empty data.
self.assertNotEqual(account_dict["content"], {})
return
self.fail("No push rules found")
_request_key = 0 _request_key = 0