okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
538acd098
main
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)"], 20stdout=subprocess.PIPE, text=True, 21) 22try: 23assert child.stdout.readline().strip() == "ready" 24assert child.poll() is None 25token = procs.start_token(child.pid) 26assert token is not None, "live child became unreadable after adopting user defaults" 27recorded = procs.write_record(child.pid, "engine") 28assert recorded == token, "child identity could not be recorded" 29print(json.dumps({"identified": True, "recorded": True}), flush=True) 30finally: 31child.kill() 32child.wait(timeout=10) 33child.stdout.close() 34""" 35 36 37@ unittest . skipUnless ( os . name == "nt" , "Windows token default DACL" ) 38class DefaultObjectAccess (unittest .TestCase ): 39def 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. 42with tempfile .TemporaryDirectory (prefix = "strata-default-access-" )as folder : 43env = dict (os .environ ,LOCALAPPDATA = folder ,PYTHONPATH = str (ROOT )) 44result = subprocess .run ( 45 [sys .executable ,"-c" ,PROBE ],cwd = ROOT ,env = env , 46stdout = subprocess .PIPE ,stderr = subprocess .PIPE ,text = True ,timeout = 25 , 47creationflags = getattr (subprocess ,"CREATE_NO_WINDOW" ,0 ), 48 ) 49self .assertEqual (result .returncode ,0 ,result .stderr ) 50self .assertEqual (json .loads (result .stdout ), {"identified" :True ,"recorded" :True }) 51 52 53if __name__ == "__main__" : 54unittest .main ()