Log device-facing /frame/* requests in the server log
The admin log viewer only ever showed exceptions from device.py, not successful requests -- no way to see a request that was slow-but-200, or a device probing with a stale/wrong token. Adds a middleware that logs method, path, device id (never the token), status, and wall time for every /frame/* request.
This commit is contained in:
@@ -8,6 +8,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
|
||||
from app.logging_setup import LOG_PATH
|
||||
from app.models import Frame
|
||||
|
||||
from .conftest import login, make_user
|
||||
|
||||
@@ -52,6 +53,20 @@ def test_admin_can_download_log_file(client, db_session):
|
||||
assert b"marker-line-for-download" in resp.content
|
||||
|
||||
|
||||
def test_device_requests_are_logged(client, db_session):
|
||||
_setup_admin_and_user(client, db_session)
|
||||
frame = db_session.get(Frame, 1)
|
||||
frame.device_id = "aabbccddeeff"
|
||||
db_session.commit()
|
||||
resp = client.get(f"/frame/config?id={frame.device_id}&token={frame.device_token}")
|
||||
assert resp.status_code == 200
|
||||
|
||||
login(client, "alice", "hunter22")
|
||||
log_resp = client.get("/admin/logs")
|
||||
# Jinja HTML-escapes the rendered <pre>, so "->" becomes "->".
|
||||
assert f"GET /frame/config id={frame.device_id} -> 200" in log_resp.text
|
||||
|
||||
|
||||
def test_download_404s_before_any_log_written(client, db_session, monkeypatch):
|
||||
_setup_admin_and_user(client, db_session)
|
||||
login(client, "alice", "hunter22")
|
||||
|
||||
Reference in New Issue
Block a user