def testReadUnicode(self): """Tests the Read function on a unicode string.""" file_object = io.StringIO(self._TEST_STRING_DATA) input_reader = tools.FileObjectInputReader(file_object) string = input_reader.Read() self.assertEqual(string, 'A first string\n') string = input_reader.Read() self.assertEqual(string, 'A 2nd string\n') string = input_reader.Read() self.assertEqual(string, 'þriðja string\n')
def testReadUTF8(self): """Tests the Read function with UTF-8 encoding.""" file_object = io.BytesIO(self._TEST_DATA) input_reader = tools.FileObjectInputReader(file_object) string = input_reader.Read() self.assertEqual(string, 'A first string\n') string = input_reader.Read() self.assertEqual(string, 'A 2nd string\n') # UTF-8 string with non-ASCII characters. string = input_reader.Read() self.assertEqual(string, 'þriðja string\n') # UTF-16 string with non-ASCII characters. string = input_reader.Read() expected_string = ( '\ufffd\ufffdf\x00j\x00\ufffd\x00r\x00\ufffd\x00a\x00 ' '\x00b\x00a\x00n\x00d\x00') self.assertEqual(string, expected_string)
def testPromptUserForVSSStoreIdentifiers(self): """Tests the _PromptUserForVSSStoreIdentifiers function.""" test_path = self._GetTestFilePath(['vsstest.qcow2']) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=test_path) test_qcow_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_QCOW, parent=test_os_path_spec) test_vss_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_VSHADOW, parent=test_qcow_path_spec) volume_system = vshadow_volume_system.VShadowVolumeSystem() volume_system.Open(test_vss_path_spec) file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(file_object) test_tool = storage_media_tool.StorageMediaTool( output_writer=test_output_writer) # Test selection of single store. input_file_object = io.BytesIO(b'2\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForVSSStoreIdentifiers( volume_system, ['vss1', 'vss2']) self.assertEqual(volume_identifiers, ['vss2']) # Test selection of single store. input_file_object = io.BytesIO(b'vss2\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForVSSStoreIdentifiers( volume_system, ['vss1', 'vss2']) self.assertEqual(volume_identifiers, ['vss2']) # Test selection of single store with invalid input on first attempt. input_file_object = io.BytesIO(b'bogus\nvss2\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForVSSStoreIdentifiers( volume_system, ['vss1', 'vss2']) self.assertEqual(volume_identifiers, ['vss2']) # Test selection of all stores. input_file_object = io.BytesIO(b'all\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForVSSStoreIdentifiers( volume_system, ['vss1', 'vss2']) self.assertEqual(volume_identifiers, ['vss1', 'vss2']) # Test selection of no stores. input_file_object = io.BytesIO(b'\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForVSSStoreIdentifiers( volume_system, ['vss1', 'vss2']) self.assertEqual(volume_identifiers, [])
def testPromptUserForPartitionIdentifiers(self): """Tests the _PromptUserForPartitionIdentifiers function.""" test_path = self._GetTestFilePath(['tsk_volume_system.raw']) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=test_path) test_raw_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) test_tsk_partition_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_TSK_PARTITION, parent=test_raw_path_spec) volume_system = tsk_volume_system.TSKVolumeSystem() volume_system.Open(test_tsk_partition_path_spec) file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(file_object) test_tool = storage_media_tool.StorageMediaTool( output_writer=test_output_writer) # Test selection of single partition. input_file_object = io.BytesIO(b'2\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForPartitionIdentifiers( volume_system, ['p1', 'p2']) self.assertEqual(volume_identifiers, ['p2']) # Test selection of single partition. input_file_object = io.BytesIO(b'p2\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForPartitionIdentifiers( volume_system, ['p1', 'p2']) self.assertEqual(volume_identifiers, ['p2']) # Test selection of single partition with invalid input on first attempt. input_file_object = io.BytesIO(b'bogus\np2\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForPartitionIdentifiers( volume_system, ['p1', 'p2']) self.assertEqual(volume_identifiers, ['p2']) # Test selection of all partitions. input_file_object = io.BytesIO(b'all\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForPartitionIdentifiers( volume_system, ['p1', 'p2']) self.assertEqual(volume_identifiers, ['p1', 'p2'])
def testPromptUserForAPFSVolumeIdentifiers(self): """Tests the _PromptUserForAPFSVolumeIdentifiers function.""" test_path = self._GetTestFilePath(['apfs.dmg']) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=test_path) test_raw_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) test_tsk_partition_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_TSK_PARTITION, location='/p1', parent=test_raw_path_spec) test_apfs_container_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_APFS_CONTAINER, location='/', parent=test_tsk_partition_path_spec) volume_system = apfs_volume_system.APFSVolumeSystem() volume_system.Open(test_apfs_container_path_spec) # Test selection of single volume. input_file_object = io.BytesIO(b'1\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, ['apfs1']) # Test selection of single volume. input_file_object = io.BytesIO(b'apfs1\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, ['apfs1']) # Test selection of single volume with invalid input on first attempt. input_file_object = io.BytesIO(b'bogus\napfs1\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, ['apfs1']) # Test selection of all volumes. input_file_object = io.BytesIO(b'all\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, ['apfs1']) # Test selection of no volumes. input_file_object = io.BytesIO(b'\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_tool = storage_media_tool.StorageMediaTool( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_tool._PromptUserForAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, [])
def testGetLVMVolumeIdentifiers(self): """Tests the GetLVMVolumeIdentifiers function.""" test_file_path = self._GetTestFilePath(['lvm.raw']) self._SkipIfPathNotExists(test_file_path) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_OS, location=test_file_path) test_raw_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) test_lvm_path_spec = path_spec_factory.Factory.NewPathSpec( dfvfs_definitions.TYPE_INDICATOR_LVM, location='/', parent=test_raw_path_spec) volume_system = lvm_volume_system.LVMVolumeSystem() volume_system.Open(test_lvm_path_spec) # Test selection of single volume. input_file_object = io.BytesIO(b'1\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_mediator = storage_media_tool.StorageMediaToolMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetLVMVolumeIdentifiers( volume_system, ['lvm1']) self.assertEqual(volume_identifiers, ['lvm1']) # Test selection of single volume. input_file_object = io.BytesIO(b'lvm1\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_mediator = storage_media_tool.StorageMediaToolMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetLVMVolumeIdentifiers( volume_system, ['lvm1']) self.assertEqual(volume_identifiers, ['lvm1']) # Test selection of single volume with invalid input on first attempt. input_file_object = io.BytesIO(b'bogus\nlvm1\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_mediator = storage_media_tool.StorageMediaToolMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetLVMVolumeIdentifiers( volume_system, ['lvm1']) self.assertEqual(volume_identifiers, ['lvm1']) # Test selection of all volumes. input_file_object = io.BytesIO(b'all\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_mediator = storage_media_tool.StorageMediaToolMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetLVMVolumeIdentifiers( volume_system, ['lvm1', 'lvm2']) self.assertEqual(volume_identifiers, ['lvm1', 'lvm2']) # Test selection of no volumes. input_file_object = io.BytesIO(b'\n') test_input_reader = tools.FileObjectInputReader(input_file_object) output_file_object = io.BytesIO() test_output_writer = tools.FileObjectOutputWriter(output_file_object) test_mediator = storage_media_tool.StorageMediaToolMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetLVMVolumeIdentifiers( volume_system, ['lvm1']) self.assertEqual(volume_identifiers, [])