"""Test the release overlay layout and rejection of a changed base.""" import argparse import hashlib from importlib import import_module import os from pathlib import Path import sys import tarfile import tempfile import unittest sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "tools")) sidecar = import_module("bundle-x11") class BundleTest(unittest.TestCase): def setUp(self): work = tempfile.TemporaryDirectory() self.addCleanup(work.cleanup) self.base, self.full, self.output = (Path(work.name, name) for name in ("base", "full", "output")) for client in (self.base, self.full): self.install_record(client, "vinix-release-desktop", "1-1") (client / "root/usr/bin").mkdir(parents=True) (client / "root/usr/bin/pkg").write_bytes(b"desktop package manager") self.install_record(self.full, "vinix-release-x11", "2-1") for path in sidecar.RELEASE_COMMANDS: command = self.full / "root" / path command.write_bytes(path.encode()) command.chmod(0o755) def install_record(self, client, name, version): directory = client / "db/local" / f"{name}-{version}" directory.mkdir(parents=True) (directory / "desc").write_text(f"%NAME%\n{name}\n\n%VERSION%\n{version}\n\n") def write_bundle(self, arch="x86_64"): # Signature and ELF checks run in the signed-root release fixture. sidecar.bundle(argparse.Namespace( desktop=self.base, x11=self.full, output=self.output, auditor="/bin/true", arch=arch)) def test_arm64_overlay_preserves_links_and_omits_desktop_paths(self): drivers = self.full / "root/usr/lib/dri" drivers.mkdir(parents=True) driver = drivers / "swrast_dri.so" driver.write_bytes(b"software driver") os.link(driver, drivers / "kms_swrast_dri.so") (drivers / "swrast.so").symlink_to(driver.name) self.write_bundle("aarch64") archive = self.output / "vinix-x11-arm64.tar.gz" digest = hashlib.sha256(archive.read_bytes()).hexdigest() self.assertEqual(archive.with_suffix(".gz.sha256").read_text(), f"{digest} {archive.name}\n") with tarfile.open(archive) as tar: self.assertNotIn("./usr/bin/pkg", tar.getnames()) self.assertNotIn("./usr/bin", tar.getnames()) self.assertNotIn("./db", tar.getnames()) binary = tar.getmember("./usr/bin/Xvfb") self.assertEqual((binary.uid, binary.gid, binary.mode), (0, 0, 0o755)) self.assertEqual(tar.getmember("./usr/lib/dri/swrast.so").linkname, driver.name) self.assertTrue(tar.getmember("./usr/lib/dri/swrast_dri.so").islnk()) def test_changed_desktop_bytes_prevent_publication(self): (self.full / "root/usr/bin/pkg").write_bytes(b"replaced package manager") with self.assertRaisesRegex(ValueError, "changed /usr/bin/pkg"): self.write_bundle() self.assertFalse(self.output.exists()) def test_missing_glx_server_prevents_publication(self): (self.full / "root/usr/bin/Xvfb-glx").unlink() with self.assertRaisesRegex(ValueError, "missing executable /usr/bin/Xvfb-glx"): self.write_bundle() self.assertFalse(self.output.exists()) if __name__ == "__main__": unittest.main()