From 3b19434c159670fb2d32babdd6cd9d366813b142 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Mon, 31 Oct 2022 13:00:05 +0000 Subject: [PATCH 1/3] test case --- synapse/rest/client/devices.py | 2 +- tests/rest/client/test_devices.py | 34 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/synapse/rest/client/devices.py b/synapse/rest/client/devices.py index 90828c95c462..a5aca4bd01aa 100644 --- a/synapse/rest/client/devices.py +++ b/synapse/rest/client/devices.py @@ -231,7 +231,7 @@ class DehydratedDeviceServlet(RestServlet): } } - PUT /org.matrix.msc2697/dehydrated_device + PUT /org.matrix.msc2697.v2/dehydrated_device Content-Type: application/json { diff --git a/tests/rest/client/test_devices.py b/tests/rest/client/test_devices.py index aa98222434ab..d80eea17d3af 100644 --- a/tests/rest/client/test_devices.py +++ b/tests/rest/client/test_devices.py @@ -200,3 +200,37 @@ def test_delete_stale_devices(self) -> None: self.reactor.advance(43200) self.get_success(self.handler.get_device(user_id, "abc")) self.get_failure(self.handler.get_device(user_id, "def"), NotFoundError) + + +class DehydratedDeviceTestCase(unittest.HomeserverTestCase): + servlets = [ + admin.register_servlets_for_client_rest_resource, + login.register_servlets, + register.register_servlets, + devices.register_servlets, + ] + + def test_PUT(self) -> None: + """Sanity-check that we can PUT a dehydrated device. + + Detects https://github.com/matrix-org/synapse/issues/14334. + """ + alice = self.register_user("alice", "correcthorse") + token = self.login(alice, "correcthorse") + + # Have alice update their device list + channel = self.make_request( + "PUT", + "_matrix/client/unstable/org.matrix.msc2697.v2/dehydrated_device", + { + "device_data": { + "algorithm": "org.matrix.msc2697.v1.dehydration.v1.olm", + "account": "dehydrated_device", + } + }, + access_token=token, + shorthand=False, + ) + self.assertEqual(channel.code, HTTPStatus.OK, channel.json_body) + device_id = channel.json_body.get("device_id") + self.assertIsInstance(device_id, str) From ae440b423c44900f378e3780f2a1563865b170c6 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Mon, 31 Oct 2022 13:06:01 +0000 Subject: [PATCH 2/3] Fix regression --- synapse/rest/client/devices.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/synapse/rest/client/devices.py b/synapse/rest/client/devices.py index a5aca4bd01aa..8f3cbd4ea2e7 100644 --- a/synapse/rest/client/devices.py +++ b/synapse/rest/client/devices.py @@ -271,7 +271,6 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: raise errors.NotFoundError("No dehydrated device available") class PutBody(RequestBodyModel): - device_id: StrictStr device_data: DehydratedDeviceDataModel initial_device_display_name: Optional[StrictStr] @@ -281,7 +280,7 @@ async def on_PUT(self, request: SynapseRequest) -> Tuple[int, JsonDict]: device_id = await self.device_handler.store_dehydrated_device( requester.user.to_string(), - submission.device_data, + submission.device_data.dict(), submission.initial_device_display_name, ) return 200, {"device_id": device_id} From 14e3cd63c60bdc04d5c610d5f2dfc0033b336b8c Mon Sep 17 00:00:00 2001 From: David Robertson Date: Mon, 31 Oct 2022 13:18:40 +0000 Subject: [PATCH 3/3] Changelog --- changelog.d/14336.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14336.bugfix diff --git a/changelog.d/14336.bugfix b/changelog.d/14336.bugfix new file mode 100644 index 000000000000..d44ff1bbc7f1 --- /dev/null +++ b/changelog.d/14336.bugfix @@ -0,0 +1 @@ +Fix a bug introduced in Synapse 1.70 where clients were unable to PUT new [dehydrated devices](https://github.com/matrix-org/matrix-spec-proposals/pull/2697).