Build Flask WAF log converter app

This commit is contained in:
Alfredo Di Stasio
2026-04-24 14:40:32 +02:00
parent f9579bd253
commit 355d61f11f
23 changed files with 1053 additions and 1 deletions

30
tests/test_parser.py Normal file
View File

@@ -0,0 +1,30 @@
import io
import pytest
from app.services.parser import LogParseError, parse_log_file
def test_parse_log_file_supports_shell_style_quotes():
stream = io.BytesIO(
b'v015xxxxdate=2024-02-15 time=09:10:11 policy="Strict Policy" msg="blocked request"\n'
)
records, union_keys = parse_log_file(stream)
assert records == [
{
"v015xxxxdate": "2024-02-15",
"time": "09:10:11",
"policy": "Strict Policy",
"msg": "blocked request",
}
]
assert union_keys == ["v015xxxxdate", "time", "policy", "msg"]
def test_parse_log_file_rejects_tokens_without_equals():
stream = io.BytesIO(b"v015xxxxdate=2024-02-15 broken-token\n")
with pytest.raises(LogParseError):
parse_log_file(stream)