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

Implement MSC3069: Guest support on whoami #9655

Merged
merged 13 commits into from
Sep 29, 2021
42 changes: 41 additions & 1 deletion tests/rest/client/v2_alpha/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,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)
turt2live marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(channel.code, 401)

def test_pending_invites(self):
Expand Down Expand Up @@ -459,6 +459,46 @@ 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,
room.register_servlets,
turt2live marked this conversation as resolved.
Show resolved Hide resolved
turt2live marked this conversation as resolved.
Show resolved Hide resolved
]

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

whoami = self.whoami(tok)
self.assertObjectHasAttributes({"user_id": user_id}, whoami)

@override_config({"allow_guest_access": True})
def test_GET_whoami_guests(self):
channel = self.make_request(
b"POST", b"/_matrix/client/r0/register?kind=guest", b"{}"
)
tok = channel.json_body["access_token"]
user_id = channel.json_body["user_id"]

whoami = self.whoami(tok)
self.assertObjectHasAttributes(
{
"user_id": user_id,
# Unstable until MSC3069 enters spec
"org.matrix.msc3069.is_guest": True,
},
whoami,
)
turt2live marked this conversation as resolved.
Show resolved Hide resolved

def whoami(self, tok):
turt2live marked this conversation as resolved.
Show resolved Hide resolved
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