Skip to content

Commit

Permalink
Make sure attackers are attacked in deepcopy test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkickling committed Sep 23, 2024
1 parent 4fd333e commit 9f8fca8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/attackgraph/test_attackgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 9f8fca8

Please sign in to comment.