Skip to content

Commit

Permalink
Add a test where we make sure rewards are applied as defined in scena…
Browse files Browse the repository at this point in the history
…rio file
  • Loading branch information
mrkickling committed Jun 18, 2024
1 parent d22c344 commit 5a50b9c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Test functions that load scenarios"""

import os
from malsim.loader import load_scenario


def path_relative_to_tests(filename):
"""Returns the absolute path of a file in ./tests
Arguments:
filename - filename to append to tests path
"""
current_dir = os.path.dirname(os.path.realpath(__file__))
return os.path.join(current_dir, f"{filename}")


def test_load_scenario():
"""Make sure we can load a scenario"""

# Load the scenario
attack_graph = load_scenario(
path_relative_to_tests('./testdata/simple_scenario.yml')
)

# Verify rewards were added as defined in './testdata/simple_scenario.yml'
assert attack_graph.get_node_by_id('OS App:notPresent')\
.reward == 2
assert attack_graph.get_node_by_id('OS App:supplyChainAuditing')\
.reward == 7
assert attack_graph.get_node_by_id('Program 1:notPresent')\
.reward == 3
assert attack_graph.get_node_by_id('Program 1:supplyChainAuditing')\
.reward == 7
assert attack_graph.get_node_by_id('SoftwareVulnerability:4:notPresent')\
.reward == 4
assert attack_graph.get_node_by_id('Data:5:notPresent')\
.reward == 1
assert attack_graph.get_node_by_id('Credentials:6:notPhishable')\
.reward == 7
assert attack_graph.get_node_by_id('Identity:11:notPresent')\
.reward == 3.5

0 comments on commit 5a50b9c

Please sign in to comment.