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

Support MSC2033: Device ID on whoami #9918

Merged
merged 9 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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/9918.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for [MSC2033](https://github.com/matrix-org/matrix-doc/pull/2033): `device_id` on `/account/whoami`.
5 changes: 4 additions & 1 deletion synapse/rest/client/v2_alpha/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,10 @@ def __init__(self, hs):
async def on_GET(self, request):
requester = await self.auth.get_user_by_req(request)

return 200, {"user_id": requester.user.to_string()}
return 200, {
"user_id": requester.user.to_string(),
"device_id": requester.device_id,
turt2live marked this conversation as resolved.
Show resolved Hide resolved
}


def register_servlets(hs, http_server):
Expand Down
25 changes: 24 additions & 1 deletion tests/rest/client/v2_alpha/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def test_deactivate_account(self):
self.assertTrue(self.get_success(store.get_user_deactivated_status(user_id)))

# Check that this access token has been invalidated.
channel = self.make_request("GET", "account/whoami")
channel = self.make_request("GET", "account/whoami", access_token=tok)
self.assertEqual(channel.code, 401)

def test_pending_invites(self):
Expand Down Expand Up @@ -458,6 +458,29 @@ def deactivate(self, user_id, tok):
self.assertEqual(channel.code, 200)


class WhoamiTestCase(unittest.HomeserverTestCase):

servlets = [
synapse.rest.admin.register_servlets_for_client_rest_resource,
login.register_servlets,
account.register_servlets,
register.register_servlets,
]

def test_GET_whoami(self):
device_id = "wouldgohere"
user_id = self.register_user("kermit", "test")
tok = self.login("kermit", "test", device_id=device_id)

whoami = self.whoami(tok)
self.assertEqual(whoami, {"user_id": user_id, "device_id": device_id})
babolivier marked this conversation as resolved.
Show resolved Hide resolved

def whoami(self, tok):
channel = self.make_request("GET", "account/whoami", {}, access_token=tok)
self.assertEqual(channel.code, 200)
return channel.json_body


class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):

servlets = [
Expand Down