Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/19186.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regression preventing subpaths in MAS endpoints.
6 changes: 4 additions & 2 deletions synapse/api/auth/mas.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def _metadata_url(self) -> str:
password=self._config.endpoint.password,
host=self._config.endpoint.host or "",
port=self._config.endpoint.port,
path=".well-known/openid-configuration",
path=(self._config.endpoint.path or "").strip("/")
+ "/.well-known/openid-configuration",
query=None,
fragment=None,
)
Expand All @@ -169,7 +170,8 @@ def _introspection_endpoint(self) -> str:
password=self._config.endpoint.password,
host=self._config.endpoint.host or "",
port=self._config.endpoint.port,
path="oauth2/introspect",
path=(self._config.endpoint.path or "").strip("/")
+ "/oauth2/introspect",
query=None,
fragment=None,
)
Expand Down
26 changes: 26 additions & 0 deletions tests/handlers/test_oauth_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,32 @@ def test_cached_expired_introspection(self) -> None:
self.assertEqual(self.server.calls, 1)


class MasAuthDelegationWithSubpath(MasAuthDelegation):
"""Test MAS delegation when the MAS server is hosted on a subpath."""

def default_config(self) -> dict[str, Any]:
config = super().default_config()
# Override the endpoint to include a subpath
config["matrix_authentication_service"]["endpoint"] = (
self.server.endpoint + "auth/path/"
)
return config

def test_introspection_endpoint_uses_subpath(self) -> None:
"""Test that the introspection endpoint correctly uses the configured subpath."""
expected_introspection_url = (
self.server.endpoint + "auth/path/oauth2/introspect"
)
self.assertEqual(self._auth._introspection_endpoint, expected_introspection_url)

def test_metadata_url_uses_subpath(self) -> None:
"""Test that the metadata URL correctly uses the configured subpath."""
expected_metadata_url = (
self.server.endpoint + "auth/path/.well-known/openid-configuration"
)
self.assertEqual(self._auth._metadata_url, expected_metadata_url)


@parameterized_class(
("config",),
[
Expand Down
Loading