def setUp(self): super().setUp() self.fake_elf = fixture_setup.FakeElf(root_path=self.path) self.useFixture(self.fake_elf) self.content_dirs = [] self.arch_triplet = ProjectOptions().arch_triplet
def test_patch_fails_with_old_version(self): self.fake_elf = fixture_setup.FakeElf(root_path=self.path, patchelf_version='0.8') self.useFixture(self.fake_elf) elf_file = self.fake_elf['fake_elf-bad-patchelf'] # The base_path does not matter here as there are not files to # be crawled for. elf_patcher = elf.Patcher(dynamic_linker='/lib/fake-ld', root_path='/fake') with mock.patch('subprocess.check_call', wraps=subprocess.check_call) as mock_check_call: self.assertRaises(errors.PatcherNewerPatchelfError, elf_patcher.patch, elf_file=elf_file) # Test that .note.go.buildid is stripped off mock_check_call.assert_has_calls([ mock.call([ 'patchelf', '--set-interpreter', '/lib/fake-ld', mock.ANY ]), mock.call([ 'strip', '--remove-section', '.note.go.buildid', mock.ANY ]), mock.call([ 'patchelf', '--set-interpreter', '/lib/fake-ld', mock.ANY ]), ])
def test_patch_fails_with_old_version(self): self.fake_elf = fixture_setup.FakeElf(root_path=self.path, patchelf_version="0.8") self.useFixture(self.fake_elf) elf_file = self.fake_elf["fake_elf-bad-patchelf"] # The base_path does not matter here as there are not files to # be crawled for. elf_patcher = elf.Patcher(dynamic_linker="/lib/fake-ld", root_path="/fake") with mock.patch("subprocess.check_call", wraps=subprocess.check_call) as mock_check_call: self.assertRaises(errors.PatcherNewerPatchelfError, elf_patcher.patch, elf_file=elf_file) # Test that .note.go.buildid is stripped off mock_check_call.assert_has_calls([ mock.call([ "patchelf", "--set-interpreter", "/lib/fake-ld", mock.ANY ]), mock.call([ "strip", "--remove-section", ".note.go.buildid", mock.ANY ]), mock.call([ "patchelf", "--set-interpreter", "/lib/fake-ld", mock.ANY ]), ])
def test_patch_fails_with_old_version(self): self.fake_elf = fixture_setup.FakeElf(root_path=self.path, patchelf_version='0.8') self.useFixture(self.fake_elf) elf_file = self.fake_elf['fake_elf-bad-patchelf'] # The base_path does not matter here as there are not files to # be crawled for. elf_patcher = elf.Patcher(dynamic_linker='/lib/fake-ld', root_path='/fake') self.assertRaises(errors.PatcherNewerPatchelfError, elf_patcher.patch, elf_file=elf_file)
def setUp(self): super().setUp() patcher = patch('snapcraft.internal.elf.ElfFile.load_dependencies') patcher.start() self.addCleanup(patcher.stop) patcher = patch('snapcraft.internal.elf.Patcher.patch') self.patch_mock = patcher.start() self.addCleanup(patcher.stop) patcher = patch('snapcraft.internal.repo.Repo.get_package_libraries') self.get_packages_mock = patcher.start() self.get_packages_mock.return_value = self._setup_libc6() self.addCleanup(patcher.stop) self.fake_elf = fixture_setup.FakeElf(root_path=self.path) self.useFixture(self.fake_elf)
def test_patch_uses_snapped_strip(self): self.useFixture(fixture_setup.FakeSnapcraftIsASnap()) self.fake_elf = fixture_setup.FakeElf(root_path=self.path, patchelf_version='0.8') self.useFixture(self.fake_elf) elf_file = self.fake_elf['fake_elf-bad-patchelf'] real_check_call = subprocess.check_call real_check_output = subprocess.check_output real_exists = os.path.exists def _fake_check_call(*args, **kwargs): if 'patchelf' in args[0][0]: self.assertThat(args[0][0], Equals('/snap/snapcraft/current/bin/patchelf')) args[0][0] = 'patchelf' elif 'strip' in args[0][0]: self.assertThat( args[0][0], Equals('/snap/snapcraft/current/usr/bin/strip')) args[0][0] = 'strip' real_check_call(*args, **kwargs) def _fake_check_output(*args, **kwargs): if 'patchelf' in args[0][0]: self.assertThat(args[0][0], Equals('/snap/snapcraft/current/bin/patchelf')) args[0][0] = 'patchelf' elif 'strip' in args[0][0]: self.assertThat( args[0][0], Equals('/snap/snapcraft/current/usr/bin/strip')) args[0][0] = 'strip' return real_check_output(*args, **kwargs) def _fake_exists(path): if path == '/snap/snapcraft/current/bin/patchelf': return True elif path == '/snap/snapcraft/current/usr/bin/strip': return True else: return real_exists(path) with mock.patch('subprocess.check_call') as mock_check_call: with mock.patch('subprocess.check_output') as mock_check_output: with mock.patch('os.path.exists', side_effect=_fake_exists): mock_check_call.side_effect = _fake_check_call mock_check_output.side_effect = _fake_check_output # The base_path does not matter here as there are not files # for which to crawl. elf_patcher = elf.Patcher(dynamic_linker='/lib/fake-ld', root_path='/fake') self.assertRaises(errors.PatcherNewerPatchelfError, elf_patcher.patch, elf_file=elf_file) # Test that .note.go.buildid is stripped off mock_check_call.assert_has_calls([ mock.call([ 'patchelf', '--set-interpreter', '/lib/fake-ld', mock.ANY ]), mock.call([ 'strip', '--remove-section', '.note.go.buildid', mock.ANY ]), mock.call([ 'patchelf', '--set-interpreter', '/lib/fake-ld', mock.ANY ]), ])
def setUp(self): super().setUp() self.fake_elf = fixture_setup.FakeElf(root_path=self.path) self.useFixture(self.fake_elf)
def test_patch_uses_snapped_strip(self): self.useFixture(fixture_setup.FakeSnapcraftIsASnap()) self.fake_elf = fixture_setup.FakeElf( root_path=self.path, patchelf_version="0.8" ) self.useFixture(self.fake_elf) elf_file = self.fake_elf["fake_elf-bad-patchelf"] real_check_call = subprocess.check_call real_check_output = subprocess.check_output real_exists = os.path.exists def _fake_check_call(*args, **kwargs): if "patchelf" in args[0][0]: self.assertThat( args[0][0], Equals("/snap/snapcraft/current/bin/patchelf") ) args[0][0] = "patchelf" elif "strip" in args[0][0]: self.assertThat( args[0][0], Equals("/snap/snapcraft/current/usr/bin/strip") ) args[0][0] = "strip" real_check_call(*args, **kwargs) def _fake_check_output(*args, **kwargs): if "patchelf" in args[0][0]: self.assertThat( args[0][0], Equals("/snap/snapcraft/current/bin/patchelf") ) args[0][0] = "patchelf" elif "strip" in args[0][0]: self.assertThat( args[0][0], Equals("/snap/snapcraft/current/usr/bin/strip") ) args[0][0] = "strip" return real_check_output(*args, **kwargs) def _fake_exists(path): if path == "/snap/snapcraft/current/bin/patchelf": return True elif path == "/snap/snapcraft/current/usr/bin/strip": return True else: return real_exists(path) with mock.patch("subprocess.check_call") as mock_check_call: with mock.patch("subprocess.check_output") as mock_check_output: with mock.patch("os.path.exists", side_effect=_fake_exists): mock_check_call.side_effect = _fake_check_call mock_check_output.side_effect = _fake_check_output # The base_path does not matter here as there are not files # for which to crawl. elf_patcher = elf.Patcher( dynamic_linker="/lib/fake-ld", root_path="/fake" ) self.assertRaises( errors.PatcherNewerPatchelfError, elf_patcher.patch, elf_file=elf_file, ) # Test that .note.go.buildid is stripped off mock_check_call.assert_has_calls( [ mock.call( [ "patchelf", "--set-interpreter", "/lib/fake-ld", mock.ANY, ] ), mock.call( [ "strip", "--remove-section", ".note.go.buildid", mock.ANY, ] ), mock.call( [ "patchelf", "--set-interpreter", "/lib/fake-ld", mock.ANY, ] ), ] )