Build Flask WAF log converter app
This commit is contained in:
30
tests/test_parser.py
Normal file
30
tests/test_parser.py
Normal 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)
|
||||
Reference in New Issue
Block a user