push_notification: Improve logged message when apns_context is None.

Earlier, while sending notification if `apns_context=None` - we logged:
"APNs: Dropping a notification because nothing configured. Set
ZULIP_SERVICES_URL (or APNS_CERT_FILE)." which is not accurate for E2EE
case.

For the non-E2EE case it is correct because configuring
ZULIP_SERVICES_URL results in transfering the responsbility to
make API call to APNs to the bouncer. Or they can configure
APNS_CERT_FILE if they want to send directly.

In E2EE case, the `send_e2ee_push_notification_apple` is part of
bouncer so configuring `ZULIP_SERVICES_URL` doesn't help. One needs
to configure either `APNS_TOKEN_KEY_FILE` or `APNS_CERT_FILE`.

Message to log is updated accordingly + severity increased from
DEBUG to ERROR.

Signed-off-by: Prakhar Pratyush <prakhar@zulip.com>
This commit is contained in:
Prakhar Pratyush
2025-11-04 00:38:21 +05:30
committed by Tim Abbott
parent d893496de1
commit 25630f316b
2 changed files with 6 additions and 7 deletions

View File

@@ -221,7 +221,7 @@ class SendPushNotificationTest(E2EEPushNotificationTestCase):
self.mock_fcm() as mock_fcm_messaging, self.mock_fcm() as mock_fcm_messaging,
mock.patch("zilencer.lib.push_notifications.get_apns_context", return_value=None), mock.patch("zilencer.lib.push_notifications.get_apns_context", return_value=None),
self.assertLogs("zerver.lib.push_notifications", level="INFO") as zerver_logger, self.assertLogs("zerver.lib.push_notifications", level="INFO") as zerver_logger,
self.assertLogs("zilencer.lib.push_notifications", level="DEBUG") as zilencer_logger, self.assertLogs("zilencer.lib.push_notifications", level="WARNING") as zilencer_logger,
mock.patch("time.perf_counter", side_effect=[10.0, 12.0]), mock.patch("time.perf_counter", side_effect=[10.0, 12.0]),
): ):
mock_fcm_messaging.send_each.return_value = self.make_fcm_error_response( mock_fcm_messaging.send_each.return_value = self.make_fcm_error_response(
@@ -238,9 +238,8 @@ class SendPushNotificationTest(E2EEPushNotificationTestCase):
zerver_logger.output[0], zerver_logger.output[0],
) )
self.assertEqual( self.assertEqual(
"DEBUG:zilencer.lib.push_notifications:" "ERROR:zilencer.lib.push_notifications:"
"APNs: Dropping a notification because nothing configured. " "APNs: Dropping push notifications since neither APNS_TOKEN_KEY_FILE nor APNS_CERT_FILE is set.",
"Set ZULIP_SERVICES_URL (or APNS_CERT_FILE).",
zilencer_logger.output[0], zilencer_logger.output[0],
) )
self.assertIn( self.assertIn(

View File

@@ -40,9 +40,9 @@ def send_e2ee_push_notification_apple(
apns_context = get_apns_context() apns_context = get_apns_context()
if apns_context is None: if apns_context is None:
logger.debug( logger.error(
"APNs: Dropping a notification because nothing configured. " "APNs: Dropping push notifications since "
"Set ZULIP_SERVICES_URL (or APNS_CERT_FILE)." "neither APNS_TOKEN_KEY_FILE nor APNS_CERT_FILE is set."
) )
return SentPushNotificationResult( return SentPushNotificationResult(
successfully_sent_count=successfully_sent_count, successfully_sent_count=successfully_sent_count,