config_error: Coalesce redundant dicts.

This commit is contained in:
Alex Vandiver 2023-10-06 14:05:07 +00:00 committed by Tim Abbott
parent 536aa32255
commit 5506dffa36
6 changed files with 29 additions and 40 deletions

View File

@ -14,7 +14,7 @@
<div class="errorcontent"> <div class="errorcontent">
<h1 class="lead">{{ _("Configuration error") }}</h1> <h1 class="lead">{{ _("Configuration error") }}</h1>
<br /> <br />
{% if error_name == "ldap_error_realm_is_none" %} {% if error_name == "ldap" %}
{% trans %} {% trans %}
You are trying to log in using LDAP without creating an You are trying to log in using LDAP without creating an
organization first. Please use EmailAuthBackend to create organization first. Please use EmailAuthBackend to create
@ -22,7 +22,7 @@
{% endtrans %} {% endtrans %}
{% endif %} {% endif %}
{% if error_name == "smtp_error" %} {% if error_name == "smtp" %}
<p> <p>
It appears there are problems with the It appears there are problems with the
email configuration. email configuration.
@ -47,7 +47,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if error_name == "dev_not_supported_error" %} {% if error_name == "dev_not_supported" %}
{% include "zerver/authentication_backends/dev-not-supported-error.html" %} {% include "zerver/authentication_backends/dev-not-supported-error.html" %}
{% endif %} {% endif %}
@ -55,8 +55,8 @@
{% if development_environment %} {% if development_environment %}
{% with %} {% with %}
{% set settings_path = secrets_path %} {% set settings_path = secrets_path %}
{% set client_id_key_name = "social_auth_" + social_backend_name + "_key" %} {% set client_id_key_name = "social_auth_" + error_name + "_key" %}
{% include "zerver/authentication_backends/" + social_backend_name + "-error.html" %} {% include "zerver/authentication_backends/" + error_name + "-error.html" %}
{% endwith %} {% endwith %}
<p> <p>
For more information, have a look at For more information, have a look at
@ -65,8 +65,8 @@
</p> </p>
{% else %} {% else %}
{% with %} {% with %}
{% set client_id_key_name = "SOCIAL_AUTH_" + social_backend_name.upper() + "_KEY" %} {% set client_id_key_name = "SOCIAL_AUTH_" + error_name.upper() + "_KEY" %}
{% include "zerver/authentication_backends/" + social_backend_name + "-error.html" %} {% include "zerver/authentication_backends/" + error_name + "-error.html" %}
{% endwith %} {% endwith %}
<p> <p>
For more information, have a look at For more information, have a look at
@ -76,7 +76,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if social_backend_name == "saml" %} {% if error_name == "saml" %}
<p> <p>
SAML authentication is either not enabled or misconfigured. Have a look at SAML authentication is either not enabled or misconfigured. Have a look at
our <a href="https://zulip.readthedocs.io/en/latest/production/authentication-methods.html#SAML">setup guide</a>. our <a href="https://zulip.readthedocs.io/en/latest/production/authentication-methods.html#SAML">setup guide</a>.
@ -90,18 +90,19 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if error_name == "remoteuser_error_backend_disabled" %} {% if error_name == "remote_user_backend_disabled" %}
<p> <p>
Authentication via the REMOTE_USER header is Authentication via the REMOTE_USER header is
disabled in `/etc/zulip/settings.py`. disabled in `/etc/zulip/settings.py`.
</p> </p>
{% endif %} {% endif %}
{% if error_name == "remoteuser_error_remote_user_header_missing" %} {% if error_name == "remote_user_header_missing" %}
<p> <p>
The REMOTE_USER header is not set. The REMOTE_USER header is not set.
</p> </p>
{% endif %} {% endif %}
{% if error_name == "oidc_error" %} {% if error_name == "oidc" %}
{# TODO: Improve the config error page for OIDC #}
<p> <p>
The OpenID Connect backend is not configured correctly. The OpenID Connect backend is not configured correctly.
</p> </p>

View File

@ -5407,7 +5407,7 @@ class TestDevAuthBackend(ZulipTestCase):
self.assert_in_success_response(["Configuration error", "DevAuthBackend"], response) self.assert_in_success_response(["Configuration error", "DevAuthBackend"], response)
def test_dev_direct_production_config_error(self) -> None: def test_dev_direct_production_config_error(self) -> None:
result = self.client_get("/config-error/dev") result = self.client_get("/config-error/dev_not_supported")
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
self.assert_in_success_response(["DevAuthBackend"], result) self.assert_in_success_response(["DevAuthBackend"], result)

View File

@ -15,7 +15,6 @@ from zerver.lib.url_redirects import (
) )
from zerver.models import Stream from zerver.models import Stream
from zproject import urls from zproject import urls
from zproject.backends import AUTH_BACKEND_NAME_MAP
class PublicURLTest(ZulipTestCase): class PublicURLTest(ZulipTestCase):
@ -136,23 +135,19 @@ class PublicURLTest(ZulipTestCase):
Here we simply sanity-check that all the URLs load Here we simply sanity-check that all the URLs load
correctly. correctly.
""" """
auth_types = [auth.lower() for auth in AUTH_BACKEND_NAME_MAP] auth_error_pages = [
for auth in [ "apple",
"azuread", "dev_not_supported",
"email", "github",
"remoteuser", "gitlab",
# The endpoint is generated dynamically based on the configuration of the OIDC backend, "google",
# so it can't be tested here. "ldap",
"openid connect", "remote_user_backend_disabled",
]: # We do not have configerror pages for AzureAD and Email. "remote_user_header_missing",
auth_types.remove(auth) "saml",
auth_types += [
"smtp", "smtp",
"remoteuser/remote_user_backend_disabled",
"remoteuser/remote_user_header_missing",
] ]
urls = [f"/config-error/{auth_type}" for auth_type in auth_types] urls = [f"/config-error/{err_page_name}" for err_page_name in auth_error_pages]
with self.settings(DEVELOPMENT=True): with self.settings(DEVELOPMENT=True):
for url in urls: for url in urls:
response = self.client_get(url) response = self.client_get(url)

