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

Commit

Permalink
Fix-up CAS code to always require a public baseurl.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Feb 3, 2021
1 parent 2e11204 commit 51fa14f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 11 additions & 10 deletions synapse/config/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ def read_config(self, config, **kwargs):
if self.cas_enabled:
self.cas_server_url = cas_config["server_url"]

# If the service_url is given, use it for backwards compatibility.
# Otherwise, use the public_baseurl.
public_base_url = cas_config.get("service_url") or self.public_baseurl
if not public_base_url:
# The public baseurl is required because it is used by the redirect
# template.
public_baseurl = self.public_baseurl
if not public_baseurl:
raise ConfigError("cas_config requires a public_baseurl to be set")

# If the service_url was given, ensure it doesn't have an extra slash.
if public_base_url[-1] != "/":
public_base_url += "/"
# If the service_url is given, use it for backwards compatibility.
# Otherwise, use the public_baseurl.
if cas_config.get("service_url"):
public_baseurl = cas_config["service_url"]
if public_baseurl[-1] != "/":
public_baseurl += "/"

# TODO Update this to a _synapse URL.
self.cas_service_url = (
public_base_url + "_matrix/client/r0/login/cas/ticket"
)
self.cas_service_url = public_baseurl + "_matrix/client/r0/login/cas/ticket"
self.cas_displayname_attribute = cas_config.get("displayname_attribute")
self.cas_required_attributes = cas_config.get("required_attributes") or {}
else:
Expand Down
4 changes: 3 additions & 1 deletion tests/rest/client/v1/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,12 @@ def make_homeserver(self, reactor, clock):
self.redirect_path = "_synapse/client/login/sso/redirect/confirm"

config = self.default_config()
config["public_baseurl"] = (
config.get("public_baseurl") or "https://matrix.goodserver.com:8448"
)
config["cas_config"] = {
"enabled": True,
"server_url": CAS_SERVER,
"service_url": "https://matrix.goodserver.com:8448",
}

cas_user_id = "username"
Expand Down

0 comments on commit 51fa14f

Please sign in to comment.