def test_reset_except_root(self, arch): soname_cache = elf.SonameCache() soname_cache[arch, "soname.so"] = Path("/fake/path/soname.so") soname_cache[arch, "soname2.so"] = Path("/keep/me/soname2.so") soname_cache[arch, "notfound.so"] = None # type: ignore assert (arch, "soname.so") in soname_cache assert (arch, "soname2.so") in soname_cache assert (arch, "notfound.so") in soname_cache soname_cache.reset_except_root("/keep/me") assert (arch, "soname.so") not in soname_cache assert (arch, "notfound.so") not in soname_cache assert (arch, "soname2.so") in soname_cache
def test_get_libraries_with_soname_cache(self, new_dir, fake_elf, fake_libs): elf_file = fake_elf("fake_elf-2.23") arch = ("ELFCLASS64", "ELFDATA2LSB", "EM_X86_64") soname_cache = elf.SonameCache() soname_cache[arch, "bar.so.2"] = Path("/lib/bar.so.2") libs = elf_file.load_dependencies( root_path=new_dir, base_path=new_dir / "core", arch_triplet="x86_64-linux-gnu", content_dirs=[], soname_cache=soname_cache, ) # With no cache this would have returned '/usr/lib/bar.so.2' assert libs == {str(fake_libs["foo.so.1"]), "/lib/bar.so.2"}
def test_is_valid_elf_ignores_corrupt_files(self, mocker, new_dir, fake_elf): soname = "libssl.so.1.0.0" soname_path = new_dir / soname fake_elf(soname) library = _Library( soname=soname, soname_path=soname_path, search_paths=[new_dir], base_path=Path("/snap/core20/current"), arch_tuple=("ELFCLASS64", "ELFDATA2LSB", "EM_X86_64"), soname_cache=elf.SonameCache(), ) assert library._is_valid_elf(soname_path) is True mocker.patch( "snapcraft.elf._elf_file.ElfFile", side_effect=errors.CorruptedElfFile(path=soname_path, error=RuntimeError()), ) assert library._is_valid_elf(soname_path) is False
def test_error(self, key, partial_message): soname_cache = elf.SonameCache() with pytest.raises(EnvironmentError) as raised: soname_cache[key] = Path("/soname.so") assert str(raised.value).startswith(partial_message)
def test_add_and_verify_soname_path(self, arch): soname_cache = elf.SonameCache() soname_cache[arch, "soname.so"] = Path("/fake/path/soname.so") assert (arch, "soname.so") in soname_cache
def test_add_and_retrieve_soname_path(self, arch): soname_cache = elf.SonameCache() soname_cache[arch, "soname.so"] = Path("/fake/path/soname.so") assert soname_cache[arch, "soname.so"] == Path("/fake/path/soname.so")