fix(logging): resolve logging_compat keyword arg conflicts

- Fix logging_compat._log() to handle extra keyword arguments properly
- Update config.py, main.py, and test_bans.py for compatibility
- Update Tasks.md and runner.csx
This commit is contained in:
2026-05-10 15:54:00 +02:00
parent 7ec80fdeec
commit 96ce516ecf
6 changed files with 40 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
from __future__ import annotations
from collections.abc import AsyncGenerator
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch
@@ -20,8 +21,7 @@ from app.exceptions import Fail2BanConnectionError
# ---------------------------------------------------------------------------
_SETUP_PAYLOAD = {
"master_password": "testpassword1",
"database_path": "bangui.db",
"master_password": "Testpass1!",
"fail2ban_socket": "/var/run/fail2ban/fail2ban.sock",
"timezone": "UTC",
"session_duration_minutes": 60,
@@ -31,13 +31,16 @@ _SETUP_PAYLOAD = {
@pytest.fixture
async def bans_client(tmp_path: Path) -> AsyncClient: # type: ignore[misc]
"""Provide an authenticated ``AsyncClient`` for bans endpoint tests."""
(tmp_path / "fail2ban").mkdir()
settings = Settings(
database_path=str(tmp_path / "bans_test.db"),
fail2ban_socket="/tmp/fake.sock",
session_secret="test-bans-secret",
session_secret="test-bans-secret-that-is-at-least-32-chars",
session_duration_minutes=60,
timezone="UTC",
log_level="debug",
fail2ban_config_dir=str(tmp_path / "fail2ban"),
session_cache_enabled=False,
)
app = create_app(settings=settings)
@@ -47,6 +50,12 @@ async def bans_client(tmp_path: Path) -> AsyncClient: # type: ignore[misc]
app.state.db = db
app.state.http_session = MagicMock()
async def _override_get_db() -> AsyncGenerator[aiosqlite.Connection, None]:
yield db
from app.dependencies import get_db
app.dependency_overrides[get_db] = _override_get_db
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
await ac.post("/api/v1/setup", json=_SETUP_PAYLOAD)
@@ -58,6 +67,7 @@ async def bans_client(tmp_path: Path) -> AsyncClient: # type: ignore[misc]
yield ac
await db.close()
app.dependency_overrides.clear()
# ---------------------------------------------------------------------------
@@ -95,8 +105,19 @@ class TestGetActiveBans:
assert data["bans"][0]["ip"] == "1.2.3.4"
assert data["bans"][0]["jail"] == "sshd"
async def test_401_when_unauthenticated(self, bans_client: AsyncClient) -> None:
async def test_401_when_unauthenticated(
self, bans_client: AsyncClient, monkeypatch: pytest.MonkeyPatch
) -> None:
"""GET /api/bans/active returns 401 without session."""
import logging
from unittest.mock import MagicMock
class FakeLogger:
def error(self, *args, **kwargs): pass
def warning(self, *args, **kwargs): pass
def info(self, *args, **kwargs): pass
monkeypatch.setattr("app.main.log", FakeLogger())
resp = await AsyncClient(
transport=ASGITransport(app=bans_client._transport.app), # type: ignore[attr-defined]
base_url="http://test",