🚧 Add broker status page
This commit is contained in:
@@ -194,6 +194,51 @@ def test_system_endpoints_rbac(auditor_client):
|
||||
)
|
||||
|
||||
|
||||
def test_broker_status_endpoint(admin_client, auditor_client):
|
||||
"""GET /broker/status returns the $SYS snapshot (spec 33/55).
|
||||
|
||||
No $SYS messages are ingested in tests (no real broker), so the
|
||||
endpoint must report available: False with all metrics None; after
|
||||
ingesting fake $SYS messages the snapshot reflects them. Read-only:
|
||||
the auditor role may view (spec section 9).
|
||||
"""
|
||||
from app import metrics
|
||||
|
||||
metrics.reset()
|
||||
|
||||
empty = admin_client.get("/api/v1/broker/status")
|
||||
assert empty.status_code == 200
|
||||
body = empty.json()
|
||||
assert body["available"] is False
|
||||
assert body["version"] is None
|
||||
assert body["clients_connected"] is None
|
||||
|
||||
# Ingest fake $SYS telemetry and verify the snapshot reflects it.
|
||||
metrics.handle_sys_message("$SYS/broker/version", b"2.1.2")
|
||||
metrics.handle_sys_message("$SYS/broker/clients/connected", b"4")
|
||||
metrics.handle_sys_message("$SYS/broker/retained messages/count", b"7")
|
||||
metrics.handle_sys_message("$SYS/broker/load/messages/received/1min", b"1.25")
|
||||
|
||||
body = admin_client.get("/api/v1/broker/status").json()
|
||||
assert body["available"] is True
|
||||
assert body["version"] == "2.1.2"
|
||||
assert body["clients_connected"] == 4
|
||||
assert body["retained_count"] == 7 # topic contains a literal space
|
||||
assert body["load_messages_received_1min"] == 1.25
|
||||
assert body["last_update"] is not None
|
||||
|
||||
# Unknown $SYS topics are ignored without breaking the snapshot.
|
||||
metrics.handle_sys_message("$SYS/broker/something/unknown", b"x")
|
||||
body = admin_client.get("/api/v1/broker/status").json()
|
||||
assert body["available"] is True
|
||||
|
||||
# Read-only for every management role (spec section 9: auditor has
|
||||
# read access to configuration/status).
|
||||
assert auditor_client.get("/api/v1/broker/status").status_code == 200
|
||||
|
||||
metrics.reset()
|
||||
|
||||
|
||||
def test_role_acl_lifecycle(admin_client):
|
||||
admin_client.post("/api/v1/mqtt/roles", json={"rolename": "telemetry"})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user