Support MSC3283: Expose `enable_set_displayname` in capabilities (#10452)

pull/10662/head
Dirk Klimpel 2021-08-19 11:40:40 +02:00 committed by GitHub
parent 220f901229
commit b5fef6054a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 23 deletions

View File

@ -0,0 +1 @@
Add support for [MSC3283](https://github.com/matrix-org/matrix-doc/pull/3283): Expose enable_set_displayname in capabilities.

View File

@ -39,5 +39,8 @@ class ExperimentalConfig(Config):
# MSC3244 (room version capabilities)
self.msc3244_enabled: bool = experimental.get("msc3244_enabled", False)
# MSC3283 (set displayname, avatar_url and change 3pid capabilities)
self.msc3283_enabled: bool = experimental.get("msc3283_enabled", False)
# MSC3266 (room summary api)
self.msc3266_enabled: bool = experimental.get("msc3266_enabled", False)

View File

@ -61,6 +61,17 @@ class CapabilitiesRestServlet(RestServlet):
"org.matrix.msc3244.room_capabilities"
] = MSC3244_CAPABILITIES
if self.config.experimental.msc3283_enabled:
response["capabilities"]["org.matrix.msc3283.set_displayname"] = {
"enabled": self.config.enable_set_displayname
}
response["capabilities"]["org.matrix.msc3283.set_avatar_url"] = {
"enabled": self.config.enable_set_avatar_url
}
response["capabilities"]["org.matrix.msc3283.3pid_changes"] = {
"enabled": self.config.enable_3pid_changes
}
return 200, response

View File

@ -30,19 +30,22 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
def make_homeserver(self, reactor, clock):
self.url = b"/_matrix/client/r0/capabilities"
hs = self.setup_test_homeserver()
self.store = hs.get_datastore()
self.config = hs.config
self.auth_handler = hs.get_auth_handler()
return hs
def prepare(self, reactor, clock, hs):
self.localpart = "user"
self.password = "pass"
self.user = self.register_user(self.localpart, self.password)
def test_check_auth_required(self):
channel = self.make_request("GET", self.url)
self.assertEqual(channel.code, 401)
def test_get_room_version_capabilities(self):
self.register_user("user", "pass")
access_token = self.login("user", "pass")
access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
@ -57,10 +60,7 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
)
def test_get_change_password_capabilities_password_login(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.login(user, password)
access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
@ -70,12 +70,9 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
@override_config({"password_config": {"localdb_enabled": False}})
def test_get_change_password_capabilities_localdb_disabled(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
user, device_id=None, valid_until_ms=None
self.user, device_id=None, valid_until_ms=None
)
)
@ -87,12 +84,9 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
@override_config({"password_config": {"enabled": False}})
def test_get_change_password_capabilities_password_disabled(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
user, device_id=None, valid_until_ms=None
self.user, device_id=None, valid_until_ms=None
)
)
@ -102,13 +96,85 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["m.change_password"]["enabled"])
def test_get_change_users_attributes_capabilities_when_msc3283_disabled(self):
"""Test that per default msc3283 is disabled server returns `m.change_password`."""
access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200)
self.assertTrue(capabilities["m.change_password"]["enabled"])
self.assertNotIn("org.matrix.msc3283.set_displayname", capabilities)
self.assertNotIn("org.matrix.msc3283.set_avatar_url", capabilities)
self.assertNotIn("org.matrix.msc3283.3pid_changes", capabilities)
@override_config({"experimental_features": {"msc3283_enabled": True}})
def test_get_change_users_attributes_capabilities_when_msc3283_enabled(self):
"""Test if msc3283 is enabled server returns capabilities."""
access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200)
self.assertTrue(capabilities["m.change_password"]["enabled"])
self.assertTrue(capabilities["org.matrix.msc3283.set_displayname"]["enabled"])
self.assertTrue(capabilities["org.matrix.msc3283.set_avatar_url"]["enabled"])
self.assertTrue(capabilities["org.matrix.msc3283.3pid_changes"]["enabled"])
@override_config(
{
"enable_set_displayname": False,
"experimental_features": {"msc3283_enabled": True},
}
)
def test_get_set_displayname_capabilities_displayname_disabled(self):
"""Test if set displayname is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["org.matrix.msc3283.set_displayname"]["enabled"])
@override_config(
{
"enable_set_avatar_url": False,
"experimental_features": {"msc3283_enabled": True},
}
)
def test_get_set_avatar_url_capabilities_avatar_url_disabled(self):
"""Test if set avatar_url is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["org.matrix.msc3283.set_avatar_url"]["enabled"])
@override_config(
{
"enable_3pid_changes": False,
"experimental_features": {"msc3283_enabled": True},
}
)
def test_change_3pid_capabilities_3pid_disabled(self):
"""Test if change 3pid is disabled that the server responds it."""
access_token = self.login(self.localpart, self.password)
channel = self.make_request("GET", self.url, access_token=access_token)
capabilities = channel.json_body["capabilities"]
self.assertEqual(channel.code, 200)
self.assertFalse(capabilities["org.matrix.msc3283.3pid_changes"]["enabled"])
def test_get_does_not_include_msc3244_fields_by_default(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
user, device_id=None, valid_until_ms=None
self.user, device_id=None, valid_until_ms=None
)
)
@ -122,12 +188,9 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
@override_config({"experimental_features": {"msc3244_enabled": True}})
def test_get_does_include_msc3244_fields_when_enabled(self):
localpart = "user"
password = "pass"
user = self.register_user(localpart, password)
access_token = self.get_success(
self.auth_handler.get_access_token_for_user_id(
user, device_id=None, valid_until_ms=None
self.user, device_id=None, valid_until_ms=None
)
)