mirror of https://github.com/zulip/zulip.git
register: Not all clients send a User-Agent header.
In 1fce1c3c73
, we added logic to parse
the User-Agent in /register requests; this logic crashed if an HTTP request
was missing that header.
Includes a test for `/register` with no user agent passed; this should catch
similar regressions in the future.
Co-authored-by: Mateusz Mandera <mateusz.mandera@zulip.com>
This commit is contained in:
parent
0e0a910304
commit
1f18fa6580
|
@ -140,7 +140,7 @@ def is_unsupported_browser(user_agent: str) -> Tuple[bool, Optional[str]]:
|
|||
return (False, browser_name)
|
||||
|
||||
|
||||
def is_pronouns_field_type_supported(user_agent_str: str) -> bool:
|
||||
def is_pronouns_field_type_supported(user_agent_str: Optional[str]) -> bool:
|
||||
# In order to avoid users having a bad experience with these
|
||||
# custom profile fields disappearing after applying migration
|
||||
# 0421_migrate_pronouns_custom_profile_fields, we provide this
|
||||
|
@ -150,6 +150,9 @@ def is_pronouns_field_type_supported(user_agent_str: str) -> bool:
|
|||
# TODO/compatibility(7.0): Because this is a relatively minor
|
||||
# detail, we can remove this compatibility hack once most users
|
||||
# have upgraded to a sufficiently new mobile client.
|
||||
if user_agent_str is None:
|
||||
return True
|
||||
|
||||
user_agent = parse_user_agent(user_agent_str)
|
||||
if user_agent["name"] != "ZulipMobile":
|
||||
return True
|
||||
|
|
|
@ -50,6 +50,10 @@ from zerver.views.events_register import (
|
|||
|
||||
|
||||
class EventsEndpointTest(ZulipTestCase):
|
||||
def test_events_register_without_user_agent(self) -> None:
|
||||
result = self.client_post("/json/register", skip_user_agent=True)
|
||||
self.assert_json_success(result)
|
||||
|
||||
def test_events_register_endpoint(self) -> None:
|
||||
|
||||
# This test is intended to get minimal coverage on the
|
||||
|
|
|
@ -124,7 +124,9 @@ def events_register_backend(
|
|||
client = RequestNotes.get_notes(request).client
|
||||
assert client is not None
|
||||
|
||||
pronouns_field_type_supported = is_pronouns_field_type_supported(request.headers["User-Agent"])
|
||||
pronouns_field_type_supported = is_pronouns_field_type_supported(
|
||||
request.headers.get("User-Agent")
|
||||
)
|
||||
ret = do_events_register(
|
||||
user_profile,
|
||||
realm,
|
||||
|
|
Loading…
Reference in New Issue