Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

auth: Allow easier bouncer testing in dev env.

Mateusz Mandera8254b74019a9
diff --git a/zilencer/auth.py b/zilencer/auth.py
index 44141a0eb42..858ff515990 100644
--- a/zilencer/auth.py
+++ b/zilencer/auth.py
@@ -2,6 +2,7 @@ import logging
from functools import wraps
from typing import Any, Callable
+from django.conf import settings
from django.http import HttpRequest, HttpResponse
from django.urls import path
from django.urls.resolvers import URLPattern
@@ -81,8 +82,11 @@ def validate_remote_server(
if remote_server.deactivated:
raise RemoteServerDeactivatedError
-
- if get_subdomain(request) != Realm.SUBDOMAIN_FOR_ROOT_DOMAIN:
+ if (
+ get_subdomain(request) != Realm.SUBDOMAIN_FOR_ROOT_DOMAIN
+ and not settings.DEVELOPMENT_DISABLE_PUSH_BOUNCER_DOMAIN_CHECK
+ ):
+ # Sometimes we may want to test push bouncer logic in development.
raise JsonableError(_("Invalid subdomain for push notifications bouncer"))
RequestNotes.get_notes(request).remote_server = remote_server
process_client(request)
diff --git a/zproject/default_settings.py b/zproject/default_settings.py
index ed94392dd0d..69d01f23f6c 100644
--- a/zproject/default_settings.py
+++ b/zproject/default_settings.py
@@ -309,6 +309,12 @@ TUTORIAL_ENABLED = True
# them easily through /emails page
DEVELOPMENT_LOG_EMAILS = DEVELOPMENT
+# The push bouncer expects to get its requests on the root subdomain,
+# but that makes it more of a hassle to test bouncer endpoints in
+# the development environment - so this setting allows us to disable
+# that check.
+DEVELOPMENT_DISABLE_PUSH_BOUNCER_DOMAIN_CHECK = False
+
# These settings are not documented in prod_settings_template.py.
# They should either be documented here, or documented there.
diff --git a/zproject/dev_settings.py b/zproject/dev_settings.py
index 6e1cbd2c106..905597a8ac4 100644
--- a/zproject/dev_settings.py
+++ b/zproject/dev_settings.py
@@ -203,3 +203,10 @@ SCIM_CONFIG: Dict[str, SCIMConfigDict] = {
"name_formatted_included": True,
}
}
+
+# You can uncomment these lines to use the development environment
+# server as a dummy push bouncer for itself, to test functionalities
+# such as register_server or update_analytics_counts management commands
+# or others involving new bouncer-side logic.
+# DEVELOPMENT_DISABLE_PUSH_BOUNCER_DOMAIN_CHECK = True
+# PUSH_NOTIFICATION_BOUNCER_URL = "http://localhost:9991"