mirror of
https://mau.dev/maunium/synapse.git
synced 2025-01-06 01:04:32 +01:00
Disable incompatible Admin API endpoints
This commit is contained in:
parent
4d0231b364
commit
e343125b38
3 changed files with 40 additions and 8 deletions
|
@ -257,9 +257,11 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
|
||||||
DeleteRoomStatusByRoomIdRestServlet(hs).register(http_server)
|
DeleteRoomStatusByRoomIdRestServlet(hs).register(http_server)
|
||||||
JoinRoomAliasServlet(hs).register(http_server)
|
JoinRoomAliasServlet(hs).register(http_server)
|
||||||
VersionServlet(hs).register(http_server)
|
VersionServlet(hs).register(http_server)
|
||||||
UserAdminServlet(hs).register(http_server)
|
if not hs.config.experimental.msc3861.enabled:
|
||||||
|
UserAdminServlet(hs).register(http_server)
|
||||||
UserMembershipRestServlet(hs).register(http_server)
|
UserMembershipRestServlet(hs).register(http_server)
|
||||||
UserTokenRestServlet(hs).register(http_server)
|
if not hs.config.experimental.msc3861.enabled:
|
||||||
|
UserTokenRestServlet(hs).register(http_server)
|
||||||
UserRestServletV2(hs).register(http_server)
|
UserRestServletV2(hs).register(http_server)
|
||||||
UsersRestServletV2(hs).register(http_server)
|
UsersRestServletV2(hs).register(http_server)
|
||||||
UserMediaStatisticsRestServlet(hs).register(http_server)
|
UserMediaStatisticsRestServlet(hs).register(http_server)
|
||||||
|
@ -274,9 +276,10 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
|
||||||
RoomEventContextServlet(hs).register(http_server)
|
RoomEventContextServlet(hs).register(http_server)
|
||||||
RateLimitRestServlet(hs).register(http_server)
|
RateLimitRestServlet(hs).register(http_server)
|
||||||
UsernameAvailableRestServlet(hs).register(http_server)
|
UsernameAvailableRestServlet(hs).register(http_server)
|
||||||
ListRegistrationTokensRestServlet(hs).register(http_server)
|
if not hs.config.experimental.msc3861.enabled:
|
||||||
NewRegistrationTokenRestServlet(hs).register(http_server)
|
ListRegistrationTokensRestServlet(hs).register(http_server)
|
||||||
RegistrationTokenRestServlet(hs).register(http_server)
|
NewRegistrationTokenRestServlet(hs).register(http_server)
|
||||||
|
RegistrationTokenRestServlet(hs).register(http_server)
|
||||||
DestinationMembershipRestServlet(hs).register(http_server)
|
DestinationMembershipRestServlet(hs).register(http_server)
|
||||||
DestinationResetConnectionRestServlet(hs).register(http_server)
|
DestinationResetConnectionRestServlet(hs).register(http_server)
|
||||||
DestinationRestServlet(hs).register(http_server)
|
DestinationRestServlet(hs).register(http_server)
|
||||||
|
@ -306,10 +309,12 @@ def register_servlets_for_client_rest_resource(
|
||||||
# The following resources can only be run on the main process.
|
# The following resources can only be run on the main process.
|
||||||
if hs.config.worker.worker_app is None:
|
if hs.config.worker.worker_app is None:
|
||||||
DeactivateAccountRestServlet(hs).register(http_server)
|
DeactivateAccountRestServlet(hs).register(http_server)
|
||||||
ResetPasswordRestServlet(hs).register(http_server)
|
if not hs.config.experimental.msc3861.enabled:
|
||||||
|
ResetPasswordRestServlet(hs).register(http_server)
|
||||||
SearchUsersRestServlet(hs).register(http_server)
|
SearchUsersRestServlet(hs).register(http_server)
|
||||||
UserRegisterServlet(hs).register(http_server)
|
if not hs.config.experimental.msc3861.enabled:
|
||||||
AccountValidityRenewServlet(hs).register(http_server)
|
UserRegisterServlet(hs).register(http_server)
|
||||||
|
AccountValidityRenewServlet(hs).register(http_server)
|
||||||
|
|
||||||
# Load the media repo ones if we're using them. Otherwise load the servlets which
|
# Load the media repo ones if we're using them. Otherwise load the servlets which
|
||||||
# don't need a media repo (typically readonly admin APIs).
|
# don't need a media repo (typically readonly admin APIs).
|
||||||
|
|
|
@ -71,6 +71,7 @@ class UsersRestServletV2(RestServlet):
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.admin_handler = hs.get_admin_handler()
|
self.admin_handler = hs.get_admin_handler()
|
||||||
self._msc3866_enabled = hs.config.experimental.msc3866.enabled
|
self._msc3866_enabled = hs.config.experimental.msc3866.enabled
|
||||||
|
self._msc3861_enabled = hs.config.experimental.msc3861.enabled
|
||||||
|
|
||||||
async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
|
async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
|
||||||
await assert_requester_is_admin(self.auth, request)
|
await assert_requester_is_admin(self.auth, request)
|
||||||
|
@ -94,7 +95,14 @@ class UsersRestServletV2(RestServlet):
|
||||||
|
|
||||||
user_id = parse_string(request, "user_id")
|
user_id = parse_string(request, "user_id")
|
||||||
name = parse_string(request, "name")
|
name = parse_string(request, "name")
|
||||||
|
|
||||||
guests = parse_boolean(request, "guests", default=True)
|
guests = parse_boolean(request, "guests", default=True)
|
||||||
|
if self._msc3861_enabled and guests:
|
||||||
|
raise SynapseError(
|
||||||
|
HTTPStatus.BAD_REQUEST,
|
||||||
|
"The guests parameter is not supported when MSC3861 is enabled.",
|
||||||
|
errcode=Codes.INVALID_PARAM,
|
||||||
|
)
|
||||||
deactivated = parse_boolean(request, "deactivated", default=False)
|
deactivated = parse_boolean(request, "deactivated", default=False)
|
||||||
|
|
||||||
# If support for MSC3866 is not enabled, apply no filtering based on the
|
# If support for MSC3866 is not enabled, apply no filtering based on the
|
||||||
|
|
|
@ -31,6 +31,7 @@ from synapse.api.errors import (
|
||||||
InvalidClientTokenError,
|
InvalidClientTokenError,
|
||||||
OAuthInsufficientScopeError,
|
OAuthInsufficientScopeError,
|
||||||
)
|
)
|
||||||
|
from synapse.rest import admin
|
||||||
from synapse.rest.client import account, devices, keys, login, logout, register
|
from synapse.rest.client import account, devices, keys, login, logout, register
|
||||||
from synapse.server import HomeServer
|
from synapse.server import HomeServer
|
||||||
from synapse.types import JsonDict
|
from synapse.types import JsonDict
|
||||||
|
@ -104,6 +105,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
|
||||||
register.register_servlets,
|
register.register_servlets,
|
||||||
login.register_servlets,
|
login.register_servlets,
|
||||||
logout.register_servlets,
|
logout.register_servlets,
|
||||||
|
admin.register_servlets,
|
||||||
]
|
]
|
||||||
|
|
||||||
def default_config(self) -> Dict[str, Any]:
|
def default_config(self) -> Dict[str, Any]:
|
||||||
|
@ -557,3 +559,20 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
|
||||||
self.expect_unrecognized(
|
self.expect_unrecognized(
|
||||||
"POST", "/_matrix/client/v3/user/{USERNAME}/openid/request_token"
|
"POST", "/_matrix/client/v3/user/{USERNAME}/openid/request_token"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_admin_api_endpoints_removed(self) -> None:
|
||||||
|
"""Test that admin API endpoints that were removed in MSC2964 are no longer available."""
|
||||||
|
self.expect_unrecognized("GET", "/_synapse/admin/v1/registration_tokens")
|
||||||
|
self.expect_unrecognized("POST", "/_synapse/admin/v1/registration_tokens/new")
|
||||||
|
self.expect_unrecognized("GET", "/_synapse/admin/v1/registration_tokens/abcd")
|
||||||
|
self.expect_unrecognized("PUT", "/_synapse/admin/v1/registration_tokens/abcd")
|
||||||
|
self.expect_unrecognized(
|
||||||
|
"DELETE", "/_synapse/admin/v1/registration_tokens/abcd"
|
||||||
|
)
|
||||||
|
self.expect_unrecognized("POST", "/_synapse/admin/v1/reset_password/foo")
|
||||||
|
self.expect_unrecognized("POST", "/_synapse/admin/v1/users/foo/login")
|
||||||
|
self.expect_unrecognized("GET", "/_synapse/admin/v1/register")
|
||||||
|
self.expect_unrecognized("POST", "/_synapse/admin/v1/register")
|
||||||
|
self.expect_unrecognized("GET", "/_synapse/admin/v1/users/foo/admin")
|
||||||
|
self.expect_unrecognized("PUT", "/_synapse/admin/v1/users/foo/admin")
|
||||||
|
self.expect_unrecognized("POST", "/_synapse/admin/v1/account_validity/validity")
|
||||||
|
|
Loading…
Reference in a new issue