def testReadUtf8(self): """Tests the Read function with UTF-8 encoding.""" file_object = io.BytesIO(self._TEST_DATA) input_reader = command_line.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 testGetVSSStoreIdentifiers(self): """Tests the GetVSSStoreIdentifiers function.""" test_path = self._GetTestFilePath(['vsstest.qcow2']) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_OS, location=test_path) test_qcow_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_QCOW, parent=test_os_path_spec) test_vss_path_spec = path_spec_factory.Factory.NewPathSpec( 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 = command_line.FileObjectOutputWriter(file_object) test_mediator = command_line.CLIVolumeScannerMediator( output_writer=test_output_writer) # Test selection of single store. input_file_object = io.BytesIO(b'2\n') test_input_reader = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetVSSStoreIdentifiers( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetVSSStoreIdentifiers( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetVSSStoreIdentifiers( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetVSSStoreIdentifiers( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetVSSStoreIdentifiers( volume_system, ['vss1', 'vss2']) self.assertEqual(volume_identifiers, [])
def testGetAPFSVolumeIdentifiers(self): """Tests the GetAPFSVolumeIdentifiers function.""" test_path = self._GetTestFilePath(['apfs.dmg']) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_OS, location=test_path) test_raw_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) test_tsk_partition_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_TSK_PARTITION, location='/p1', parent=test_raw_path_spec) test_apfs_container_path_spec = path_spec_factory.Factory.NewPathSpec( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, ['apfs1']) # Test selection of single volume. input_file_object = io.BytesIO(b'apfs1\n') test_input_reader = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetAPFSVolumeIdentifiers( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, ['apfs1']) # Test selection of all volumes. input_file_object = io.BytesIO(b'all\n') test_input_reader = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, ['apfs1']) # Test selection of no volumes. input_file_object = io.BytesIO(b'\n') test_input_reader = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetAPFSVolumeIdentifiers( volume_system, ['apfs1']) self.assertEqual(volume_identifiers, [])
def testGetPartitionIdentifiers(self): """Tests the GetPartitionIdentifiers function.""" test_path = self._GetTestFilePath(['tsk_volume_system.raw']) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_OS, location=test_path) test_raw_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) test_tsk_partition_path_spec = path_spec_factory.Factory.NewPathSpec( 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 = command_line.FileObjectOutputWriter(file_object) test_mediator = command_line.CLIVolumeScannerMediator( output_writer=test_output_writer) # Test selection of single partition. input_file_object = io.BytesIO(b'2\n') test_input_reader = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetPartitionIdentifiers( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetPartitionIdentifiers( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetPartitionIdentifiers( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetPartitionIdentifiers( volume_system, ['p1', 'p2']) self.assertEqual(volume_identifiers, ['p1', 'p2']) # Test selection of no partitions. input_file_object = io.BytesIO(b'\n') test_input_reader = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetPartitionIdentifiers( volume_system, ['p1', 'p2']) self.assertEqual(volume_identifiers, [])
def testGetLVMVolumeIdentifiers(self): """Tests the GetLVMVolumeIdentifiers function.""" test_path = self._GetTestFilePath(['lvm.raw']) self._SkipIfPathNotExists(test_path) test_os_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_OS, location=test_path) test_raw_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_RAW, parent=test_os_path_spec) test_lvm_container_path_spec = path_spec_factory.Factory.NewPathSpec( definitions.TYPE_INDICATOR_LVM, location='/', parent=test_raw_path_spec) volume_system = lvm_volume_system.LVMVolumeSystem() volume_system.Open(test_lvm_container_path_spec) # Test selection of single volume. input_file_object = io.BytesIO(b'1\n') test_input_reader = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( 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 = command_line.FileObjectInputReader( input_file_object) output_file_object = io.BytesIO() test_output_writer = command_line.FileObjectOutputWriter( output_file_object) test_mediator = command_line.CLIVolumeScannerMediator( input_reader=test_input_reader, output_writer=test_output_writer) volume_identifiers = test_mediator.GetLVMVolumeIdentifiers( volume_system, ['lvm1']) self.assertEqual(volume_identifiers, [])