Move Fail2Ban exceptions into central app.exceptions module
This commit is contained in:
@@ -13,7 +13,7 @@ from app.config import Settings
|
||||
from app.db import init_db
|
||||
from app.main import create_app
|
||||
from app.models.ban import ActiveBan, ActiveBanListResponse
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Fixtures
|
||||
|
||||
@@ -121,7 +121,7 @@ class TestGetJailConfigs:
|
||||
|
||||
async def test_502_on_connection_error(self, config_client: AsyncClient) -> None:
|
||||
"""GET /api/config/jails returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jail_config.config_service.list_jail_configs",
|
||||
@@ -373,7 +373,7 @@ class TestReloadFail2ban:
|
||||
|
||||
async def test_502_when_fail2ban_unreachable(self, config_client: AsyncClient) -> None:
|
||||
"""POST /api/config/reload returns 502 when fail2ban socket is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.config_misc.jail_service.reload_all",
|
||||
@@ -458,7 +458,7 @@ class TestRestartFail2ban:
|
||||
|
||||
async def test_502_when_fail2ban_unreachable(self, config_client: AsyncClient) -> None:
|
||||
"""POST /api/config/restart returns 502 when fail2ban socket is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.config_misc.jail_service.restart",
|
||||
@@ -1965,7 +1965,7 @@ class TestGetFail2BanLog:
|
||||
|
||||
async def test_502_when_fail2ban_unreachable(self, config_client: AsyncClient) -> None:
|
||||
"""GET /api/config/fail2ban-log returns 502 when fail2ban is down."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.config_misc.config_service.read_fail2ban_log",
|
||||
|
||||
@@ -423,7 +423,7 @@ class TestIgnoreIpEndpoints:
|
||||
|
||||
async def test_get_ignore_list_502_on_connection_error(self, jails_client: AsyncClient) -> None:
|
||||
"""GET /api/jails/sshd/ignoreip returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.get_ignore_list",
|
||||
@@ -465,7 +465,7 @@ class TestIgnoreIpEndpoints:
|
||||
|
||||
async def test_add_ignore_ip_502_on_connection_error(self, jails_client: AsyncClient) -> None:
|
||||
"""POST /api/jails/sshd/ignoreip returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.add_ignore_ip",
|
||||
@@ -512,7 +512,7 @@ class TestIgnoreIpEndpoints:
|
||||
|
||||
async def test_delete_ignore_ip_502_on_connection_error(self, jails_client: AsyncClient) -> None:
|
||||
"""DELETE /api/jails/sshd/ignoreip returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.del_ignore_ip",
|
||||
@@ -599,7 +599,7 @@ class TestToggleIgnoreSelf:
|
||||
|
||||
async def test_502_on_connection_error(self, jails_client: AsyncClient) -> None:
|
||||
"""POST /api/jails/sshd/ignoreself returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.set_ignore_self",
|
||||
@@ -624,7 +624,7 @@ class TestFail2BanConnectionErrors:
|
||||
|
||||
async def test_get_jails_502(self, jails_client: AsyncClient) -> None:
|
||||
"""GET /api/jails returns 502 when fail2ban socket is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.list_jails",
|
||||
@@ -636,7 +636,7 @@ class TestFail2BanConnectionErrors:
|
||||
|
||||
async def test_get_jail_502(self, jails_client: AsyncClient) -> None:
|
||||
"""GET /api/jails/sshd returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.get_jail",
|
||||
@@ -660,7 +660,7 @@ class TestFail2BanConnectionErrors:
|
||||
|
||||
async def test_reload_all_502(self, jails_client: AsyncClient) -> None:
|
||||
"""POST /api/jails/reload-all returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.reload_all",
|
||||
@@ -672,7 +672,7 @@ class TestFail2BanConnectionErrors:
|
||||
|
||||
async def test_start_jail_502(self, jails_client: AsyncClient) -> None:
|
||||
"""POST /api/jails/sshd/start returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.start_jail",
|
||||
@@ -696,7 +696,7 @@ class TestFail2BanConnectionErrors:
|
||||
|
||||
async def test_stop_jail_502(self, jails_client: AsyncClient) -> None:
|
||||
"""POST /api/jails/sshd/stop returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.stop_jail",
|
||||
@@ -740,7 +740,7 @@ class TestFail2BanConnectionErrors:
|
||||
|
||||
async def test_toggle_idle_502(self, jails_client: AsyncClient) -> None:
|
||||
"""POST /api/jails/sshd/idle returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.set_idle",
|
||||
@@ -780,7 +780,7 @@ class TestFail2BanConnectionErrors:
|
||||
|
||||
async def test_reload_jail_502(self, jails_client: AsyncClient) -> None:
|
||||
"""POST /api/jails/sshd/reload returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.reload_jail",
|
||||
@@ -894,7 +894,7 @@ class TestGetJailBannedIps:
|
||||
|
||||
async def test_502_when_fail2ban_unreachable(self, jails_client: AsyncClient) -> None:
|
||||
"""GET /api/jails/sshd/banned returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.jails.jail_service.get_jail_banned_ips",
|
||||
|
||||
@@ -106,7 +106,7 @@ class TestGetServerSettings:
|
||||
|
||||
async def test_502_on_connection_error(self, server_client: AsyncClient) -> None:
|
||||
"""GET /api/server/settings returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.server.server_service.get_settings",
|
||||
@@ -163,7 +163,7 @@ class TestUpdateServerSettings:
|
||||
|
||||
async def test_502_on_connection_error(self, server_client: AsyncClient) -> None:
|
||||
"""PUT /api/server/settings returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.server.server_service.update_settings",
|
||||
@@ -218,7 +218,7 @@ class TestFlushLogs:
|
||||
|
||||
async def test_502_on_connection_error(self, server_client: AsyncClient) -> None:
|
||||
"""POST /api/server/flush-logs returns 502 when fail2ban is unreachable."""
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
with patch(
|
||||
"app.routers.server.server_service.flush_logs",
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from app.services.fail2ban_metadata_service import Fail2BanMetadataService
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
|
||||
async def test_get_db_path_caches_result() -> None:
|
||||
|
||||
@@ -9,7 +9,7 @@ import pytest
|
||||
|
||||
from app.models.server import ServerStatus
|
||||
from app.services import health_service
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError, Fail2BanProtocolError
|
||||
from app.exceptions import Fail2BanConnectionError, Fail2BanProtocolError
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers
|
||||
|
||||
@@ -13,7 +13,7 @@ from app.models.geo import GeoDetail, GeoInfo
|
||||
from app.models.jail import JailDetailResponse, JailListResponse
|
||||
from app.services import jail_service
|
||||
from app.services.jail_service import JailNotFoundError, JailOperationError
|
||||
from app.utils.fail2ban_client import Fail2BanConnectionError
|
||||
from app.exceptions import Fail2BanConnectionError
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers
|
||||
|
||||
Reference in New Issue
Block a user