Repository: google/GiftStick

Issue:
Try to upload the "disk list" artifact before failing if no disk is detected 
In https://github.com/google/GiftStick/blob/main/auto_forensicate/recipes/disk.py we raise if no "acquire-able" disk is detected, before trying to upload the list of all disks

Discussion:

Patch:
diff --git a/auto_forensicate/recipes/disk.py b/auto_forensicate/recipes/disk.py
index 1e09f3f..79d47e4 100644
--- a/auto_forensicate/recipes/disk.py
+++ b/auto_forensicate/recipes/disk.py
@@ -133,7 +133,9 @@ class DiskArtifact(base.BaseArtifact):
     code = self._ddprocess.returncode
     error = self._ddprocess.stderr.read()
     if code > 0:
-      raise errors.RecipeException('Command dcfldd returned non-zero exit status {0:d}, with error: "{1:s}"'.format(code, error.decode()))
+      raise errors.RecipeException(
+          'Command dcfldd returned non-zero exit status {0:d}, '
+          'with error: "{1:s}"'.format(code, error.decode()))
     return error
 
   def GetDescription(self):
@@ -142,7 +144,7 @@ class DiskArtifact(base.BaseArtifact):
     Returns:
       str: the description
     """
-    return 'Name: {0:s} (Size: {1:d})'.format(self.name, self.size)
+    description = 'Name: {0:s} (Size: {1:d})'.format(self.name, self.size)
     if self.mounted:
       description = '(WARNING: disk has a mounted partition) ' + description
     return description
@@ -281,7 +283,7 @@ class DiskRecipe(base.BaseRecipe):
   """
 
   def __init__(self, name, options=None):
-    """TODO"""
+    """Class for a disks acquisition Recipe"""
     self.use_dcfldd = True
     super().__init__(name, options=options)
 
@@ -306,7 +308,9 @@ class DiskRecipe(base.BaseRecipe):
     for mac_disk in macdisk.WholeDisks():
       disk_name = mac_disk.deviceidentifier
       disk_size = mac_disk.totalsize
-      disk = MacDiskArtifact(os.path.join('/dev', disk_name), disk_size, use_dcfldd=self.use_dcfldd)
+      disk = MacDiskArtifact(
+          os.path.join('/dev', disk_name), disk_size,
+          use_dcfldd=self.use_dcfldd)
       disk_list.append(disk)
     return disk_list
 
@@ -352,8 +356,7 @@ class DiskRecipe(base.BaseRecipe):
     return disk_list
 
   def _ListDisks(self, all_devices=False, names=None):
-    """Between all disks connected to the machine, selects the one we want to
-    acquire.
+    """Builds a list of DiskArtifact object to acquire.
 
     Args:
       all_devices(bool): whether to also list devices that aren't internal to
@@ -395,8 +398,7 @@ class DiskRecipe(base.BaseRecipe):
     return lsblk_artifact
 
   def _GetDiskInfoArtifact(self, disk):
-    """Returns an StringArtifact containing information about a disk being
-    copied.
+    """Returns an StringArtifact containing info about a disk being copied.
 
     Args:
       disk(DiskArtifact): the disk object to get info from.
@@ -443,13 +445,12 @@ class DiskRecipe(base.BaseRecipe):
     else:
       disks_to_collect = self._ListDisks()
 
-
-    if not disks_to_collect:
-      raise errors.RecipeException('No disk to collect')
-
     disk_list_artifact = self._GetListDisksArtifact()
     artifacts.append(disk_list_artifact)
 
+    if not disks_to_collect:
+      self._logger.warn('No disk to collect')
+
     for disk in disks_to_collect:
 
       disk_info_artifact = self._GetDiskInfoArtifact(disk)


Test patch:
diff --git a/tests/disk_tests.py b/tests/disk_tests.py
index 2e1acd0..ad5d274 100644
--- a/tests/disk_tests.py
+++ b/tests/disk_tests.py
@@ -199,8 +199,11 @@ class DiskRecipeTests(unittest.TestCase):
       patched_listdisk.return_value = []
       recipe = disk.DiskRecipe('Disk')
       recipe._platform = 'linux'
-      with self.assertRaises(errors.RecipeException):
-        recipe.GetArtifacts()
+      artifacts = recipe.GetArtifacts()
+      self.assertEqual(len(artifacts), 1)
+
+      artifact = artifacts[0]
+      self.assertEqual(artifact.name, 'lsblk.txt')
 
   def testGetArtifacts(self):
     disk_name = 'sdx'