RedFlag/installer/linux/test_maintainer_scripts.py
Fimeg 765ec4188f publish: carry the Windows product into the projection
The tree adds the installer, service and test paths admitted by this source commit. Nothing else changes about what may cross.

Source-Sha: 3e4a3aa4ce092e9e3f51bc78daf3ddc14d9638f8

Policy-Sha: 3e4a3aa4ce092e9e3f51bc78daf3ddc14d9638f8

Tree-Digest: 89d6fce3828a0e0de0c8eeb41ee6750f4462217e2a04b5190297134d7f4a50c3
2026-09-09 12:47:34 -04:00

52 lines
2.4 KiB
Python

"""Exercise package ownership guards without modifying the host installation."""
import pathlib
import subprocess
import tempfile
import unittest
HERE = pathlib.Path(__file__).parent
class PackageOwnership(unittest.TestCase):
def run_script(self, name, root, action):
# Relocate only the fixed installation root. Execute the actual shell
# script; every command and branch in its ownership guard remains real.
script = (HERE / "debian" / name).read_text().replace("/usr/local/bin", str(root))
return subprocess.run(["sh", "-s", "--", action], input=script, text=True, capture_output=True)
def test_fresh_install_and_own_links_are_accepted(self):
with tempfile.TemporaryDirectory() as directory:
root = pathlib.Path(directory)
self.assertEqual(self.run_script("preinst", root, "install").returncode, 0)
for binary in ["redflag-agent", "redflag-helper", "redflag-desktop"]:
(root / binary).symlink_to("/usr/bin/" + binary)
self.assertEqual(self.run_script("preinst", root, "upgrade").returncode, 0)
def test_unmanaged_binary_and_foreign_link_survive_refusal(self):
for kind in ["binary", "symlink"]:
with self.subTest(kind=kind), tempfile.TemporaryDirectory() as directory:
root = pathlib.Path(directory)
path = root / "redflag-agent"
if kind == "binary":
path.write_bytes(b"existing runtime")
else:
path.symlink_to("/opt/existing/redflag-agent")
result = self.run_script("preinst", root, "upgrade")
self.assertNotEqual(result.returncode, 0)
self.assertIn("explicitly migrate", result.stderr)
if kind == "binary":
self.assertEqual(path.read_bytes(), b"existing runtime")
else:
self.assertEqual(str(path.readlink()), "/opt/existing/redflag-agent")
def test_reconfigure_refuses_before_provisioning(self):
with tempfile.TemporaryDirectory() as directory:
root = pathlib.Path(directory)
(root / "redflag-helper").write_bytes(b"existing helper")
result = self.run_script("postinst", root, "configure")
self.assertNotEqual(result.returncode, 0)
self.assertIn("explicit migration", result.stderr)
if __name__ == "__main__":
unittest.main()