okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-gh-ctl: GitHub setup, Docker, docs and bench items for 0.2.7538acd098

main
2.0 KiB54 linesraw
1"""Windows token defaults must permit identifying children, not just opening files."""
2import json
3import os
4from pathlib import Path
5import subprocess
6import sys
7import tempfile
8import unittest
9
10
11ROOT = Path(__file__).resolve().parents[2]
12PROBE = r"""
13import json, subprocess, sys
14from pathlib import Path
15from strata_control import private_files, procs
16
17assert private_files.adopt_user_defaults()
18child = subprocess.Popen(
19    [sys.executable, "-c", "import time; print('ready', flush=True); time.sleep(30)"],
20    stdout=subprocess.PIPE, text=True,
21)
22try:
23    assert child.stdout.readline().strip() == "ready"
24    assert child.poll() is None
25    token = procs.start_token(child.pid)
26    assert token is not None, "live child became unreadable after adopting user defaults"
27    recorded = procs.write_record(child.pid, "engine")
28    assert recorded == token, "child identity could not be recorded"
29    print(json.dumps({"identified": True, "recorded": True}), flush=True)
30finally:
31    child.kill()
32    child.wait(timeout=10)
33    child.stdout.close()
34"""
35
36
37@unittest.skipUnless(os.name == "nt", "Windows token default DACL")
38class DefaultObjectAccess(unittest.TestCase):
39    def test_adopting_user_defaults_preserves_child_identity(self):
40        # Token defaults affect every subsequent object creation in this process.
41        # Exercise them in a disposable helper, not in the test runner itself.
42        with tempfile.TemporaryDirectory(prefix="strata-default-access-") as folder:
43            env = dict(os.environ, LOCALAPPDATA=folder, PYTHONPATH=str(ROOT))
44            result = subprocess.run(
45                [sys.executable, "-c", PROBE], cwd=ROOT, env=env,
46                stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, timeout=25,
47                creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0),
48            )
49            self.assertEqual(result.returncode, 0, result.stderr)
50            self.assertEqual(json.loads(result.stdout), {"identified": True, "recorded": True})
51
52
53if __name__ == "__main__":
54    unittest.main()