Also expose unstable capability

hughns/msc3882-unstable-r1
Hugh Nimmo-Smith 2023-09-22 18:01:59 +01:00
parent cf3b20a2f1
commit 151b237768
5 changed files with 21 additions and 7 deletions

View File

@ -68,6 +68,9 @@ class CapabilitiesRestServlet(RestServlet):
"m.get_login_token": { "m.get_login_token": {
"enabled": self.config.auth.login_via_existing_enabled, "enabled": self.config.auth.login_via_existing_enabled,
}, },
"org.matrix.msc3882.get_login_token": {
"enabled": self.config.auth.login_via_existing_enabled,
},
} }
} }

View File

@ -174,6 +174,7 @@ class LoginRestServlet(RestServlet):
# If the login token flow is enabled advertise the get_login_token flag. # If the login token flow is enabled advertise the get_login_token flag.
if self._get_login_token_enabled: if self._get_login_token_enabled:
tokenTypeFlow["get_login_token"] = True tokenTypeFlow["get_login_token"] = True
tokenTypeFlow["org.matrix.msc3882.get_login_token"] = True
flows.append(tokenTypeFlow) flows.append(tokenTypeFlow)
flows.extend({"type": t} for t in self.auth_handler.get_supported_login_types()) flows.extend({"type": t} for t in self.auth_handler.get_supported_login_types())

View File

@ -200,6 +200,7 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
self.assertEqual(channel.code, HTTPStatus.OK) self.assertEqual(channel.code, HTTPStatus.OK)
self.assertFalse(capabilities["m.get_login_token"]["enabled"]) self.assertFalse(capabilities["m.get_login_token"]["enabled"])
self.assertFalse(capabilities["org.matrix.msc3882.get_login_token"]["enabled"])
@override_config({"login_via_existing_session": {"enabled": True}}) @override_config({"login_via_existing_session": {"enabled": True}})
def test_get_get_token_login_fields_when_enabled(self) -> None: def test_get_get_token_login_fields_when_enabled(self) -> None:
@ -214,3 +215,4 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
self.assertEqual(channel.code, HTTPStatus.OK) self.assertEqual(channel.code, HTTPStatus.OK)
self.assertTrue(capabilities["m.get_login_token"]["enabled"]) self.assertTrue(capabilities["m.get_login_token"]["enabled"])
self.assertTrue(capabilities["org.matrix.msc3882.get_login_token"]["enabled"])

View File

@ -527,7 +527,11 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
self.assertCountEqual( self.assertCountEqual(
channel.json_body["flows"], channel.json_body["flows"],
[ [
{"type": "m.login.token", "get_login_token": True}, {
"type": "m.login.token",
"get_login_token": True,
"org.matrix.msc3882.get_login_token": True,
},
{"type": "m.login.password"}, {"type": "m.login.password"},
{"type": "m.login.application_service"}, {"type": "m.login.application_service"},
], ],

View File

@ -15,7 +15,7 @@
from twisted.test.proto_helpers import MemoryReactor from twisted.test.proto_helpers import MemoryReactor
from synapse.rest import admin from synapse.rest import admin
from synapse.rest.client import login, login_token_request, versions from synapse.rest.client import capabilities, login, login_token_request, versions
from synapse.server import HomeServer from synapse.server import HomeServer
from synapse.util import Clock from synapse.util import Clock
@ -31,6 +31,7 @@ class LoginTokenRequestServletTestCase(unittest.HomeserverTestCase):
admin.register_servlets, admin.register_servlets,
login_token_request.register_servlets, login_token_request.register_servlets,
versions.register_servlets, # TODO: remove once unstable revision 0 support is removed versions.register_servlets, # TODO: remove once unstable revision 0 support is removed
capabilities.register_servlets, # TODO: remove once unstable revision 1 support is removed
] ]
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer: def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
@ -179,18 +180,21 @@ class LoginTokenRequestServletTestCase(unittest.HomeserverTestCase):
def test_unstable_revision1_support(self) -> None: def test_unstable_revision1_support(self) -> None:
# TODO: remove when unstable MSC3882 is no longer needed # TODO: remove when unstable MSC3882 is no longer needed
self.register_user(self.user, self.password)
token = self.login(self.user, self.password)
# check feature is advertised in versions response: # check feature is advertised in versions response:
channel = self.make_request( channel = self.make_request(
"GET", "/_matrix/client/versions", {}, access_token=None "GET", "/_matrix/client/v3/capabilities", {}, access_token=token
) )
self.assertEqual(channel.code, 200) self.assertEqual(channel.code, 200)
self.assertEqual( self.assertEqual(
channel.json_body["unstable_features"]["org.matrix.msc3882"], True channel.json_body["capabilities"]["org.matrix.msc3882.get_login_token"][
"enabled"
],
True,
) )
self.register_user(self.user, self.password)
token = self.login(self.user, self.password)
# check feature is available via the r1 unstable endpoint and returns an expires_in_ms value in milliseconds # check feature is available via the r1 unstable endpoint and returns an expires_in_ms value in milliseconds
channel = self.make_request( channel = self.make_request(
"POST", "POST",