/
azathd
/
mutiagent
Обзор
Документация
Войти
/
azathd
/
mutiagent
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/unit/test_parser.py
53 строки
2 KB
Your Name
init
15 май 2026, 18:54
15 май 2026, 18:54
07c4701
Код
Авторство
О чём код?
"""Parser fixtures (text + JSON + Marzban).""" from __future__ import annotations from src.agents.collector.parser import detect_format, parse_line MARZBAN_ACCESS = [ "2026/05/15 13:50:47.097116 from 84.18.116.71:58873 accepted tcp:8.8.8.8:853 [VLESS + WS >> DIRECT] email: 23.u5006909607", "2026/05/15 13:50:47.112471 from 84.18.116.71:59112 accepted udp:8.8.8.8:53 [VLESS + WS >> DIRECT] email: 23.u5006909607", "2026/05/15 13:50:47.123820 from 87.117.189.37:45994 accepted udp:1.1.1.1:53 [VLESS + WS >> DIRECT] email: 9.u1753584712", ] MARZBAN_ERROR = [ "2026/05/15 13:50:46.922402 [Info] transport/internet/splithttp: listening TCP for XHTTP on 0.0.0.0:3443", "2026/05/15 13:50:46.922432 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:37113", ] TEXT_SAMPLES = [ "2024/05/01 10:00:00 from 8.8.8.8:12345 accepted tcp:example.com:443 [inbound -> proxy] email: user@example.com", ] JSON_SAMPLES = [ '{"timestamp":1714550400,"email":"bob@test.com","sourceIP":"8.8.4.4","dest":"cdn.example.com","port":443}', ] def test_marzban_access_lines() -> None: for line in MARZBAN_ACCESS: ev = parse_line(line) assert ev is not None, line assert ev.user_email assert ev.source_ip assert ev.inbound_tag and "VLESS" in ev.inbound_tag assert ev.outbound_tag == "DIRECT" def test_marzban_error_lines() -> None: for line in MARZBAN_ERROR: ev = parse_line(line, log_type="error") assert ev is not None assert ev.log_type == "error" def test_detect_format() -> None: assert detect_format('{"a":1}') == "json" assert detect_format("2024/01/01") == "text" def test_parse_legacy_text() -> None: for line in TEXT_SAMPLES: ev = parse_line(line) assert ev is not None assert ev.user_email