Skip to content

Commit

Permalink
events: include user agent in events (cherry-pick #7693) (#7938)
Browse files Browse the repository at this point in the history
events: include user agent in events (#7693)

* events: include user agent in events



* fix tests



---------

Signed-off-by: Jens Langhammer <[email protected]>
Co-authored-by: Jens L <[email protected]>
  • Loading branch information
gcp-cherry-pick-bot[bot] and BeryJu authored Dec 19, 2023
1 parent 750669d commit d9d5ac1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions authentik/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def from_http(self, request: HttpRequest, user: Optional[User] = None) -> "Event
"path": request.path,
"method": request.method,
"args": cleanse_dict(QueryDict(request.META.get("QUERY_STRING", ""))),
"user_agent": request.META.get("HTTP_USER_AGENT", ""),
}
# Special case for events created during flow execution
# since they keep the http query within a wrapped query
Expand Down
12 changes: 11 additions & 1 deletion authentik/events/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ def test_from_http_basic(self):
"""Test plain from_http"""
event = Event.new("unittest").from_http(self.factory.get("/"))
self.assertEqual(
event.context, {"http_request": {"args": {}, "method": "GET", "path": "/"}}
event.context,
{
"http_request": {
"args": {},
"method": "GET",
"path": "/",
"user_agent": "",
}
},
)

def test_from_http_clean_querystring(self):
Expand All @@ -67,6 +75,7 @@ def test_from_http_clean_querystring(self):
"args": {"token": SafeExceptionReporterFilter.cleansed_substitute},
"method": "GET",
"path": "/",
"user_agent": "",
}
},
)
Expand All @@ -83,6 +92,7 @@ def test_from_http_clean_querystring_flow(self):
"args": {"token": SafeExceptionReporterFilter.cleansed_substitute},
"method": "GET",
"path": "/",
"user_agent": "",
}
},
)
Expand Down
1 change: 1 addition & 0 deletions authentik/stages/authenticator_validate/tests/test_duo.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def test_full(self):
"args": {},
"method": "GET",
"path": f"/api/v3/flows/executor/{flow.slug}/",
"user_agent": "",
},
},
)

0 comments on commit d9d5ac1

Please sign in to comment.