From 46ebd578b77a1daaf9dd878d818d5d935319a9c3 Mon Sep 17 00:00:00 2001 From: TheTechromancer Date: Fri, 3 Nov 2023 14:21:50 -0400 Subject: [PATCH] fixed resolved_hosts with reserialized events --- bbot/core/event/base.py | 4 ++++ bbot/test/test_step_1/test_events.py | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bbot/core/event/base.py b/bbot/core/event/base.py index c24601fef..cffce05a3 100644 --- a/bbot/core/event/base.py +++ b/bbot/core/event/base.py @@ -1315,6 +1315,10 @@ def event_from_json(j): "dummy": True, } event = make_event(**kwargs) + + resolved_hosts = j.get("resolved_hosts", []) + event._resolved_hosts = set(resolved_hosts) + event.timestamp = datetime.fromtimestamp(j["timestamp"]) event.scope_distance = j["scope_distance"] source_id = j.get("source", None) diff --git a/bbot/test/test_step_1/test_events.py b/bbot/test/test_step_1/test_events.py index 842b91f9c..ecb0e355e 100644 --- a/bbot/test/test_step_1/test_events.py +++ b/bbot/test/test_step_1/test_events.py @@ -337,19 +337,21 @@ async def test_events(events, scan, helpers, bbot_config): # test event serialization from bbot.core.event import event_from_json - db_event = scan.make_event("127.0.0.1", dummy=True) + db_event = scan.make_event("evilcorp.com", dummy=True) + db_event._resolved_hosts = {"127.0.0.1"} db_event.scope_distance = 1 timestamp = db_event.timestamp.timestamp() json_event = db_event.json() assert json_event["scope_distance"] == 1 - assert json_event["data"] == "127.0.0.1" - assert json_event["type"] == "IP_ADDRESS" + assert json_event["data"] == "evilcorp.com" + assert json_event["type"] == "DNS_NAME" assert json_event["timestamp"] == timestamp reconstituted_event = event_from_json(json_event) assert reconstituted_event.scope_distance == 1 assert reconstituted_event.timestamp.timestamp() == timestamp - assert reconstituted_event.data == "127.0.0.1" - assert reconstituted_event.type == "IP_ADDRESS" + assert reconstituted_event.data == "evilcorp.com" + assert reconstituted_event.type == "DNS_NAME" + assert "127.0.0.1" in reconstituted_event.resolved_hosts http_response = scan.make_event(httpx_response, "HTTP_RESPONSE", source=scan.root_event) assert http_response.source_id == scan.root_event.id