def test_partition_in_partition(): #TODO Remove "+" on DFXML Schema 1.3.0 tracking. dobj = Objects.DFXMLObject(version="1.2.0+") psobj = Objects.PartitionSystemObject() psobj.pstype_str = "mbr" dobj.append(psobj) pobj_outer = Objects.PartitionObject() psobj.append(pobj_outer) pobj_inner = Objects.PartitionObject() pobj_outer.append(pobj_inner) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: psobj_reconst = dobj_reconst.partition_systems[0] pobj_outer_reconst = psobj_reconst.partitions[0] pobj_inner_reconst = pobj_outer_reconst.partitions[0] assert isinstance(pobj_inner_reconst, Objects.PartitionObject) except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_empty_object(): dobj = Objects.DFXMLObject(version="1.2.0") pobj = Objects.PartitionObject() dobj.append(pobj) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: pobj_reconst = dobj_reconst.partitions[0] except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_bsd_disklabel_properties(): """ These were drawn from a BSD Disk Label sample image. """ dobj = Objects.DFXMLObject(version="1.2.0") pobj_a = Objects.PartitionObject() pobj_c = Objects.PartitionObject() dobj.append(pobj_a) dobj.append(pobj_c) pobj_a.partition_index = "a" pobj_c.partition_index = "c" # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: pobj_a_reconst = dobj_reconst.partitions[0] pobj_c_reconst = dobj_reconst.partitions[1] assert pobj_a_reconst.partition_index == "a" assert pobj_c_reconst.partition_index == "c" except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_solaris_ps_in_partition(): dobj = Objects.DFXMLObject(version="1.2.0") psobj_outer = Objects.PartitionSystemObject() dobj.append(psobj_outer) # Add file to outer partition system. fobj_psobj_outer = Objects.FileObject() fobj_psobj_outer.alloc_inode = False fobj_psobj_outer.alloc_name = False fobj_psobj_outer.sha512 = TEST_HASH_1 psobj_outer.append(fobj_psobj_outer) pobj = Objects.PartitionObject() psobj_outer.append(pobj) # Add file to partition. fobj_pobj = Objects.FileObject() fobj_pobj.alloc_inode = False fobj_pobj.alloc_name = False fobj_pobj.sha512 = TEST_HASH_2 pobj.append(fobj_pobj) psobj_inner = Objects.PartitionSystemObject() pobj.append(psobj_inner) # Add file to inner partition system. fobj_psobj_inner = Objects.FileObject() fobj_psobj_inner.alloc_inode = False fobj_psobj_inner.alloc_name = False fobj_psobj_inner.sha512 = TEST_HASH_3 psobj_inner.append(fobj_psobj_inner) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: psobj_outer_reconst = dobj_reconst.partition_systems[0] pobj_reconst = psobj_outer_reconst.partitions[0] psobj_inner_reconst = pobj_reconst.partition_systems[0] assert psobj_outer_reconst.files[0].sha512 == TEST_HASH_1 assert pobj_reconst.files[0].sha512 == TEST_HASH_2 assert psobj_inner_reconst.files[0].sha512 == TEST_HASH_3 except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_cfreds_macwd_properties(): """ These were drawn from a CFReDS sample Mac disk image. """ dobj = Objects.DFXMLObject(version="1.2.0") pobj = Objects.PartitionObject() dobj.append(pobj) pobj.ptype_str = "Apple_Boot" pobj.partition_index = 8 # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: pobj_reconst = dobj_reconst.partitions[0] assert pobj_reconst.ptype_str == "Apple_Boot" assert pobj_reconst.partition_index == "8" except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def test_all(): dobj = Objects.DFXMLObject(version="1.2.0") # Make objects for simple appends. diobj_0 = Objects.DiskImageObject() psobj_0 = Objects.PartitionSystemObject() pobj_0 = Objects.PartitionObject() vobj_0 = Objects.VolumeObject() vobj_0.ftype_str = "hfs" fobj_0 = Objects.FileObject() # Make objects for more exotic appends. psobj_1 = Objects.PartitionSystemObject() vobj_1 = Objects.VolumeObject() vobj_1.ftype_str = "hfsplus" fobj_dobj_1 = Objects.FileObject() fobj_dobj_1.alloc_inode = False fobj_dobj_1.alloc_name = False fobj_psobj_1 = Objects.FileObject() fobj_psobj_1.alloc_inode = False fobj_psobj_1.alloc_name = False fobj_pobj_1 = Objects.FileObject() fobj_pobj_1.alloc_inode = False fobj_pobj_1.alloc_name = False # Do simple appends. dobj.append(diobj_0) diobj_0.append(psobj_0) psobj_0.append(pobj_0) pobj_0.append(vobj_0) vobj_0.append(fobj_0) # Do more exotic appends. pobj_0.append(psobj_1) vobj_0.append(vobj_1) dobj.append(fobj_dobj_1) psobj_0.append(fobj_psobj_1) pobj_0.append(fobj_pobj_1)
def _test_file_in_non_fs_levels_deep(include_disk_image, include_partition_system, include_partition, include_file_system): """ This test follows a simple, vertical storage layer stack, but adds a file at each layer. """ dobj = Objects.DFXMLObject(version="1.2.0") # Add file to top-level document. fobj_dobj = Objects.FileObject() fobj_dobj.alloc_inode = False fobj_dobj.alloc_name = False fobj_dobj.sha512 = TEST_HASH_1 dobj.append(fobj_dobj) appender_stack = [dobj] if include_disk_image: # Add disk image to top-level document. diobj = Objects.DiskImageObject() appender_stack[-1].append(diobj) appender_stack.append(diobj) # Add file to disk image. fobj_diobj = Objects.FileObject() fobj_diobj.alloc_inode = False fobj_diobj.alloc_name = False fobj_diobj.sha512 = TEST_HASH_2 diobj.append(fobj_diobj) if include_partition_system: # Add partition system to disk image. psobj = Objects.PartitionSystemObject() appender_stack[-1].append(psobj) appender_stack.append(psobj) # Add file to partition system. fobj_psobj = Objects.FileObject() fobj_psobj.alloc_inode = False fobj_psobj.alloc_name = False fobj_psobj.sha512 = TEST_HASH_3 psobj.append(fobj_psobj) if include_partition: # Add partition to partition system, but not disk image. if not (include_disk_image and not include_partition_system): pobj = Objects.PartitionObject() appender_stack[-1].append(pobj) appender_stack.append(pobj) # Add file to partition. fobj_pobj = Objects.FileObject() fobj_pobj.alloc_inode = False fobj_pobj.alloc_name = False fobj_pobj.sha512 = TEST_HASH_4 pobj.append(fobj_pobj) if include_file_system: # Add file system to anything but a partition system. if not (include_partition_system and not include_partition): vobj = Objects.VolumeObject() appender_stack[-1].append(vobj) appender_stack.append(vobj) # Add file to file system. fobj_vobj = Objects.FileObject() fobj_vobj.sha512 = TEST_HASH_5 vobj.append(fobj_vobj) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: container_stack = [dobj_reconst] assert dobj_reconst.files[0].sha512 == TEST_HASH_1 if include_disk_image: diobj_reconst = container_stack[-1].disk_images[0] container_stack.append(diobj_reconst) assert diobj_reconst.files[0].sha512 == TEST_HASH_2 if include_partition_system: psobj_reconst = container_stack[-1].partition_systems[0] container_stack.append(psobj_reconst) assert psobj_reconst.files[0].sha512 == TEST_HASH_3 if include_partition: if not (include_disk_image and not include_partition_system): pobj_reconst = container_stack[-1].partitions[0] container_stack.append(pobj_reconst) assert pobj_reconst.files[0].sha512 == TEST_HASH_4 if include_file_system: if not (include_partition_system and not include_partition): vobj_reconst = container_stack[-1].volumes[0] assert vobj_reconst.files[0].sha512 == TEST_HASH_5 except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)
def _test_file_in_non_fs_levels_flat(include_disk_image, include_partition_system, include_partition, include_file_system): """ This test follows a simple, horizontal storage layer stack (every container attached to top document object), and adds a file for each container. """ dobj = Objects.DFXMLObject(version="1.2.0") # Add file to top-level document. fobj_dobj = Objects.FileObject() fobj_dobj.alloc_inode = False fobj_dobj.alloc_name = False fobj_dobj.sha512 = TEST_HASH_1 dobj.append(fobj_dobj) if include_disk_image: # Add disk image. diobj = Objects.DiskImageObject() dobj.append(diobj) # Add file to disk image. fobj_diobj = Objects.FileObject() fobj_diobj.alloc_inode = False fobj_diobj.alloc_name = False fobj_diobj.sha512 = TEST_HASH_2 diobj.append(fobj_diobj) if include_partition_system: # Add partition system. psobj = Objects.PartitionSystemObject() dobj.append(psobj) # Add file to partition system. fobj_psobj = Objects.FileObject() fobj_psobj.alloc_inode = False fobj_psobj.alloc_name = False fobj_psobj.sha512 = TEST_HASH_3 psobj.append(fobj_psobj) if include_partition: # Add partition. pobj = Objects.PartitionObject() dobj.append(pobj) # Add file to partition. fobj_pobj = Objects.FileObject() fobj_pobj.alloc_inode = False fobj_pobj.alloc_name = False fobj_pobj.sha512 = TEST_HASH_4 pobj.append(fobj_pobj) if include_file_system: # Add file system. vobj = Objects.VolumeObject() dobj.append(vobj) # Add file to file system. fobj_vobj = Objects.FileObject() fobj_vobj.sha512 = TEST_HASH_5 vobj.append(fobj_vobj) # Do file I/O round trip. (tmp_filename, dobj_reconst) = libtest.file_round_trip_dfxmlobject(dobj) try: assert dobj_reconst.files[0].sha512 == TEST_HASH_1 if include_disk_image: diobj_reconst = dobj_reconst.disk_images[0] assert diobj_reconst.files[0].sha512 == TEST_HASH_2 if include_partition_system: psobj_reconst = dobj_reconst.partition_systems[0] assert psobj_reconst.files[0].sha512 == TEST_HASH_3 if include_partition: pobj_reconst = dobj_reconst.partitions[0] assert pobj_reconst.files[0].sha512 == TEST_HASH_4 if include_file_system: vobj_reconst = dobj_reconst.volumes[0] assert vobj_reconst.files[0].sha512 == TEST_HASH_5 except: _logger.debug("tmp_filename = %r." % tmp_filename) raise os.remove(tmp_filename)