vinix-ports / tests / accounts-upgrade.py
60 lines · 54 sloc · 2.76 KB · e9ef004605abe667fafa90c9c26864bd6c8597a6
Raw
1"""Upgrade a signed Vinix account seed over locally edited, locked test accounts."""
2import argparse
3from pathlib import Path
4import stat
5import subprocess
6
7
8def command(*args):
9 subprocess.run(args, check=True)
10
11
12def test(args):
13 args.work.mkdir()
14 old_feed = args.work / "old-feed"
15 new_feed = args.work / "new-feed"
16 command("feed", "publish", args.keys, old_feed, args.arch, args.old_package)
17 command("feed", "publish", args.keys, new_feed, args.arch, args.new_package)
18 client = args.work / "client"
19 command("feed", "install", args.keys, old_feed, args.arch, client, "--fakeroot", "vinix-accounts")
20 etc = client / "root/etc"
21 edited = {}
22 for name, entry in [("passwd", "fixture:x:45000:45000:Test:/nonexistent:/bin/false"),
23 ("group", "fixture:x:45000:"), ("shadow", "fixture:!:0:0:99999:7:::")]:
24 path = etc / name
25 with path.open("a") as output:
26 output.write(entry + "\n")
27 edited[name] = path.read_bytes()
28 config = (client / "config.vile").read_text()
29 if config.count("/old-feed/") != 1:
30 raise ValueError("expected exactly one initial feed in client configuration")
31 upgrade_config = client / "upgrade.vile"
32 upgrade_config.write_text(config.replace("/old-feed/", "/new-feed/"))
33 command("fakeroot", "--", "vpac", "--config", upgrade_config, "u", "--sync", "--noconfirm")
34 for name, value in edited.items():
35 if (etc / name).read_bytes() != value:
36 raise RuntimeError(f"local {name} entries changed on upgrade")
37 if stat.S_IMODE((etc / "shadow").stat().st_mode) != 0o600:
38 raise RuntimeError("installed shadow permissions changed")
39 defaults = {
40 "passwd": "nobody:x:65534:65534:Unprivileged user:/nonexistent:/bin/false",
41 "group": "nobody:x:65534:",
42 "shadow": "nobody:*:0:0:99999:7:::",
43 }
44 for name, entry in defaults.items():
45 if entry not in (etc / (name + ".pacnew")).read_text().splitlines():
46 raise RuntimeError(f"new {name} default was not preserved for review")
47 if stat.S_IMODE((etc / "shadow.pacnew").stat().st_mode) != 0o600:
48 raise RuntimeError("new shadow defaults are not private")
49 db = client / "db/local"
50 if not (db / "vinix-accounts-0.1.0-2").is_dir() or (db / "vinix-accounts-0.1.0-1").exists():
51 raise RuntimeError("account seed version did not upgrade")
52 print("Account seed upgrade preserved local passwd, group and private shadow with the new defaults.")
53
54
55if __name__ == "__main__":
56 parser = argparse.ArgumentParser(description=__doc__)
57 for name in ("old_package", "new_package", "keys", "work"):
58 parser.add_argument(name, type=lambda path: Path(path).resolve())
59 parser.add_argument("arch", choices=["x86_64", "aarch64"])
60 test(parser.parse_args())
61