Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
push_notification: Drop notif if ANDROID_FCM_CREDENTIALS_PATH is unset.
Prakhar Pratyushd893496de1c4
diff --git a/zerver/tests/test_e2ee_push_notifications.py b/zerver/tests/test_e2ee_push_notifications.pyindex e80ed3e72d9..de4513bb71c 100644--- a/zerver/tests/test_e2ee_push_notifications.py+++ b/zerver/tests/test_e2ee_push_notifications.py@@ -294,6 +294,46 @@ class SendPushNotificationTest(E2EEPushNotificationTestCase):zerver_logger.output[2],)+ # `ANDROID_FCM_CREDENTIALS_PATH` is unset / fcm_app=None.+ message_id = self.send_personal_message(+ from_user=aaron, to_user=hamlet, skip_capture_on_commit_callbacks=True+ )+ missed_message = {+ "message_id": message_id,+ "trigger": NotificationTriggers.DIRECT_MESSAGE,+ }++ with (+ mock.patch("zilencer.lib.push_notifications.fcm_app", new=None),+ mock.patch(+ "zilencer.lib.push_notifications.send_e2ee_push_notification_apple",+ return_value=SentPushNotificationResult(+ successfully_sent_count=1,+ delete_device_ids=[],+ ),+ ),+ self.assertLogs("zerver.lib.push_notifications", level="INFO") as zerver_logger,+ self.assertLogs("zilencer.lib.push_notifications", level="ERROR") as zilencer_logger,+ mock.patch("time.perf_counter", side_effect=[10.0, 12.0]),+ ):+ handle_push_notification(hamlet.id, missed_message)++ self.assertEqual(+ "INFO:zerver.lib.push_notifications:"+ f"Sending push notifications to mobile clients for user {hamlet.id}",+ zerver_logger.output[0],+ )+ self.assertEqual(+ "ERROR:zilencer.lib.push_notifications:"+ "FCM: Dropping push notifications since ANDROID_FCM_CREDENTIALS_PATH is unset",+ zilencer_logger.output[0],+ )+ self.assertEqual(+ "INFO:zerver.lib.push_notifications:"+ f"Sent E2EE mobile push notifications for user {hamlet.id}: 0 via FCM, 1 via APNs in 2.000s",+ zerver_logger.output[2],+ )+def test_early_return_if_expired_time_set(self) -> None:aaron = self.example_user("aaron")hamlet = self.example_user("hamlet")diff --git a/zilencer/lib/push_notifications.py b/zilencer/lib/push_notifications.pyindex c3adafbb0fd..e25947f38e1 100644--- a/zilencer/lib/push_notifications.py+++ b/zilencer/lib/push_notifications.py@@ -88,6 +88,13 @@ def send_e2ee_push_notification_android(successfully_sent_count = 0delete_device_ids: list[int] = []+ if fcm_app is None:+ logger.error("FCM: Dropping push notifications since ANDROID_FCM_CREDENTIALS_PATH is unset")+ return SentPushNotificationResult(+ successfully_sent_count=successfully_sent_count,+ delete_device_ids=delete_device_ids,+ )+try:batch_response = firebase_messaging.send_each(fcm_requests, app=fcm_app)except firebase_exceptions.FirebaseError: