Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
push_notifs: Log an error if ios_app_id missing on any APNs token.
Greg Price7a0ebc0d18d7
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.pyindex d9e2cf0feed..2443b60fd78 100644--- a/zerver/lib/push_notifications.py+++ b/zerver/lib/push_notifications.py@@ -258,6 +258,14 @@ def send_apple_push_notification(payload_data = dict(modernize_apns_payload(payload_data))message = {**payload_data.pop("custom", {}), "aps": payload_data}+ for device in devices:+ if device.ios_app_id is None:+ # This should be present for all APNs tokens, as an invariant maintained+ # by the views that add the token to our database.+ logger.error(+ "APNs: Missing ios_app_id for user %s device %s", user_identity, device.token+ )+async def send_all_notifications() -> Iterable[Tuple[DeviceToken, Union[aioapns.common.NotificationResult, BaseException]]]:diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.pyindex 0310a3953d3..af37be1b0c7 100644--- a/zerver/tests/test_push_notifications.py+++ b/zerver/tests/test_push_notifications.py@@ -2277,6 +2277,24 @@ class TestAPNs(PushNotificationTest):logger.output,)+ def test_log_missing_ios_app_id(self) -> None:+ device = RemotePushDeviceToken.objects.create(+ kind=RemotePushDeviceToken.APNS,+ token="1234",+ ios_app_id=None,+ user_id=self.user_profile.id,+ server=RemoteZulipServer.objects.get(uuid=self.server_uuid),+ )+ with self.mock_apns() as (apns_context, send_notification), self.assertLogs(+ "zerver.lib.push_notifications", level="INFO"+ ) as logger:+ send_notification.return_value.is_successful = True+ self.send(devices=[device])+ self.assertIn(+ f"ERROR:zerver.lib.push_notifications:APNs: Missing ios_app_id for user <id:{self.user_profile.id}> device {device.token}",+ logger.output,+ )+def test_modernize_apns_payload(self) -> None:payload = {"alert": "Message from Hamlet",