0a497ca0f1
Run Tests / Secret Detection (pull_request) Failing after 42s
Run Tests / Backend Tests (pull_request) Successful in 32m26s
Run Tests / Frontend Tests (pull_request) Failing after 26s
Deploy Dashboard (Dev) / Backend Tests (push) Successful in 30m35s
Deploy Dashboard (Dev) / Frontend Tests (push) Failing after 16m37s
Deploy Dashboard (Dev) / Deploy to Dev (push) Has been skipped
- Add agent fetchrow to OPC mock to fix "Task or agent not found" errors
- Reorder conversation tracker routes: /search, /stats, /trigger before /{session_id}
- Fix test_task_creator_tracked_in_metadata to expect token username (testuser)
- Mock shutil/psutil in system stats test for non-Synology environments
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
84 lines
3.0 KiB
Python
84 lines
3.0 KiB
Python
"""Integration tests for system router"""
|
|
|
|
import pytest
|
|
from unittest.mock import Mock, patch
|
|
|
|
|
|
def test_system_stats_endpoint(test_app, admin_headers):
|
|
"""Test system stats endpoint returns expected format"""
|
|
mock_disk = Mock()
|
|
mock_disk.total = 1000000000000
|
|
mock_disk.used = 500000000000
|
|
mock_disk.free = 500000000000
|
|
|
|
mock_mem = Mock()
|
|
mock_mem.total = 8000000000
|
|
mock_mem.available = 4000000000
|
|
mock_mem.used = 4000000000
|
|
mock_mem.percent = 50.0
|
|
|
|
with patch("shutil.disk_usage", return_value=mock_disk), \
|
|
patch("psutil.disk_partitions", return_value=[]), \
|
|
patch("psutil.virtual_memory", return_value=mock_mem), \
|
|
patch("psutil.cpu_percent", return_value=25.5), \
|
|
patch("psutil.getloadavg", return_value=(1.0, 0.5, 0.2)), \
|
|
patch("psutil.boot_time", return_value=1000000.0):
|
|
response = test_app.get("/api/system/stats", headers=admin_headers)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "cpu_percent" in data
|
|
assert "cpu_count" in data
|
|
assert "load_avg" in data
|
|
assert "memory" in data
|
|
assert "disk" in data
|
|
assert "uptime" in data
|
|
assert "platform" in data
|
|
assert "volumes" in data
|
|
|
|
|
|
def test_audit_log_endpoint(test_app, admin_headers, temp_volume_root):
|
|
"""Test audit log endpoint returns expected format"""
|
|
import os
|
|
|
|
audit_path = os.path.join(temp_volume_root, "docker/nas-dashboard/audit.log")
|
|
os.makedirs(os.path.dirname(audit_path), exist_ok=True)
|
|
with open(audit_path, "w") as f:
|
|
f.write("2024-01-01T10:00:00 1.2.3.4 admin GET /api/docker/containers 200 50ms\n")
|
|
|
|
response = test_app.get("/api/system/audit-log", headers=admin_headers)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "entries" in data
|
|
assert isinstance(data["entries"], list)
|
|
|
|
|
|
def test_audit_log_classifies_failed_auth(test_app, admin_headers, temp_volume_root):
|
|
"""Test audit log classifies failed auth as high severity"""
|
|
import os
|
|
|
|
audit_path = os.path.join(temp_volume_root, "docker/nas-dashboard/audit.log")
|
|
os.makedirs(os.path.dirname(audit_path), exist_ok=True)
|
|
with open(audit_path, "w") as f:
|
|
f.write("2024-01-01T10:00:00 1.2.3.4 - POST /api/auth/login 401 100ms\n")
|
|
|
|
response = test_app.get("/api/system/audit-log", headers=admin_headers)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
if data["entries"]:
|
|
assert data["entries"][0]["level"] == "high"
|
|
|
|
|
|
def test_send_notification_missing_message(test_app, admin_headers):
|
|
"""Test send notification with missing message"""
|
|
response = test_app.post("/api/system/notify", json={}, headers=admin_headers)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["ok"] is False
|
|
assert "error" in data
|
|
|
|
|
|
def test_openclaw_token_lan_only(test_app, admin_headers):
|
|
"""Test OpenClaw token endpoint requires LAN IP"""
|
|
response = test_app.get("/api/system/openclaw-token", headers=admin_headers)
|
|
assert response.status_code == 403
|