Move history geo enrichment into history service

This commit is contained in:
2026-04-17 16:28:53 +02:00
parent 8c6950afc1
commit 487f252a4d
4 changed files with 109 additions and 50 deletions

View File

@@ -235,6 +235,37 @@ class TestListHistory:
assert len(recent.matches) == 1
assert "Failed password" in recent.matches[0]
async def test_http_session_geo_lookup_is_used(
self, f2b_db_path: str
) -> None:
"""A provided HTTP session is used for geo enrichment by the service."""
fake_session = AsyncMock()
mock_geo = AsyncMock()
mock_geo.country_code = "US"
mock_geo.country_name = "United States"
mock_geo.asn = "AS15169"
mock_geo.org = "Google"
with patch(
"app.services.history_service.get_fail2ban_db_path",
new=AsyncMock(return_value=f2b_db_path),
), patch(
"app.services.history_service.geo_service.lookup",
new=AsyncMock(return_value=mock_geo),
) as mock_lookup:
result = await history_service.list_history(
"fake_socket",
ip_filter="1.2.3.4",
http_session=fake_session,
)
assert mock_lookup.call_args.args == ("1.2.3.4", fake_session)
assert result.items[0].country_code == "US"
assert result.items[0].country_name == "United States"
assert result.items[0].asn == "AS15169"
assert result.items[0].org == "Google"
async def test_null_data_column_handled_gracefully(
self, f2b_db_path: str
) -> None: