"""Disposable HTTP integration test for the native Windows client. No user DB/HWID.""" import json import subprocess import sys import tempfile import threading from pathlib import Path from wsgiref.simple_server import make_server, WSGIRequestHandler sys.path.insert(0,str(Path(__file__).resolve().parents[1])) from amnesia_licensing.app import Application, Settings from test_api import Browser, PASSWORD class QuietHandler(WSGIRequestHandler): def log_message(self,*args):pass def check(outage=False): executable=Path(__file__).resolve().parents[2]/"client/build/tests/licensing_test.exe" with tempfile.TemporaryDirectory() as directory: app=Application(Settings(Path(directory),allow_local_setup=True,rate_limit=False,client_seconds=3)) admin,user=Browser(app),Browser(app) assert admin.request("/api/setup",{"username":"owner","password":PASSWORD})[0]==200 assert user.request("/api/auth/register",{"username":"member","password":PASSWORD})[0]==200 issued=admin.request("/api/admin/licenses",{"label":"native test","duration_days":30})[1] assert user.request("/api/licenses/redeem",{"key":issued["key"]})[0]==200 failing=threading.Event() def gateway(environ,start): if failing.is_set() and environ.get("PATH_INFO")=="/api/client/verify": start("503 Service Unavailable",[("Content-Type","application/json")]) return [b'{"error":"test outage"}'] return app(environ,start) with make_server("127.0.0.1",0,gateway,handler_class=QuietHandler) as server: thread=threading.Thread(target=server.serve_forever);thread.start() try: child=subprocess.Popen([str(executable),f"http://127.0.0.1:{server.server_port}/api"],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True) for line in child.stdout: print(line,end="",flush=True) if "worker activated" in line: if outage:failing.set() else:assert admin.request(f"/api/admin/licenses/{issued['license']['id']}/revoke",{})[0]==200 assert child.wait(timeout=15)==0 finally: if child.poll() is None:child.kill();child.wait() server.shutdown();thread.join() if __name__=="__main__": check();print("native revocation passed") check(outage=True);print("native outage expiry passed")