View File

@ -76,7 +76,7 @@ def dev_direct_login(
if (not dev_auth_enabled()) or settings.PRODUCTION: if (not dev_auth_enabled()) or settings.PRODUCTION:
# This check is probably not required, since authenticate would fail without # This check is probably not required, since authenticate would fail without
# an enabled DevAuthBackend. # an enabled DevAuthBackend.
return config_error(request, "dev") return config_error(request, "dev_not_supported")
subdomain = get_subdomain(request) subdomain = get_subdomain(request)
realm = get_realm(subdomain) realm = get_realm(subdomain)
@ -88,7 +88,7 @@ def dev_direct_login(
email = request.POST["direct_email"] email = request.POST["direct_email"]
user_profile = authenticate(dev_auth_username=email, realm=realm) user_profile = authenticate(dev_auth_username=email, realm=realm)
if user_profile is None: if user_profile is None:
return config_error(request, "dev") return config_error(request, "dev_not_supported")
assert isinstance(user_profile, UserProfile) assert isinstance(user_profile, UserProfile)
do_login(request, user_profile) do_login(request, user_profile)

View File

@ -10,14 +10,8 @@ def config_error(request: HttpRequest, error_category_name: str) -> HttpResponse
"google": {"social_backend_name": "google", "has_error_template": True}, "google": {"social_backend_name": "google", "has_error_template": True},
"github": {"social_backend_name": "github", "has_error_template": True}, "github": {"social_backend_name": "github", "has_error_template": True},
"gitlab": {"social_backend_name": "gitlab", "has_error_template": True}, "gitlab": {"social_backend_name": "gitlab", "has_error_template": True},
"ldap": {"error_name": "ldap_error_realm_is_none"},
"dev": {"error_name": "dev_not_supported_error"},
"saml": {"social_backend_name": "saml"},
"smtp": {"error_name": "smtp_error"},
"remote_user_backend_disabled": {"error_name": "remoteuser_error_backend_disabled"},
"remote_user_header_missing": {"error_name": "remoteuser_error_remote_user_header_missing"},
# TODO: Improve the config error page for OIDC.
"oidc": {"error_name": "oidc_error"},
} }
return render(request, "zerver/config_error.html", contexts[error_category_name]) context = contexts.get(error_category_name, {})
context["error_name"] = error_category_name
return render(request, "zerver/config_error.html", context)

View File

@ -92,7 +92,6 @@ urls = [
), ),
path("devtools/integrations/<integration_name>/fixtures", get_fixtures), path("devtools/integrations/<integration_name>/fixtures", get_fixtures),
path("config-error/<error_category_name>", config_error, name="config_error"), path("config-error/<error_category_name>", config_error, name="config_error"),
path("config-error/remoteuser/<error_category_name>", config_error),
# Special endpoint to remove all the server-side caches. # Special endpoint to remove all the server-side caches.
path("flush_caches", remove_caches), path("flush_caches", remove_caches),
# Redirect camo URLs for development # Redirect camo URLs for development