mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	compatibility: Respond with HTTP 400 when no User-Agent header.
Prior to this commit, a request to /compatibility without a User-Agent header would result in the server 500ing.
This commit is contained in:
		@@ -78,6 +78,10 @@ class CompatibilityTest(ZulipTestCase):
 | 
			
		||||
      ok  ZulipMobile/20.0.103 (iOS 12.1)
 | 
			
		||||
    '''.strip().split('\n') if case]
 | 
			
		||||
 | 
			
		||||
    def test_compatibility_without_user_agent(self) -> None:
 | 
			
		||||
        result = self.client_get("/compatibility")
 | 
			
		||||
        self.assert_json_error(result, 'User-Agent header missing from request')
 | 
			
		||||
 | 
			
		||||
    def test_compatibility(self) -> None:
 | 
			
		||||
        for expected, user_agent in self.data:
 | 
			
		||||
            result = self.client_get("/compatibility",
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,8 @@ from django.http import HttpResponse, HttpRequest
 | 
			
		||||
import re
 | 
			
		||||
from typing import Any, List, Dict, Optional, Tuple, Union
 | 
			
		||||
 | 
			
		||||
from django.utils.translation import ugettext as _
 | 
			
		||||
 | 
			
		||||
from zerver.lib.response import json_error, json_success
 | 
			
		||||
from zerver.lib.user_agent import parse_user_agent
 | 
			
		||||
 | 
			
		||||
@@ -71,6 +73,9 @@ def find_mobile_os(user_agent: str) -> Optional[str]:
 | 
			
		||||
android_min_app_version = '16.2.96'
 | 
			
		||||
 | 
			
		||||
def check_global_compatibility(request: HttpRequest) -> HttpResponse:
 | 
			
		||||
    if request.META.get('HTTP_USER_AGENT') is None:
 | 
			
		||||
        return json_error(_('User-Agent header missing from request'))
 | 
			
		||||
 | 
			
		||||
    # This string should not be tagged for translation, since old
 | 
			
		||||
    # clients are checking for an extra string.
 | 
			
		||||
    legacy_compatibility_error_message = "Client is too old"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user