Repository navigation
fix(abi-gate): fail closed when the scan inspected no ELF; install file(1) in manylinux #1574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TimeToBuildBob
wants to merge
4
commits into
ActivityWatch:master
Choose a base branch
from
TimeToBuildBob:fix/abi-gate-fail-closed-on-empty-scan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−6
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e37569a
fix(abi-gate): fail closed when the scan inspected no ELF; install fi…
TimeToBuildBob 29cf756
fix(abi-gate): scan unpadded file output and assert exact failures
TimeToBuildBob 7ae87e5
fix(abi-gate): reject a failed inspection of any ELF
TimeToBuildBob e79ac17
test(abi-gate): fail when the real readelf cannot inspect
TimeToBuildBob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| """Tests for scripts/package/abi-gate.sh failing closed. | ||
|
|
||
| The gate proves the manylinux bundle stays under the glibc 2.28 floor. A run | ||
| that inspected no ELF at all (missing file/readelf, or an archive with no | ||
| binaries) proves nothing and must not print PASS. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
| import stat | ||
| import subprocess | ||
| import zipfile | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| ABI_GATE = Path(__file__).parents[1] / "package" / "abi-gate.sh" | ||
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| shutil.which("readelf") is None or shutil.which("file") is None, | ||
| reason="needs binutils readelf and file(1)", | ||
| ) | ||
|
|
||
|
|
||
| def _zip(tmp_path: Path, members: dict[str, Path | str]) -> Path: | ||
| archive = tmp_path / "bundle.zip" | ||
| with zipfile.ZipFile(archive, "w") as zf: | ||
| for name, src in members.items(): | ||
| if isinstance(src, Path): | ||
| zf.write(src, f"activitywatch/{name}") | ||
| else: | ||
| zf.writestr(f"activitywatch/{name}", src) | ||
| return archive | ||
|
|
||
|
|
||
| def _stub(bindir: Path, name: str, body: str) -> None: | ||
| bindir.mkdir(exist_ok=True) | ||
| path = bindir / name | ||
| path.write_text("#!/bin/bash\n" + body) | ||
| path.chmod(path.stat().st_mode | stat.S_IEXEC) | ||
|
|
||
|
|
||
| def run_gate(tmp_path: Path, archive: Path, bindir: Path | None = None): | ||
| env = dict(os.environ) | ||
| if bindir is not None: | ||
| env["PATH"] = f"{bindir}:{env['PATH']}" | ||
| return subprocess.run( | ||
| ["bash", str(ABI_GATE), str(archive)], | ||
| env=env, | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=60, | ||
| ) | ||
|
|
||
|
|
||
| def test_archive_without_elfs_fails(tmp_path: Path) -> None: | ||
| archive = _zip(tmp_path, {"README.txt": "no binaries here\n"}) | ||
| result = run_gate(tmp_path, archive) | ||
| assert result.returncode == 2, result | ||
| assert "no ELF with GLIBC version references found" in result.stderr | ||
| assert "PASS" not in result.stdout | ||
|
|
||
|
|
||
| def test_broken_file_tool_fails(tmp_path: Path) -> None: | ||
| archive = _zip(tmp_path, {"aw-qt": Path(shutil.which("ls") or "/bin/ls")}) | ||
| bindir = tmp_path / "bin" | ||
| _stub(bindir, "file", "exit 127\n") | ||
| result = run_gate(tmp_path, archive, bindir) | ||
| assert result.returncode == 2, result | ||
| assert "no ELF with GLIBC version references found" in result.stderr | ||
| assert "PASS" not in result.stdout | ||
|
|
||
|
|
||
| def test_broken_readelf_fails(tmp_path: Path) -> None: | ||
| archive = _zip(tmp_path, {"aw-qt": Path(shutil.which("ls") or "/bin/ls")}) | ||
| bindir = tmp_path / "bin" | ||
| _stub(bindir, "readelf", "exit 127\n") | ||
| result = run_gate(tmp_path, archive, bindir) | ||
| assert result.returncode == 2, result | ||
| assert "could not inspect ELF version information" in result.stderr | ||
| assert "PASS" not in result.stdout | ||
|
|
||
|
|
||
| def test_partial_readelf_failure_fails_closed(tmp_path: Path) -> None: | ||
| binary = Path(shutil.which("ls") or "/bin/ls") | ||
| archive = _zip(tmp_path, {"aw-qt": binary, "aw-server": binary}) | ||
| bindir = tmp_path / "bin" | ||
| _stub( | ||
| bindir, "readelf", 'case "$2" in */aw-qt) exit 1;; *) echo GLIBC_2.28;; esac\n' | ||
| ) | ||
| result = run_gate(tmp_path, archive, bindir) | ||
| assert result.returncode == 2, result | ||
| assert "could not inspect ELF version information" in result.stderr | ||
| assert "aw-qt" in result.stderr | ||
| assert "PASS" not in result.stdout | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("short_version, expected_code", [("2.28", 0), ("2.29", 1)]) | ||
| def test_mixed_length_paths_are_all_scanned( | ||
| tmp_path: Path, short_version: str, expected_code: int | ||
| ) -> None: | ||
| binary = Path(shutil.which("ls") or "/bin/ls") | ||
| archive = _zip( | ||
| tmp_path, | ||
| { | ||
| "aw-qt": binary, | ||
| "longer-binary-name": binary, | ||
| "a-much-longer-readme-name.txt": "not an ELF\n", | ||
| }, | ||
| ) | ||
| # Keep file(1) real so its padding is exercised; make symbol versions | ||
| # deterministic, with any violation confined to the shorter binary. | ||
| bindir = tmp_path / "bin" | ||
| _stub( | ||
| bindir, | ||
| "readelf", | ||
| f'case "$2" in */aw-qt) echo GLIBC_{short_version};; ' | ||
| "*) echo GLIBC_2.28;; esac\n", | ||
| ) | ||
| result = run_gate(tmp_path, archive, bindir) | ||
| assert "ELFs with GLIBC refs: 2 / 2" in result.stdout, result | ||
| assert result.returncode == expected_code, result | ||
| if expected_code == 0: | ||
| assert "PASS" in result.stdout | ||
| else: | ||
| assert "VIOLATION in aw-qt: GLIBC_2.29" in result.stdout | ||
| assert "PASS" not in result.stdout | ||
|
|
||
|
|
||
| def test_real_binary_is_scanned(tmp_path: Path) -> None: | ||
| # Host binaries may legitimately exceed the floor; either verdict is fine | ||
| # as long as the binary was actually inspected. | ||
| binary = Path(shutil.which("ls") or "/bin/ls") | ||
| versions = subprocess.run( | ||
| ["readelf", "--version-info", str(binary)], capture_output=True, text=True | ||
| ) | ||
| assert versions.returncode == 0, versions | ||
| if "GLIBC_" not in versions.stdout: | ||
| pytest.skip("host ls has no GLIBC version references") | ||
| archive = _zip(tmp_path, {"aw-qt": binary}) | ||
| result = run_gate(tmp_path, archive) | ||
| assert "ELFs with GLIBC refs: 1 / 1" in result.stdout, result.stdout | ||
|
TimeToBuildBob marked this conversation as resolved.
Resolved
|
||
| assert result.returncode in (0, 1) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.