Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit dbfc9b8

Browse files
author
David Robertson
authored
Fix dehydrated device REST checks (#14336)
1 parent cc3a52b commit dbfc9b8

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

changelog.d/14336.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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).

synapse/rest/client/devices.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class DehydratedDeviceServlet(RestServlet):
231231
}
232232
}
233233
234-
PUT /org.matrix.msc2697/dehydrated_device
234+
PUT /org.matrix.msc2697.v2/dehydrated_device
235235
Content-Type: application/json
236236
237237
{
@@ -271,7 +271,6 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
271271
raise errors.NotFoundError("No dehydrated device available")
272272

273273
class PutBody(RequestBodyModel):
274-
device_id: StrictStr
275274
device_data: DehydratedDeviceDataModel
276275
initial_device_display_name: Optional[StrictStr]
277276

@@ -281,7 +280,7 @@ async def on_PUT(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
281280

282281
device_id = await self.device_handler.store_dehydrated_device(
283282
requester.user.to_string(),
284-
submission.device_data,
283+
submission.device_data.dict(),
285284
submission.initial_device_display_name,
286285
)
287286
return 200, {"device_id": device_id}

tests/rest/client/test_devices.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,37 @@ def test_delete_stale_devices(self) -> None:
200200
self.reactor.advance(43200)
201201
self.get_success(self.handler.get_device(user_id, "abc"))
202202
self.get_failure(self.handler.get_device(user_id, "def"), NotFoundError)
203+
204+
205+
class DehydratedDeviceTestCase(unittest.HomeserverTestCase):
206+
servlets = [
207+
admin.register_servlets_for_client_rest_resource,
208+
login.register_servlets,
209+
register.register_servlets,
210+
devices.register_servlets,
211+
]
212+
213+
def test_PUT(self) -> None:
214+
"""Sanity-check that we can PUT a dehydrated device.
215+
216+
Detects https://github.com/matrix-org/synapse/issues/14334.
217+
"""
218+
alice = self.register_user("alice", "correcthorse")
219+
token = self.login(alice, "correcthorse")
220+
221+
# Have alice update their device list
222+
channel = self.make_request(
223+
"PUT",
224+
"_matrix/client/unstable/org.matrix.msc2697.v2/dehydrated_device",
225+
{
226+
"device_data": {
227+
"algorithm": "org.matrix.msc2697.v1.dehydration.v1.olm",
228+
"account": "dehydrated_device",
229+
}
230+
},
231+
access_token=token,
232+
shorthand=False,
233+
)
234+
self.assertEqual(channel.code, HTTPStatus.OK, channel.json_body)
235+
device_id = channel.json_body.get("device_id")
236+
self.assertIsInstance(device_id, str)

0 commit comments

Comments
 (0)