myxce/src/xceadmin/tests/conftest.py
Rongsong Shen ee8473bd99 feat(admin-config-tool): drop ha/data/ entirely, match real client TLS
deploy-ha.sh no longer takes a <data-dir> argument or --build-config
flag. Every deploy now generates a fresh self-signed TLS cert/key
(openssl, RSA 2048, 10y validity) directly into the deploy dir's
certs/, and builds cluster.bin directly into controller/ctrl-1/conf/
via xceadmin -- no intermediate staging directory, nothing preserved
across runs. run-ha-soak.sh (/xce-test-ha) updated to match: dropped
its own XCE_HA_DATADIR-based precondition entirely. Updated 4 callers
(run-ha-soak.sh, test-heartbeat-tolerance.sh, test-commit-durability.sh,
both xce-deploy-ha/xce-test-ha SKILL.md docs).

Separately: xcecommon.wire.connect() was loading a client-side TLS
cert, diverging from the real reference client -- netio.c's
create_ssl_context() presents no certificate at all when acting as a
client (cert_file/key_file both NULL, bare TLS_client_method()).
Fixed connect() to match, and since nothing else consumed cert_dir
(verify_mode=CERT_NONE throughout, no CA check either), removed it
end-to-end: discovery.follow_redirects(), push.push_config()/
probe_config(), and the --cert-dir CLI flag.

Server-side cert loading (mock TLS test servers) is unaffected --
moved into a shared session-scoped tls_certs fixture (new
tests/conftest.py, openssl-generated) replacing 3 duplicated
REPO_HA_DATA_DIR/skipif blocks. Net result: those tests no longer skip
under a hermetic nix build sandbox (which never had ha/data/) --
verified 165/165 passed, 0 skipped, via both meson compile and a full
nix build --option sandbox false .#xcecore_debug rebuild (previously
128 passed / 37 skipped there).

ha/data/{xce.crt,xce.key} removed from git tracking. Requirements
2.3/2.4 and 8.3/8.4/8.5 marked superseded in requirements.md with
dated correction notes.
2026-07-22 14:50:51 +00:00

44 lines
1.4 KiB
Python

"""Shared pytest fixtures for xceadmin's test suite."""
from __future__ import annotations
import shutil
import subprocess
from dataclasses import dataclass
from pathlib import Path
import pytest
@dataclass(frozen=True)
class TlsCertPair:
cert_file: Path
key_file: Path
@pytest.fixture(scope="session")
def tls_certs(tmp_path_factory) -> TlsCertPair:
"""A fresh self-signed TLS cert/key pair, generated once per test
session via openssl -- not read from any checked-in fixture (this
repo carries none; ``ha/data/`` was removed). Matches deploy-ha.sh's
own cert generation: TLS verification is ``SSL_VERIFY_NONE``
everywhere in this codebase (no hostname/identity check anywhere),
so a fresh self-signed pair is exactly as valid a test double as a
long-lived shared one.
"""
if shutil.which("openssl") is None:
pytest.skip("openssl not found on PATH -- required to generate a test TLS cert")
cert_dir = tmp_path_factory.mktemp("xceadmin-tls")
cert_file = cert_dir / "xce.crt"
key_file = cert_dir / "xce.key"
subprocess.run(
[
"openssl", "req", "-x509", "-newkey", "rsa:2048", "-nodes",
"-days", "3650",
"-keyout", str(key_file), "-out", str(cert_file),
"-subj", "/CN=xceadmin-test",
],
check=True,
capture_output=True,
)
return TlsCertPair(cert_file=cert_file, key_file=key_file)