feat(auto-ban): add immediate unban and list_bans to AutoBanService #328
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/BUNYIP-318-autoban-unban-list"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds AutoBanService::unban(ip), which lifts a still-valid ban in one call by removing the IP from the in-memory
bannedmap (the map the request path checks in is_banned), clearing any accumulated strikes, and deleting the persisted ip_bans row so the ban does not reappear on the next restart. The in-memory removals run before the awaited DELETE, so the enforcement effect holds even if the database delete errors; the error is then propagated. It returns whether a ban was actually present (in memory or in the ip_bans table).Adds AutoBanService::list_bans(), which merges the persisted ip_bans rows (source of strikes and banned_at) with the in-memory map (authoritative for enforcement) and returns the active bans as BanInfo { ip, reason, strikes, banned_at, expires_at } for reuse by the admin API in BUNYIP-319. IpBanRow and the load_active_bans SELECT are extended with the strikes and banned_at columns to carry the full metadata; BanInfo is re-exported from the middleware module.
Tests: in-memory tests prove is_banned returns false after unban and that strikes reset; DB-gated tests (skipped when DATABASE_URL is unset, per the repo convention) prove unban returns presence and deletes the row, and that list_bans surfaces a persisted ban with its reason and strikes.
#BUNYIP-318
Adds AutoBanService::unban(ip), which lifts a still-valid ban in one call by removing the IP from the in-memory `banned` map (the map the request path checks in is_banned), clearing any accumulated strikes, and deleting the persisted ip_bans row so the ban does not reappear on the next restart. The in-memory removals run before the awaited DELETE, so the enforcement effect holds even if the database delete errors; the error is then propagated. It returns whether a ban was actually present (in memory or in the ip_bans table). Adds AutoBanService::list_bans(), which merges the persisted ip_bans rows (source of strikes and banned_at) with the in-memory map (authoritative for enforcement) and returns the active bans as BanInfo { ip, reason, strikes, banned_at, expires_at } for reuse by the admin API in BUNYIP-319. IpBanRow and the load_active_bans SELECT are extended with the strikes and banned_at columns to carry the full metadata; BanInfo is re-exported from the middleware module. Tests: in-memory tests prove is_banned returns false after unban and that strikes reset; DB-gated tests (skipped when DATABASE_URL is unset, per the repo convention) prove unban returns presence and deletes the row, and that list_bans surfaces a persisted ban with its reason and strikes. #BUNYIP-318