From e6fa1f54364807c7ed06b2435a86979287eb816d Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 8 Feb 2024 19:15:01 +0000 Subject: [PATCH] email_mirror_message: Move endpoint under /api/internal/. This also has the side effect that it saves the endpint from being improperly redirected by the HostDomainMiddleware's canonicalization code. --- scripts/lib/email-mirror-postfix | 4 ++-- zerver/tests/test_email_mirror.py | 2 +- zproject/urls.py | 13 +++---------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/scripts/lib/email-mirror-postfix b/scripts/lib/email-mirror-postfix index a0ab0ffc72..a5d68676fc 100755 --- a/scripts/lib/email-mirror-postfix +++ b/scripts/lib/email-mirror-postfix @@ -32,7 +32,7 @@ Also you can use optional keys to configure the script and change default values -d HOST Destination Zulip host for email uploading. Address must contain type of HTTP protocol, e.g. "https://example.com". Default value: "https://127.0.0.1". --u URL Destination relative for email uploading. Default value: "/email_mirror_message". +-u URL Destination relative for email uploading. Default value: "/api/internal/email_mirror_message". -n Disable checking ssl certificate. This option is used for self-signed certificates. Default value: False. @@ -76,7 +76,7 @@ parser.add_argument( "-u", "--dst-url", dest="url", - default="/email_mirror_message", + default="/api/internal/email_mirror_message", help="Destination relative URL for uploading email from email mirror.", ) diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py index b72286cce4..c7c878c6d3 100644 --- a/zerver/tests/test_email_mirror.py +++ b/zerver/tests/test_email_mirror.py @@ -1543,7 +1543,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase): with mock_queue_publish("zerver.lib.email_mirror.queue_json_publish") as m: m.side_effect = check_queue_json_publish - return self.client_post("/email_mirror_message", post_data) + return self.client_post("/api/internal/email_mirror_message", post_data) def test_success_stream(self) -> None: stream = get_stream("Denmark", get_realm("zulip")) diff --git a/zproject/urls.py b/zproject/urls.py index 8e3d993f36..a8387aea40 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -726,11 +726,6 @@ v1_api_mobile_patterns = [ path("jwt/fetch_api_key", jwt_fetch_api_key), ] -# View for uploading messages from email mirror -urls += [ - path("email_mirror_message", email_mirror_message), -] - # Include URL configuration files for site-specified extra installed # Django apps for app_name in settings.EXTRA_INSTALLED_APPS: @@ -739,12 +734,10 @@ for app_name in settings.EXTRA_INSTALLED_APPS: urls += [path("", include(f"{app_name}.urls"))] i18n_urls += import_string(f"{app_name}.urls.i18n_urlpatterns") -# Tornado views +# Used internally for communication between command-line, Django, +# and Tornado processes urls += [ - # Used internally for communication between Django and Tornado processes - # - # Since these views don't use rest_dispatch, they cannot have - # asynchronous Tornado behavior. + path("api/internal/email_mirror_message", email_mirror_message), path("api/internal/notify_tornado", notify), path("api/v1/events/internal", get_events_internal), ]