def get_fileinfo(path, base): if new_root_path is None: return FileInfo(path) else: path_for_tag = path.replace(unicode_patch(base), unicode_patch(new_root_path), 1) path_for_tag = path_for_tag.replace('//', '/') file_info = FileInfo(path_for_tag, actual_path=False) file_info.set_actual_path(path) return file_info
def test_get_files_from_packagefile(self): all_files = self.pacman_environment.get_files_from_packagefile( "/tmp/docker.pkg") expected_file_list = list() expected_file_list.append(FileInfo("/usr/bin/docker.ini")) expected_file_list.append(FileInfo("/usr/bin/docker")) expected_file_list.append(FileInfo("/usr/bin/docker-containerd")) for index, result_file in enumerate(all_files): assert result_file.name == expected_file_list[index].name assert result_file.location == expected_file_list[index].location assert result_file.location == expected_file_list[index].location assert result_file.full_pathname == expected_file_list[ index].full_pathname
def test_get_files_for_package(self): package_info = PackageInfo(package="docker") result_list = self.pacman_environment.get_files_for_package( package_info) expected_file_list = list() expected_file_list.append(FileInfo("/usr/bin/docker")) expected_file_list.append(FileInfo("/usr/bin/docker-containerd")) expected_file_list.append(FileInfo("/usr/bin/docker-containerd-ctr")) expected_file_list.append(FileInfo("/usr/bin/docker-containerd-shim")) expected_file_list.append(FileInfo("/etc/docker.ini")) for index, result_file in enumerate(result_list): assert result_file.name == expected_file_list[index].name assert result_file.location == expected_file_list[index].location if index >= 4: # These are configuration-files assert result_file.mutable is True assert result_file.location == expected_file_list[index].location assert result_file.full_pathname == expected_file_list[ index].full_pathname
def get_files_from_folder(cls, evidence_path, new_root_path): """ Get all files from a path on the filesystem :param evidence_path: Path on the filesystem :return: Lexicographical sorted List of FileInfo()-Objects """ result_files = [] for dirpath, _, files in os.walk(evidence_path): for file in files: actual_path = '/'.join([unicode_patch(dirpath), unicode_patch(file)]) if new_root_path is not None: path_for_tag = actual_path.replace(unicode_patch(evidence_path), unicode_patch(new_root_path), 1) path_for_tag = path_for_tag.replace('//', '/') file_info = FileInfo(path_for_tag, actual_path=False) file_info.set_actual_path(actual_path) else: file_info = FileInfo(actual_path) result_files.append(file_info) return result_files
def get_files_from_folder(cls, evidence_path, new_root_path): """ Get all files from a path on the filesystem :param evidence_path: Path on the filesystem :return: Lexicographical sorted List of FileInfo()-Objects """ result_files = [] for dirpath, _, files in os.walk(evidence_path): for file in files: actual_path = '/'.join( [unicode_patch(dirpath), unicode_patch(file)]) if new_root_path is not None: path_for_tag = actual_path.replace( unicode_patch(evidence_path), unicode_patch(new_root_path), 1) path_for_tag = path_for_tag.replace('//', '/') file_info = FileInfo(path_for_tag, actual_path=False) file_info.set_actual_path(actual_path) else: file_info = FileInfo(actual_path) result_files.append(file_info) return result_files
def test_get_files_from_packagefile(self): all_files = self.dpkg_environment.get_files_from_packagefile( "/tmp/docker.pkg") for f in all_files: print(f.full_pathname) expected_file_list = list() expected_file_list.append( FileInfo("/usr/share/bug/docker-bin/control")) expected_file_list.append(FileInfo("/usr/share/bug/docker/control")) expected_file_list.append( FileInfo("/usr/share/doc/docker/README.backtrace")) expected_file_list.append(FileInfo("/usr/share/man/man8/docker.8.gz")) expected_file_list.append( FileInfo("/usr/share/man/man8/dockerctl.8.gz")) for index, result_file in enumerate(all_files): assert result_file.name == expected_file_list[index].name assert result_file.location == expected_file_list[index].location assert result_file.location == expected_file_list[index].location assert result_file.full_pathname == expected_file_list[ index].full_pathname
def _check_rpm_result_list(list_to_check): expected_file_list = list() # configuration-files expected_file_list.append(FileInfo("/etc/sysconfig/docker-network")) expected_file_list.append(FileInfo("/etc/sysconfig/docker-storage")) expected_file_list.append( FileInfo("/etc/sysconfig/docker-storage-setup")) # normal-files expected_file_list.append(FileInfo("/etc/docker")) expected_file_list.append(FileInfo("/etc/docker/certs.d")) expected_file_list.append(FileInfo("/etc/docker/certs.d/redhat.com")) expected_file_list.append(FileInfo("/var/lib/docker")) for index, result_file in enumerate(list_to_check): assert result_file.name == expected_file_list[index].name assert result_file.location == expected_file_list[index].location if index <= 2: # These are configuration-files assert result_file.mutable is True assert result_file.location == expected_file_list[index].location assert result_file.full_pathname == expected_file_list[ index].full_pathname
def test_get_files_for_package(self): package_info = PackageInfo(package="docker") result_list = self.dpkg_environment.get_files_for_package(package_info) expected_file_list = list() expected_file_list.append(FileInfo("/etc/apt/apt.conf.d/01autoremove")) expected_file_list.append(FileInfo("/etc/cron.daily/apt-compat")) expected_file_list.append( FileInfo("/etc/kernel/postinst.d/apt-auto-removal")) expected_file_list.append(FileInfo("/usr/share/doc/docker")) expected_file_list.append( FileInfo("/usr/share/doc/docker/changelog.Debian.gz")) expected_file_list.append(FileInfo("/usr/share/menu")) expected_file_list.append(FileInfo("/usr/share/menu/docker")) for index, result_file in enumerate(result_list): assert result_file.name == expected_file_list[index].name assert result_file.location == expected_file_list[index].location if index <= 2: # These are configuration-files assert result_file.mutable is True assert result_file.location == expected_file_list[index].location assert result_file.full_pathname == expected_file_list[ index].full_pathname