def test_symlinks(self): symlinked_path = os.path.join(self.fake_elf.root_path, "symlinked") os.symlink("/bin/dash", symlinked_path) elf_files = elf.get_elf_files(self.fake_elf.root_path, {"symlinked"}) self.assertThat(elf_files, Equals(set()))
def test_skip_object_files(self): open(os.path.join(self.fake_elf.root_path, "object_file.o"), "w").close() elf_files = elf.get_elf_files(self.fake_elf.root_path, {"object_file.o"}) self.assertThat(elf_files, Equals(set()))
def test_non_elf_files(self): with open(os.path.join(self.fake_elf.root_path, "non-elf"), "wb") as f: # A bz2 header f.write(b"\x42\x5a\x68") elf_files = elf.get_elf_files(self.fake_elf.root_path, {"non-elf"}) self.assertThat(elf_files, Equals(set()))
def test_get_elf_files(self): elf_files = elf.get_elf_files(self.fake_elf.root_path, {"fake_elf-2.23"}) self.assertThat(len(elf_files), Equals(1)) elf_file = set(elf_files).pop() self.assertThat(elf_file.interp, Equals("/lib64/ld-linux-x86-64.so.2"))
def test_fifo(self): fifo_path = os.path.join(self.fake_elf.root_path, "fifo") os.mkfifo(fifo_path) elf_files = elf.get_elf_files(self.fake_elf.root_path, {"fifo"}) self.assertThat(elf_files, Equals(set()))
def test_device_files(self): elf_files = elf.get_elf_files("/dev", {"null"}) self.assertThat(elf_files, Equals(set()))
def test_elf_without_execstack(self): elf_files = elf.get_elf_files(self.fake_elf.root_path, {"fake_elf-2.23"}) elf_file = set(elf_files).pop() self.assertThat(elf_file.execstack_set, Equals(False))
def test_elf_with_execstack(self): elf_files = elf.get_elf_files(self.fake_elf.root_path, {"fake_elf-with-execstack"}) elf_file = set(elf_files).pop() self.assertThat(elf_file.execstack_set, Equals(True))
def test_no_find_dependencies_statically_linked(self): elf_files = elf.get_elf_files(self.fake_elf.root_path, {"fake_elf-static"}) self.assertThat(elf_files, Equals(set()))
def test_invalid_elf_file(self): invalid_elf = os.path.join(self.path, "invalid-elf") open(invalid_elf, "wb").write(b"\x7fELF\x00") elf_files = elf.get_elf_files(self.path, ["invalid-elf"]) self.assertThat(elf_files, Equals(set()))