auth: Allow easier bouncer testing in dev env.

This commit is contained in:
Mateusz Mandera 2023-10-02 01:52:22 +02:00 committed by Tim Abbott
parent ab633f4557
commit 8254b74019
3 changed files with 19 additions and 2 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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"