Add mass unban: DELETE /api/bans/all clears all active bans
- Send fail2ban's `unban --all` command via new `unban_all_ips()` service function; returns the count of unbanned IPs - Add `UnbanAllResponse` Pydantic model (message + count) - Add `DELETE /api/bans/all` router endpoint; handles 502 on socket error - Frontend: `bansAll` endpoint constant, `unbanAllBans()` API call, `UnbanAllResponse` type, `unbanAll` action in `useActiveBans` hook - JailsPage: "Clear All Bans" button (visible when bans > 0) with a Fluent UI confirmation Dialog before executing the operation - 7 new tests (3 service, 4 router); 440 total pass, 82% coverage
This commit is contained in:
@@ -554,3 +554,38 @@ class TestLookupIp:
|
||||
result = await jail_service.lookup_ip(_SOCKET, "9.9.9.9")
|
||||
|
||||
assert result["currently_banned_in"] == []
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# unban_all_ips
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestUnbanAllIps:
|
||||
"""Tests for :func:`~app.services.jail_service.unban_all_ips`."""
|
||||
|
||||
async def test_unban_all_ips_returns_count(self) -> None:
|
||||
"""unban_all_ips returns the integer count from fail2ban."""
|
||||
responses = {"unban|--all": (0, 5)}
|
||||
with _patch_client(responses):
|
||||
count = await jail_service.unban_all_ips(_SOCKET)
|
||||
|
||||
assert count == 5
|
||||
|
||||
async def test_unban_all_ips_returns_zero_when_none_banned(self) -> None:
|
||||
"""unban_all_ips returns 0 when no IPs are currently banned."""
|
||||
responses = {"unban|--all": (0, 0)}
|
||||
with _patch_client(responses):
|
||||
count = await jail_service.unban_all_ips(_SOCKET)
|
||||
|
||||
assert count == 0
|
||||
|
||||
async def test_unban_all_ips_raises_on_connection_error(self) -> None:
|
||||
"""unban_all_ips propagates Fail2BanConnectionError."""
|
||||
with patch(
|
||||
"app.services.jail_service.Fail2BanClient",
|
||||
side_effect=Fail2BanConnectionError("unreachable", _SOCKET),
|
||||
):
|
||||
with pytest.raises(Fail2BanConnectionError):
|
||||
await jail_service.unban_all_ips(_SOCKET)
|
||||
|
||||
Reference in New Issue
Block a user