Files
WoW-Hybrid-gateway/tests/loopback_key_width_test.py

45 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Deterministic real-SRP header-wrap regression for the loopback source peer."""
import os
from pathlib import Path
import shlex
import subprocess
import sys
import tempfile
def check_source_key_width(driver, fixture):
source = Path(__file__).with_name('loopback_srp_entropy_fixture.c')
with tempfile.TemporaryDirectory(prefix='gateway-header-width-') as tmp:
directory = Path(tmp)
shim = directory / 'synthetic-srp.so'
# Compile before opening test listeners; this is not part of any
# socket/child deadline. No production artifact is built or replaced.
subprocess.run([*shlex.split(os.environ.get('CC', 'cc')), '-shared', '-fPIC',
str(source), '-ldl', '-o', str(shim)], check=True,
capture_output=True, text=True)
for name, value in [('password', fixture.PASSWORD + b'\n'),
('version', fixture.VERSION), ('addons', fixture.ADDONS)]:
(directory / name).write_bytes(value)
saved = {key: os.environ.get(key) for key in ('LD_PRELOAD', 'GW_TEST_HEADER_KEY_WIDTH')}
try:
os.environ['LD_PRELOAD'] = str(shim) + (':' + saved['LD_PRELOAD'] if saved['LD_PRELOAD'] else '')
for width in (39, 40):
os.environ['GW_TEST_HEADER_KEY_WIDTH'] = str(width)
# The source peer independently derives K and asserts this
# natural width, proving that the forced draw really applied.
fixture.run_case(driver, directory, 'instant-character-logout',
discover=True, wire=True, reentry=True)
print(f'source header width {width}: real-SRP three-entry lifecycle PASS', flush=True)
finally:
for key, value in saved.items():
if value is None:
os.environ.pop(key, None)
else:
os.environ[key] = value
if __name__ == '__main__':
import loopback_fixture
check_source_key_width(sys.argv[1], loopback_fixture)