-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test where we make sure rewards are applied as defined in scena…
…rio file
- Loading branch information
1 parent
d22c344
commit 5a50b9c
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |