Skip to content

Commit cbea4fc

Browse files
committed
test: add assertions to deserialization tests
Add field-level assertions to test_l9event_json_from_reference_repository covering event metadata, HTTP, SSL, service, leak, network, tags, and transport fields. Add structural assertions to test_l9events_from_ip4scout verifying event_source, event_type, ip, and port. Closes #26
1 parent d8ee8ad commit cbea4fc

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

tests/test_l9format.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,56 @@ def test_l9event_json_from_reference_repository():
1616
path = TESTS_DIR / "l9event.json"
1717
with open(path) as f:
1818
c = json.load(f)
19-
L9Event.from_dict(c)
19+
event = L9Event.from_dict(c)
20+
assert event.event_type == "leak"
21+
assert event.event_source == "DotEnvConfigPlugin"
22+
assert event.ip == "127.0.0.1"
23+
assert event.port == "8080"
24+
assert event.host == "site1.example.com"
25+
assert event.reverse == "ptr1.example.com"
26+
assert event.protocol == "https"
27+
assert event.summary == "GET /... qwerqwer"
28+
assert event.http.root == "/site1"
29+
assert event.http.url == "/site1/.env"
30+
assert event.http.status == 200
31+
assert event.http.length == 12423
32+
assert event.http.title == "Apache welcome page"
33+
assert event.ssl.detected is True
34+
assert event.ssl.enabled is True
35+
assert event.ssl.version == "TLSv1.3"
36+
assert event.ssl.certificate.cn == "example.com"
37+
assert event.ssl.certificate.key_algo == "RSA"
38+
assert event.ssl.certificate.key_size == 2048
39+
assert event.service.software.name == "Apache"
40+
assert event.service.software.version == "2.2.4"
41+
assert event.service.credentials.noauth is True
42+
assert event.leak.stage == "open"
43+
assert event.leak.type == "configuration"
44+
assert event.leak.severity == "medium"
45+
assert event.leak.dataset.rows == 4
46+
assert event.leak.dataset.files == 1
47+
assert event.network.asn == 0
48+
assert event.tags == ["plc"]
49+
assert event.transport == ["tcp", "tls", "http"]
50+
assert event.event_pipeline == [
51+
"ip4scout",
52+
"l9tcpid",
53+
"l9explore",
54+
"DotEnvConfigPlugin",
55+
]
2056

2157

2258
def test_l9events_from_ip4scout():
2359
for path in IP4SCOUT_FILES:
2460
with open(path) as f:
2561
c = json.load(f)
26-
L9Event.from_dict(c)
62+
event = L9Event.from_dict(c)
63+
assert event.event_source == "ip4scout"
64+
assert event.event_type == "synack"
65+
assert isinstance(event.ip, str)
66+
assert len(event.ip) > 0
67+
assert isinstance(event.port, str)
68+
assert len(event.port) > 0
2769

2870

2971
def test_iso8601_nanosecond_parsing():

0 commit comments

Comments
 (0)