-
Notifications
You must be signed in to change notification settings - Fork 404
Mark dehydrated devices in admin get devices endpoint #18252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b6b879a
9deca6d
e23297e
7f2f56f
8d6712b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Mark dehydrated devices in the admin get devices endpoint. | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,6 +142,17 @@ async def on_GET( | |||||||||
| raise NotFoundError("Unknown user") | ||||||||||
|
|
||||||||||
| devices = await self.device_handler.get_devices_by_user(target_user.to_string()) | ||||||||||
|
|
||||||||||
| # mark the dehydrated device by adding a "dehydrated" flag | ||||||||||
| dehydrated_device_info = await self.device_handler.get_dehydrated_device( | ||||||||||
| target_user.to_string() | ||||||||||
| ) | ||||||||||
| if dehydrated_device_info: | ||||||||||
| dehydrated_device_id = dehydrated_device_info[0] | ||||||||||
| for device in devices: | ||||||||||
| if device["device_id"] == dehydrated_device_id: | ||||||||||
| device["dehydrated"] = True | ||||||||||
|
||||||||||
| if device["device_id"] == dehydrated_device_id: | |
| device["dehydrated"] = True | |
| is_dehydrated = device["device_id"] == dehydrated_device_id | |
| device["dehydrated"] = is_dehydrated |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,7 +27,7 @@ | |||||||
| import synapse.rest.admin | ||||||||
| from synapse.api.errors import Codes | ||||||||
| from synapse.handlers.device import DeviceHandler | ||||||||
| from synapse.rest.client import login | ||||||||
| from synapse.rest.client import devices, login | ||||||||
| from synapse.server import HomeServer | ||||||||
| from synapse.util import Clock | ||||||||
|
|
||||||||
|
|
@@ -299,6 +299,7 @@ def test_delete_device(self) -> None: | |||||||
| class DevicesRestTestCase(unittest.HomeserverTestCase): | ||||||||
| servlets = [ | ||||||||
| synapse.rest.admin.register_servlets, | ||||||||
| devices.register_servlets, | ||||||||
| login.register_servlets, | ||||||||
| ] | ||||||||
|
|
||||||||
|
|
@@ -390,15 +391,63 @@ def test_user_has_no_devices(self) -> None: | |||||||
| self.assertEqual(0, channel.json_body["total"]) | ||||||||
| self.assertEqual(0, len(channel.json_body["devices"])) | ||||||||
|
|
||||||||
| @unittest.override_config( | ||||||||
| {"experimental_features": {"msc2697_enabled": False, "msc3814_enabled": True}} | ||||||||
| ) | ||||||||
| def test_get_devices(self) -> None: | ||||||||
| """ | ||||||||
| Tests that a normal lookup for devices is successfully | ||||||||
| """ | ||||||||
| # Create devices | ||||||||
| number_devices = 5 | ||||||||
| for _ in range(number_devices): | ||||||||
| # we create 2 fewer devices in the loop, because we will create another | ||||||||
| # login after the loop, and we will create a dehydrated device | ||||||||
| for _ in range(number_devices - 2): | ||||||||
| self.login("user", "pass") | ||||||||
|
|
||||||||
| other_user_token = self.login("user", "pass") | ||||||||
| dehydrated_device_url = ( | ||||||||
| "/_matrix/client/unstable/org.matrix.msc3814.v1/dehydrated_device" | ||||||||
| ) | ||||||||
| content = { | ||||||||
| "device_data": { | ||||||||
| "algorithm": "m.dehydration.v1.olm", | ||||||||
| }, | ||||||||
| "device_id": "dehydrated_device", | ||||||||
| "initial_device_display_name": "foo bar", | ||||||||
| "device_keys": { | ||||||||
| "user_id": "@user:test", | ||||||||
| "device_id": "dehydrated_device", | ||||||||
| "valid_until_ts": "80", | ||||||||
| "algorithms": [ | ||||||||
| "m.olm.curve25519-aes-sha2", | ||||||||
| ], | ||||||||
| "keys": { | ||||||||
| "<algorithm>:<device_id>": "<key_base64>", | ||||||||
| }, | ||||||||
| "signatures": { | ||||||||
| "@user:test": {"<algorithm>:<device_id>": "<signature_base64>"} | ||||||||
| }, | ||||||||
| }, | ||||||||
| "fallback_keys": { | ||||||||
| "alg1:device1": "f4llb4ckk3y", | ||||||||
| "signed_<algorithm>:<device_id>": { | ||||||||
| "fallback": "true", | ||||||||
| "key": "f4llb4ckk3y", | ||||||||
| "signatures": { | ||||||||
| "@user:test": {"<algorithm>:<device_id>": "<key_base64>"} | ||||||||
| }, | ||||||||
| }, | ||||||||
| }, | ||||||||
| "one_time_keys": {"alg1:k1": "0net1m3k3y"}, | ||||||||
| } | ||||||||
| self.make_request( | ||||||||
| "PUT", | ||||||||
| dehydrated_device_url, | ||||||||
| access_token=other_user_token, | ||||||||
| content=content, | ||||||||
| ) | ||||||||
|
|
||||||||
| # Get devices | ||||||||
| channel = self.make_request( | ||||||||
| "GET", | ||||||||
|
|
@@ -410,13 +459,21 @@ def test_get_devices(self) -> None: | |||||||
| self.assertEqual(number_devices, channel.json_body["total"]) | ||||||||
| self.assertEqual(number_devices, len(channel.json_body["devices"])) | ||||||||
| self.assertEqual(self.other_user, channel.json_body["devices"][0]["user_id"]) | ||||||||
| # Check that all fields are available | ||||||||
| # Check that all fields are available, and that the dehydrated device is marked as dehydrated | ||||||||
| found_dehydrated = False | ||||||||
| for d in channel.json_body["devices"]: | ||||||||
| self.assertIn("user_id", d) | ||||||||
| self.assertIn("device_id", d) | ||||||||
| self.assertIn("display_name", d) | ||||||||
| self.assertIn("last_seen_ip", d) | ||||||||
| self.assertIn("last_seen_ts", d) | ||||||||
| if d["device_id"] == "dehydrated_device": | ||||||||
| self.assertEqual(True, d.get("dehydrated")) | ||||||||
|
||||||||
| self.assertEqual(True, d.get("dehydrated")) | |
| self.assertTrue(d.get("dehydrated")) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To align with the suggestion above.
| self.assertNotIn("dehydrated", d) | |
| # Either the field is not present, or set to False | |
| self.assertFalse(d["dehydrated]) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self.assertEqual(True, found_dehydrated) | |
| self.assertTrue(found_dehydrated) |
Uh oh!
There was an error while loading. Please reload this page.