Skip to content

Commit

Permalink
Start of test expansion for arg validation per recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ramo-j committed Jul 22, 2024
1 parent 1b17976 commit 611446f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion data/recipes/aws_forensics.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "aws_forensics",
"short_description": "Copies a volume from an AWS account to an analysis VM.",
"description": "Copies a volume from an AWS account, creates an analysis VM in AWS (with a startup script containing installation instructions for basic forensics tooling), and attaches the copied volume to it.",
"test_params": "default us-east-1 incident_id --instance_id i-01234567 --volume_ids vol-01234567",
"modules": [{
"wants": [],
"name": "AWSCollector",
Expand All @@ -26,7 +27,7 @@
["--instance_id", "Instance ID of the instance to analyze.", null, {"format": "regex", "comma_separated": false, "regex": "^i-[0-9a-f]{8,17}$"}],
["--volume_ids", "Comma-separated list of volume IDs to copy.", null, {"format": "regex", "comma_separated": true, "regex": "^vol-[0-9a-f]{8,17}$"}],
["--all_volumes", "Copy all volumes in the designated instance. Overrides volume_ids if specified.", false],
["--boot_volume_size", "The size of the analysis VM boot volume (in GB).", 50, {"format": "regex", "regex": "^\\d+$"}],
["--boot_volume_size", "The size of the analysis VM boot volume (in GB).", "50", {"format": "regex", "regex": "^\\d+$"}],
["--analysis_zone", "The AWS zone in which to create the VM.", null, {"format": "aws_region"}],
["--analysis_profile_name", "Name of the AWS profile to use when creating the analysis VM.", null]
]
Expand Down
3 changes: 3 additions & 0 deletions dftimewolf/lib/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ def GetHelpString(self) -> str:
short_description = self.contents.get(
'short_description', 'No description')
return ' {0:<35s}{1:s}\n'.format(self.name, short_description)

def GetTestParams(self) -> list[str]:
return self.contents.get('test_params', '').split(' ')
7 changes: 6 additions & 1 deletion tests/cli/main_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _EnumerateRecipeNames():
tool = _CreateToolObject()
# pylint: disable=protected-access
for recipe in tool._recipes_manager.GetRecipes():
yield (recipe.name, recipe.name)
yield (f'_{recipe.name}', recipe.name)


class MainToolTest(parameterized.TestCase):
Expand Down Expand Up @@ -140,6 +140,9 @@ def _testRecipeValidators(self, recipe_name):
self.tool._state = dftw_state.DFTimewolfState(config.Config)
recipe = self.tool._recipes_manager.Recipes()[recipe_name]

recipe_args = [recipe_name] + recipe.GetTestParams()
self.tool.ParseArguments(recipe_args)

self.tool._state.LoadRecipe(recipe.contents, dftimewolf_recipes.MODULES)
for arg in recipe.args:
if arg.validation_params:
Expand All @@ -148,6 +151,8 @@ def _testRecipeValidators(self, recipe_name):
validators_manager.ValidatorsManager.ListValidators(),
f'Error in {recipe.name}:{arg.switch} - '
f'Invalid validator {arg.validation_params["format"]}.')

self.tool.ValidateArguments()

def testRecipeWithNestedArgs(self):
"""Tests that a recipe with args referenced in other args is populated."""
Expand Down

0 comments on commit 611446f

Please sign in to comment.