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

Add custom well-known #13035

Merged
merged 12 commits into from
Jun 16, 2022
24 changes: 24 additions & 0 deletions tests/rest/test_well_known.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ def test_client_well_known_no_public_baseurl(self) -> None:

self.assertEqual(channel.code, HTTPStatus.NOT_FOUND)

@unittest.override_config(
{
"default_identity_server": "https://testis",
}
)
def test_client_well_known_only_default_identity_server(self) -> None:
channel = self.make_request(
"GET", "/.well-known/matrix/client", shorthand=False
)

self.assertEqual(channel.code, HTTPStatus.NOT_FOUND)

@unittest.override_config(
{
"extra_well_known_content": {"custom": False},
}
)
def test_client_well_known_only_extra_well_known(self) -> None:
channel = self.make_request(
"GET", "/.well-known/matrix/client", shorthand=False
)

self.assertEqual(channel.code, HTTPStatus.NOT_FOUND)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised these tests pass as written.

  • override_config makes additions to the default_config; fields that aren't mentioned don't get changed
  • a public_baseurl will be set based on the server_name from default_config (see also - Add custom well-known #13035 (comment))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh. We only actually serve well-known if a public_baseurl is explicitly set:

# For the sake of backwards compatibility with existing installations, this is
# True if public_baseurl is specified explicitly, and otherwise False. (The
# reasoning here is that we have no way of knowing that the default
# public_baseurl is actually correct for existing installations - many things
# will not work correctly, but that's (probably?) better than sending clients
# to a completely broken URL.
self.serve_client_wellknown = False
public_baseurl = config.get("public_baseurl")
if public_baseurl is None:
public_baseurl = f"https://{self.server_name}/"
logger.info("Using default public_baseurl %s", public_baseurl)
else:
self.serve_client_wellknown = True
if public_baseurl[-1] != "/":
public_baseurl += "/"
self.public_baseurl = public_baseurl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these tests add much compared to test_client_well_known_no_public_baseurl (since that is the condition). Can you remove these please?

@unittest.override_config(
{
"public_baseurl": "https://tesths",
Expand Down