Skip to content

Commit cae5238

Browse files
authored
Merge pull request #42 from LeakIX/add-test-assertions
Add assertions to deserialization tests
2 parents d8ee8ad + 2128635 commit cae5238

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to
1010

1111
### Added
1212

13+
- Add field-level assertions to deserialization tests ([cbea4fc], [#26])
1314
- Add 34 edge-case and validation tests covering missing fields, null values,
1415
empty strings, boundary integers, malformed datetimes/decimals, and nested
1516
validation ([1ca6e4d], [#33])
@@ -152,6 +153,7 @@ and this project adheres to
152153
<!-- Commit links -->
153154

154155
[b66a6f5]: https://github.com/LeakIX/l9format-python/commit/b66a6f5
156+
[cbea4fc]: https://github.com/LeakIX/l9format-python/commit/cbea4fc
155157
[3547e22]: https://github.com/LeakIX/l9format-python/commit/3547e22
156158
[1ca6e4d]: https://github.com/LeakIX/l9format-python/commit/1ca6e4d
157159
[0d8736e]: https://github.com/LeakIX/l9format-python/commit/0d8736e
@@ -218,6 +220,7 @@ and this project adheres to
218220
[#18]: https://github.com/LeakIX/l9format-python/pull/18
219221
[#21]: https://github.com/LeakIX/l9format-python/issues/21
220222
[#22]: https://github.com/LeakIX/l9format-python/issues/22
223+
[#26]: https://github.com/LeakIX/l9format-python/issues/26
221224
[#27]: https://github.com/LeakIX/l9format-python/issues/27
222225
[#33]: https://github.com/LeakIX/l9format-python/issues/33
223226
[#25]: https://github.com/LeakIX/l9format-python/issues/25

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)