|
23 | 23 | ReadReceiptEventFields,
|
24 | 24 | RelationTypes,
|
25 | 25 | )
|
26 |
| -from synapse.rest.client import knock, login, read_marker, receipts, room, sync |
| 26 | +from synapse.rest.client import devices, knock, login, read_marker, receipts, room, sync |
27 | 27 |
|
28 | 28 | from tests import unittest
|
29 | 29 | from tests.federation.transport.test_knocking import (
|
@@ -710,3 +710,58 @@ def test_noop_sync_does_not_tightloop(self):
|
710 | 710 | channel.await_result(timeout_ms=9900)
|
711 | 711 | channel.await_result(timeout_ms=200)
|
712 | 712 | self.assertEqual(channel.code, 200, channel.json_body)
|
| 713 | + |
| 714 | + |
| 715 | +class DeviceListSyncTestCase(unittest.HomeserverTestCase): |
| 716 | + servlets = [ |
| 717 | + synapse.rest.admin.register_servlets, |
| 718 | + login.register_servlets, |
| 719 | + sync.register_servlets, |
| 720 | + devices.register_servlets, |
| 721 | + ] |
| 722 | + |
| 723 | + def test_user_with_no_rooms_receives_self_device_list_updates(self): |
| 724 | + """Tests that a user with no rooms still receives their own device list updates""" |
| 725 | + device_id = "TESTDEVICE" |
| 726 | + |
| 727 | + # Register a user and login, creating a device |
| 728 | + self.user_id = self.register_user("kermit", "monkey") |
| 729 | + self.tok = self.login("kermit", "monkey", device_id=device_id) |
| 730 | + |
| 731 | + # Request an initial sync |
| 732 | + channel = self.make_request("GET", "/sync", access_token=self.tok) |
| 733 | + self.assertEqual(channel.code, 200, channel.json_body) |
| 734 | + next_batch = channel.json_body["next_batch"] |
| 735 | + |
| 736 | + # Now, make an incremental sync request. |
| 737 | + # It won't return until something has happened |
| 738 | + incremental_sync_channel = self.make_request( |
| 739 | + "GET", |
| 740 | + f"/sync?since={next_batch}&timeout=30000", |
| 741 | + access_token=self.tok, |
| 742 | + await_result=False, |
| 743 | + ) |
| 744 | + |
| 745 | + # Change our device's display name |
| 746 | + channel = self.make_request( |
| 747 | + "PUT", |
| 748 | + f"devices/{device_id}", |
| 749 | + { |
| 750 | + "display_name": "freeze ray", |
| 751 | + }, |
| 752 | + access_token=self.tok, |
| 753 | + ) |
| 754 | + self.assertEqual(channel.code, 200, channel.json_body) |
| 755 | + |
| 756 | + # The sync should now have returned |
| 757 | + incremental_sync_channel.await_result(timeout_ms=20000) |
| 758 | + self.assertEqual(incremental_sync_channel.code, 200, channel.json_body) |
| 759 | + |
| 760 | + # We should have received notification that the (user's) device has changed |
| 761 | + device_list_changes = incremental_sync_channel.json_body.get( |
| 762 | + "device_lists", {} |
| 763 | + ).get("changed", []) |
| 764 | + |
| 765 | + self.assertIn( |
| 766 | + self.user_id, device_list_changes, incremental_sync_channel.json_body |
| 767 | + ) |
0 commit comments