def testGetArtifactsZeroDisk(self): with mock.patch('auto_forensicate.recipes.disk.DiskRecipe._ListDisks' ) as patched_listdisk: patched_listdisk.return_value = [] recipe = disk.DiskRecipe('Disk') with self.assertRaises(errors.RecipeException): recipe.GetArtifacts()
def testListAllDisks(self): recipe = disk.DiskRecipe('Disk') disk.DiskRecipe._GetLsblkDict = self._GetLsblkDictThreeDisks disk_list = recipe._ListDisks(all_devices=True) self.assertEqual(len(disk_list), 3) self.assertGreaterEqual(disk_list[0].size, disk_list[1].size) self.assertEqual(disk_list[0].size, 512110190592) self.assertEqual(disk_list[1].size, 502110190592) self.assertEqual(disk_list[2].size, 3000041824)
def testListDisksWithNames(self): recipe = disk.DiskRecipe('Disk') recipe._platform = 'linux' disk.DiskRecipe._GetLsblkDict = self._GetLsblkDictThreeDisks disk_list = recipe._ListDisks(all_devices=True, names=['sdz_not_present']) self.assertEqual(len(disk_list), 0) disk_list = recipe._ListDisks(all_devices=True, names=['usb0', 'sdy']) self.assertEqual(len(disk_list), 2) self.assertEqual(disk_list[0].name, 'sdy') self.assertEqual(disk_list[1].name, 'usb0')
def testGetArtifacts(self): disk_name = 'sdx' disk_size = 20 * 1024 * 1024 * 1024 # 20GB disk_object = disk.DiskArtifact('/dev/{0:s}'.format(disk_name), disk_size) disk_object._udevadm_metadata = { 'udevadm_text_output': 'fake disk info' } with mock.patch('auto_forensicate.recipes.disk.DiskRecipe._ListDisks' ) as patched_listdisk: patched_listdisk.return_value = [disk_object] with mock.patch( 'auto_forensicate.recipes.disk.DiskRecipe._GetLsblkDict' ) as patched_lsblk: patched_lsblk.return_value = self._lsblk_dict recipe = disk.DiskRecipe('Disk') artifacts = recipe.GetArtifacts() self.assertEqual(len(artifacts), 4) udevadm_artifact = artifacts[0] self.assertIsInstance(udevadm_artifact, base.StringArtifact) self.assertEqual(udevadm_artifact._GetStream().read(), b'fake disk info') self.assertEqual(udevadm_artifact.remote_path, 'Disks/sdx.udevadm.txt') lsblk_artifact = artifacts[1] self.assertIsInstance(lsblk_artifact, base.StringArtifact) self.assertEqual(lsblk_artifact._GetStream().read(), json.dumps(self._lsblk_dict).encode('utf-8')) self.assertEqual(lsblk_artifact.remote_path, 'Disks/lsblk.txt') self.assertEqual(artifacts[2], disk_object) file_artifact = artifacts[3] self.assertIsInstance(file_artifact, base.FileArtifact) self.assertEqual(file_artifact.name, '{0:s}.hash'.format(disk_name)) self.assertEqual(file_artifact.remote_path, 'Disks/{0:s}.hash'.format(disk_name))
def testListDisksZero(self): recipe = disk.DiskRecipe('Disk') recipe._platform = 'linux' disk.DiskRecipe._GetLsblkDict = self._GetLsblkDictZeroDisks self.assertEqual(0, len(recipe._ListDisks()))