Skip to content

Commit ca56ebb

Browse files
authored
Fix #282: defaults user-agent to empty string in request.summary (#327)
* Fix #282: defaults user-agent to empty string in request.summary * Remove useless comment
1 parent cbf5684 commit ca56ebb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

jbi/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def format_request_summary_fields(
6464

6565
current_time = time.time()
6666
return RequestSummary(
67-
agent=request.headers.get("User-Agent"),
67+
agent=request.headers.get("User-Agent", ""),
6868
path=request.url.path,
6969
method=request.method,
7070
lang=request.headers.get("Accept-Language"),

tests/unit/test_main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ def test_request_summary_is_logged(caplog):
2222
assert summary.querystring == "{}"
2323

2424

25+
def test_request_summary_defaults_user_agent_to_empty_string(caplog):
26+
with caplog.at_level(logging.INFO):
27+
with TestClient(app) as anon_client:
28+
del anon_client.headers["User-Agent"]
29+
anon_client.get("/")
30+
31+
summary = caplog.records[-1]
32+
33+
assert summary.agent == ""
34+
35+
2536
def test_errors_are_reported_to_sentry(
2637
anon_client, webhook_create_example: BugzillaWebhookRequest
2738
):

0 commit comments

Comments
 (0)