Fix dehydrated device REST checks (#14336)

This commit is contained in:
David Robertson 2022-10-31 20:31:43 +00:00 committed by GitHub
parent cc3a52b33d
commit dbfc9b803e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

1
changelog.d/14336.bugfix Normal file
View file

@ -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).

View file

@ -231,7 +231,7 @@ class DehydratedDeviceServlet(RestServlet):
} }
} }
PUT /org.matrix.msc2697/dehydrated_device PUT /org.matrix.msc2697.v2/dehydrated_device
Content-Type: application/json Content-Type: application/json
{ {
@ -271,7 +271,6 @@ class DehydratedDeviceServlet(RestServlet):
raise errors.NotFoundError("No dehydrated device available") raise errors.NotFoundError("No dehydrated device available")
class PutBody(RequestBodyModel): class PutBody(RequestBodyModel):
device_id: StrictStr
device_data: DehydratedDeviceDataModel device_data: DehydratedDeviceDataModel
initial_device_display_name: Optional[StrictStr] initial_device_display_name: Optional[StrictStr]
@ -281,7 +280,7 @@ class DehydratedDeviceServlet(RestServlet):
device_id = await self.device_handler.store_dehydrated_device( device_id = await self.device_handler.store_dehydrated_device(
requester.user.to_string(), requester.user.to_string(),
submission.device_data, submission.device_data.dict(),
submission.initial_device_display_name, submission.initial_device_display_name,
) )
return 200, {"device_id": device_id} return 200, {"device_id": device_id}

View file

@ -200,3 +200,37 @@ class DevicesTestCase(unittest.HomeserverTestCase):
self.reactor.advance(43200) self.reactor.advance(43200)
self.get_success(self.handler.get_device(user_id, "abc")) self.get_success(self.handler.get_device(user_id, "abc"))
self.get_failure(self.handler.get_device(user_id, "def"), NotFoundError) 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)