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

Fix dehydrated device REST checks #14336

Merged
merged 3 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14336.bugfix
Original file line number Diff line number Diff line change
@@ -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).
5 changes: 2 additions & 3 deletions synapse/rest/client/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class DehydratedDeviceServlet(RestServlet):
}
}

PUT /org.matrix.msc2697/dehydrated_device
PUT /org.matrix.msc2697.v2/dehydrated_device
Content-Type: application/json

{
Expand Down Expand Up @@ -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]

Expand All @@ -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(),
Comment on lines -284 to +283
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy didn't spot this because self.device_handler: Any, grr.

submission.initial_device_display_name,
)
return 200, {"device_id": device_id}
Expand Down
34 changes: 34 additions & 0 deletions tests/rest/client/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)