diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py index 830507a459..021c40b2d1 100644 --- a/zerver/lib/push_notifications.py +++ b/zerver/lib/push_notifications.py @@ -61,10 +61,6 @@ redis_client = get_redis_client() # for each request connection = None -# We maintain an additional APNS connection for pushing to Zulip apps that have been signed -# by the Dropbox certs (and have an app id of com.dropbox.zulip) -dbx_connection = None - # `APNS_SANDBOX` should be a bool assert isinstance(settings.APNS_SANDBOX, bool) @@ -147,10 +143,6 @@ if settings.APNS_CERT_FILE is not None and os.path.exists(settings.APNS_CERT_FIL connection = get_connection(settings.APNS_CERT_FILE, settings.APNS_KEY_FILE) -if settings.DBX_APNS_CERT_FILE is not None and os.path.exists(settings.DBX_APNS_CERT_FILE): # nocoverage - dbx_connection = get_connection(settings.DBX_APNS_CERT_FILE, - settings.DBX_APNS_KEY_FILE) - def num_push_devices_for_user(user_profile, kind = None): # type: (UserProfile, Optional[int]) -> PushDeviceToken if kind is None: @@ -169,7 +161,7 @@ def hex_to_b64(data): def _do_push_to_apns_service(user_id, message, apns_connection): # type: (int, APNsMessage, APNs) -> None - if not apns_connection: + if not apns_connection: # nocoverage logging.info("Not delivering APNS message %s to user %s due to missing connection" % (message, user_id)) return @@ -188,7 +180,7 @@ def send_apple_push_notification_to_user(user, alert, **extra_data): @statsd_increment("apple_push_notification") def send_apple_push_notification(user_id, devices, **extra_data): # type: (int, List[DeviceToken], **Any) -> None - if not connection and not dbx_connection: + if not connection: logging.warning("Attempting to send push notification, but no connection was found. " "This may be because we could not find the APNS Certificate file.") return @@ -197,22 +189,18 @@ def send_apple_push_notification(user_id, devices, **extra_data): tokens = [(b64_to_hex(device.token), device.ios_app_id, device.token) for device in devices] - for conn, app_ids in [ - (connection, [settings.ZULIP_IOS_APP_ID, None]), - (dbx_connection, [settings.DBX_IOS_APP_ID])]: - - valid_devices = [device for device in tokens if device[1] in app_ids] - valid_tokens = [device[0] for device in valid_devices] - if valid_tokens: - logging.info("APNS: Sending apple push notification " - "to devices: %s" % (valid_devices,)) - zulip_message = APNsMessage(user_id, valid_tokens, - alert=extra_data['zulip']['alert'], - **extra_data) - _do_push_to_apns_service(user_id, zulip_message, conn) - else: - logging.warn("APNS: Not sending notification because " - "tokens didn't match devices: %s" % (app_ids,)) + valid_devices = [device for device in tokens if device[1] in [settings.ZULIP_IOS_APP_ID, None]] + valid_tokens = [device[0] for device in valid_devices] + if valid_tokens: + logging.info("APNS: Sending apple push notification " + "to devices: %s" % (valid_devices,)) + zulip_message = APNsMessage(user_id, valid_tokens, + alert=extra_data['zulip']['alert'], + **extra_data) + _do_push_to_apns_service(user_id, zulip_message, connection) + else: # nocoverage + logging.warn("APNS: Not sending notification because " + "tokens didn't match devices: %s/%s" % (tokens, settings.ZULIP_IOS_APP_ID,)) # NOTE: This is used by the check_apns_tokens manage.py command. Do not call it otherwise, as the # feedback() call can take up to 15s diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 4be46df3cf..c55060230f 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -233,7 +233,6 @@ class PushNotificationTest(BouncerTestCase): self.user_profile = self.example_user('hamlet') apn.connection = apn.get_connection('fake-cert', 'fake-key') self.redis_client = apn.redis_client = MockRedis() # type: ignore - apn.dbx_connection = apn.get_connection('fake-cert', 'fake-key') self.tokens = [u'aaaa', u'bbbb'] for token in self.tokens: PushDeviceToken.objects.create( @@ -306,8 +305,7 @@ class HandlePushNotificationTest(PushNotificationTest): mock.patch('zerver.lib.push_notifications.requests.request', side_effect=self.bounce_request), \ mock.patch('zerver.lib.push_notifications._do_push_to_apns_service'), \ - mock.patch('logging.info') as mock_info, \ - mock.patch('logging.warn') as mock_warn: + mock.patch('logging.info') as mock_info: apn.handle_push_notification(self.user_profile.id, missed_message) devices = [ (apn.b64_to_hex(device.token), device.ios_app_id, device.token) @@ -315,10 +313,6 @@ class HandlePushNotificationTest(PushNotificationTest): ] mock_info.assert_called_with("APNS: Sending apple push " "notification to devices: %s" % (devices,)) - mock_warn.assert_called_with("APNS: Not sending " - "notification because tokens " - "didn't match devices: " - "['com.dropbox.Zulip']") def test_disabled_notifications(self): # type: () -> None @@ -723,19 +717,11 @@ class SendNotificationTest(PushNotificationTest): @mock.patch('logging.warn') @mock.patch('logging.info') @mock.patch('apns.GatewayConnection.send_notification_multiple') - def test_connection_single_none(self, mock_push, mock_info, mock_warn): + def test_connection_none(self, mock_push, mock_info, mock_warn): # type: (mock.MagicMock, mock.MagicMock, mock.MagicMock) -> None apn.connection = None apn.send_apple_push_notification_to_user(self.user_profile, "test alert") - @mock.patch('logging.error') - @mock.patch('apns.GatewayConnection.send_notification_multiple') - def test_connection_both_none(self, mock_push, mock_error): - # type: (mock.MagicMock, mock.MagicMock) -> None - apn.connection = None - apn.dbx_connection = None - apn.send_apple_push_notification_to_user(self.user_profile, "test alert") - class APNsFeedbackTest(PushNotificationTest): @mock.patch('logging.info') @mock.patch('apns.FeedbackConnection.items') diff --git a/zproject/settings.py b/zproject/settings.py index 315733051f..d25debf1ed 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -1204,7 +1204,6 @@ POLL_TIMEOUT = 90 * 1000 # iOS App IDs ZULIP_IOS_APP_ID = 'com.zulip.Zulip' -DBX_IOS_APP_ID = 'com.dropbox.Zulip' ######################################################################## # SSO AND LDAP SETTINGS