Compare commits

..

2 Commits

Author SHA1 Message Date
Stefan Agner
3bf5ea4a05 Add remaining NetworkManager device type enums (#6593) 2026-02-26 18:50:52 +01:00
Stefan Agner
7f6327e94e Handle missing Accept header in host logs (#6594)
* Handle missing Accept header in host logs

Avoid indexing request headers directly in the host advanced logs handler when Accept is absent, preventing KeyError crashes on valid requests without that header. Fixes SUPERVISOR-1939.

* Add pytest
2026-02-26 11:30:08 +01:00
3 changed files with 33 additions and 2 deletions

View File

@@ -240,7 +240,9 @@ class APIHost(CoreSysAttributes):
f"Cannot determine CONTAINER_LOG_EPOCH of {identifier}, latest logs not available."
) from err
if ACCEPT in request.headers and request.headers[ACCEPT] not in [
accept_header = request.headers.get(ACCEPT)
if accept_header and accept_header not in [
CONTENT_TYPE_TEXT,
CONTENT_TYPE_X_LOG,
"*/*",
@@ -250,7 +252,7 @@ class APIHost(CoreSysAttributes):
"supported for now."
)
if "verbose" in request.query or request.headers[ACCEPT] == CONTENT_TYPE_X_LOG:
if "verbose" in request.query or accept_header == CONTENT_TYPE_X_LOG:
log_formatter = LogFormatter.VERBOSE
if "no_colors" in request.query:

View File

@@ -304,14 +304,38 @@ class DeviceType(DBusIntEnum):
UNKNOWN = 0
ETHERNET = 1
WIRELESS = 2
UNUSED1 = 3
UNUSED2 = 4
BLUETOOTH = 5
OLPC_MESH = 6
WIMAX = 7
MODEM = 8
INFINIBAND = 9
BOND = 10
VLAN = 11
ADSL = 12
BRIDGE = 13
GENERIC = 14
TEAM = 15
TUN = 16
IP_TUNNEL = 17
MAC_VLAN = 18
VXLAN = 19
VETH = 20
MACSEC = 21
DUMMY = 22
PPP = 23
OVS_INTERFACE = 24
OVS_PORT = 25
OVS_BRIDGE = 26
WPAN = 27
LOWPAN6 = 28
WIREGUARD = 29
WIFI_P2P = 30
VRF = 31
LOOPBACK = 32
HSR = 33
IPVLAN = 34
class WirelessMethodType(DBusIntEnum):

View File

@@ -374,6 +374,11 @@ async def test_advanced_logs_formatters(
await api_client.get("/host/logs/identifiers/test", headers=headers)
journal_logs_reader.assert_called_once_with(ANY, LogFormatter.VERBOSE, False)
journal_logs_reader.reset_mock()
await api_client.get("/host/logs/identifiers/test", skip_auto_headers={"Accept"})
journal_logs_reader.assert_called_once_with(ANY, LogFormatter.PLAIN, False)
async def test_advanced_logs_errors(coresys: CoreSys, api_client: TestClient):
"""Test advanced logging API errors."""