mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	remote_server: Handle data of non existent realms.
This commit adds code to make sure that the push notification does not crash on receiving data for a non-existent realm.
This commit is contained in:
		@@ -1909,6 +1909,36 @@ class AnalyticsBouncerTest(BouncerTestCase):
 | 
			
		||||
            ],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    @override_settings(PUSH_NOTIFICATION_BOUNCER_URL="https://push.zulip.org.example.com")
 | 
			
		||||
    @responses.activate
 | 
			
		||||
    def test_non_existent_realm_uuid(self) -> None:
 | 
			
		||||
        self.add_mock_response()
 | 
			
		||||
        realm_info = get_realms_info_for_push_bouncer()
 | 
			
		||||
 | 
			
		||||
        # Hard-delete a realm to test the non existent realm uuid case.
 | 
			
		||||
        realm = Realm.objects.order_by("id").first()
 | 
			
		||||
        assert realm is not None
 | 
			
		||||
        deleted_realm_uuid = realm.uuid
 | 
			
		||||
        realm.delete()
 | 
			
		||||
 | 
			
		||||
        with mock.patch(
 | 
			
		||||
            "zerver.lib.remote_server.get_realms_info_for_push_bouncer", return_value=realm_info
 | 
			
		||||
        ) as m, self.assertLogs("zulip.analytics", level="WARNING") as analytics_logger:
 | 
			
		||||
            send_server_data_to_push_bouncer(consider_usage_statistics=False)
 | 
			
		||||
            m.assert_called()
 | 
			
		||||
            realms = Realm.objects.all()
 | 
			
		||||
            for realm in realms:
 | 
			
		||||
                self.assertEqual(realm.push_notifications_enabled, True)
 | 
			
		||||
                self.assertEqual(realm.push_notifications_enabled_end_timestamp, None)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            analytics_logger.output,
 | 
			
		||||
            [
 | 
			
		||||
                "WARNING:zulip.analytics:"
 | 
			
		||||
                f"Received unexpected realm UUID from bouncer {deleted_realm_uuid}"
 | 
			
		||||
            ],
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PushNotificationTest(BouncerTestCase):
 | 
			
		||||
    @override
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user