From 9f8fca85a6ecd454df0dbb1e59bc2dcb43adeaae Mon Sep 17 00:00:00 2001 From: Joakim Loxdal Date: Mon, 23 Sep 2024 14:42:44 +0200 Subject: [PATCH] Make sure attackers are attacked in deepcopy test --- tests/attackgraph/test_attackgraph.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/attackgraph/test_attackgraph.py b/tests/attackgraph/test_attackgraph.py index 65976f2..bc31fc1 100644 --- a/tests/attackgraph/test_attackgraph.py +++ b/tests/attackgraph/test_attackgraph.py @@ -14,6 +14,7 @@ @pytest.fixture def example_attackgraph(corelang_lang_graph: LanguageGraph, model: Model): """Fixture that generates an example attack graph + with unattached attacker Uses coreLang specification and model with two applications with an association and an attacker to create and return @@ -412,6 +413,7 @@ def test_attackgraph_deepcopy(example_attackgraph: AttackGraph): and attackers should be duplicated into new objects, while references to the instance model should remain the same. """ + example_attackgraph.attach_attackers() copied_attackgraph: AttackGraph = copy.deepcopy(example_attackgraph) assert copied_attackgraph != example_attackgraph @@ -433,6 +435,8 @@ def test_attackgraph_deepcopy(example_attackgraph: AttackGraph): assert id(copied_attackgraph.model) == id(example_attackgraph.model) + assert len(copied_attackgraph.nodes) \ + == len(example_attackgraph.nodes) for node in copied_attackgraph.nodes: assert node.id is not None original_node = example_attackgraph.get_node_by_id(node.id) @@ -441,6 +445,11 @@ def test_attackgraph_deepcopy(example_attackgraph: AttackGraph): assert original_node.to_dict() == node.to_dict() assert id(original_node.asset) == id(node.asset) + assert len(copied_attackgraph.attackers) \ + == len(example_attackgraph.attackers) + assert id(copied_attackgraph.attackers) \ + != id(example_attackgraph.attach_attackers) + for attacker in copied_attackgraph.attackers: assert attacker.id is not None original_attacker = example_attackgraph.get_attacker_by_id(attacker.id)