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

Commit

Permalink
Support MSC2033: Device ID on whoami
Browse files Browse the repository at this point in the history
MSC: matrix-org/matrix-spec-proposals#2033

The MSC has passed FCP, which means stable endpoints can be used.
  • Loading branch information
turt2live committed May 1, 2021
1 parent 6fc9dc0 commit c29d99b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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,
}


def register_servlets(hs, http_server):
Expand Down
23 changes: 23 additions & 0 deletions tests/rest/client/v2_alpha/test_account.py
Original file line number Diff line number Diff line change
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.assertObjectHasAttributes({"user_id": user_id, "device_id": device_id}, whoami)

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

0 comments on commit c29d99b

Please sign in to comment.