All checks were successful
Desktop source guards / guards (push) Successful in 26s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
115 lines
5.8 KiB
Python
115 lines
5.8 KiB
Python
from pathlib import Path
|
|
|
|
|
|
SOURCE_DIR = Path(__file__).resolve().parents[1]
|
|
MODULE = SOURCE_DIR / "zsg_pathtest"
|
|
WSS_SOCKET_CPP = SOURCE_DIR / "mtproto" / "proxy" / "wss" / "socket.cpp"
|
|
NAIVE_SOCKET_CPP = SOURCE_DIR / "zsg_naive" / "zsg_naive_socket.cpp"
|
|
TLS_HANDSHAKE_CPP = SOURCE_DIR / "mtproto" / "proxy" / "mtproxy" / "tls_socket_handshake.cpp"
|
|
CMAKE_LISTS = SOURCE_DIR.parent / "CMakeLists.txt"
|
|
|
|
|
|
def read(path):
|
|
return path.read_text(encoding="utf-8")
|
|
|
|
|
|
def test_the_probe_uses_the_real_client_code_not_a_second_hello():
|
|
# Owner rule 2026-11-29: the diagnostic must not become a second client. The probe takes the config of the
|
|
# library from the same builders as the real sockets and the hello from the same two functions as TlsSocket.
|
|
probe = read(MODULE / "pathtest_probe.cpp")
|
|
runner = read(MODULE / "pathtest_runner.cpp")
|
|
assert "WssClientConfig(route)" in probe
|
|
assert "NaiveClientConfig(" in probe
|
|
assert "std::make_unique<WssClientConfig>(_route)" in read(WSS_SOCKET_CPP)
|
|
assert "std::make_unique<NaiveClientConfig>(" in read(NAIVE_SOCKET_CPP)
|
|
handshake = read(TLS_HANDSHAKE_CPP)
|
|
assert "PrepareClientHelloRules(profile)" in handshake
|
|
assert "PrepareClientHello(" in handshake
|
|
assert "MTP::details::PrepareClientHelloRules(profile.tls)" in runner
|
|
assert "MTP::details::PrepareClientHello(" in runner
|
|
# No hand-made hello bytes anywhere in the module.
|
|
for name in ("pathtest_probe.cpp", "pathtest_runner.cpp", "pathtest_core.cpp"):
|
|
source = read(MODULE / name)
|
|
assert "\\x16\\x03" not in source
|
|
assert "GREASE" not in source
|
|
|
|
|
|
def test_the_module_never_touches_credentials():
|
|
runner = read(MODULE / "pathtest_runner.cpp")
|
|
probe = read(MODULE / "pathtest_probe.cpp")
|
|
core = read(MODULE / "pathtest_core.cpp")
|
|
# The proxy user name and password are never read; only the cover domain of a FakeTLS secret is taken. (The
|
|
# developer hook only WRITES throw-away entries into the in-memory list; it is named `entry`, not `proxy`.)
|
|
assert "proxy.password" not in runner
|
|
assert "proxy.user" not in runner
|
|
assert ".password" not in core and ".password" not in probe
|
|
assert "secretFromMtprotoPassword()" in runner
|
|
assert "const auto domain = target.sni.toUtf8();" in runner
|
|
assert "random_not_the_secret" in runner
|
|
# The Naive probe sends throw-away credentials.
|
|
assert 'kProbeUser = "zsg-pathtest"' in probe
|
|
|
|
|
|
def test_every_log_field_goes_through_the_closed_vocabulary():
|
|
core = read(MODULE / "pathtest_core.cpp")
|
|
assert "SafeToken(result)" in core and "SafeToken(detail)" in core and "SafeToken(app)" in core
|
|
assert "CleanEnvironmentValue(entry.value)" in core
|
|
# Attempt lines carry only the masked id; a real name is written in the hosts table alone.
|
|
assert "if (_includeRealNames)" in core
|
|
|
|
|
|
def test_the_probe_does_not_disturb_the_client():
|
|
# The probe has its own threads and sockets; it must not call into the route health of the real client.
|
|
probe = read(MODULE / "pathtest_probe.cpp")
|
|
runner = read(MODULE / "pathtest_runner.cpp")
|
|
for forbidden in ("WssTrackNetwork", "NoteDirect", "SuppressRoute", "RecordFailure"):
|
|
assert forbidden not in probe and forbidden not in runner
|
|
|
|
|
|
def test_the_probe_does_not_show_the_whole_server_list_to_the_provider():
|
|
# Owner rule 2026-11-29 (the stealth gate of the KVN module): ONE selected server by default; every server only
|
|
# on an explicit tick, one host at a time with a random 10-20 s pause; nothing resolves or connects to a later
|
|
# server before its turn.
|
|
runner = read(MODULE / "pathtest_runner.cpp")
|
|
assert "bool allServers = false;" in read(MODULE / "pathtest_runner.h")
|
|
assert "proxy().selected()" in runner
|
|
assert "Core::App().settings().proxy().isEnabled()" in runner
|
|
assert "10000 + int(QRandomGenerator::global()->bounded(10001))" in runner
|
|
assert "RunWindow(*state, window)" in runner
|
|
# DNS and TCP happen inside the window of the host, never in a loop over all targets before the probes.
|
|
window = runner[runner.index("void RunWindow("):runner.index("void Run(\n")]
|
|
assert "Resolve(state, *target);" in window and "PlainTcp(state, *target);" in window
|
|
run = runner[runner.index("void Run(\n"):runner.index("} // namespace\n\nbool Running()")]
|
|
assert "Resolve(" not in run and "PlainTcp(" not in run
|
|
box = read(SOURCE_DIR / "boxes" / "connection_box.cpp")
|
|
assert ".allServers = allServers" in box
|
|
assert "start(false, false)" in box and "start(false, true)" in box
|
|
|
|
|
|
def test_every_probe_socket_bypasses_the_application_proxy():
|
|
# Found by the first real desktop run with a proxy enabled: a QTcpSocket picks up the application-wide proxy and
|
|
# the probe to the proxy host itself failed in 2 ms ("connect_error"). Every socket of the probe dials directly.
|
|
probe = read(MODULE / "pathtest_probe.cpp")
|
|
sockets = probe.count("QTcpSocket();") + probe.count("QSslSocket();")
|
|
assert sockets >= 4
|
|
assert probe.count("setProxy(QNetworkProxy::NoProxy)") == sockets
|
|
|
|
|
|
def test_the_developer_hook_is_inert_without_its_environment_variable():
|
|
runner = read(MODULE / "pathtest_runner.cpp")
|
|
assert 'qEnvironmentVariable("ZSG_PATHTEST_SELFTEST")' in runner
|
|
assert "StartSelfTestFromEnvironment();" in read(SOURCE_DIR / "core" / "application.cpp")
|
|
|
|
|
|
def test_the_module_is_built_and_wired_into_the_ui():
|
|
cmake = read(CMAKE_LISTS)
|
|
for name in ("pathtest_core", "pathtest_probe", "pathtest_runner"):
|
|
assert f"zsg_pathtest/{name}.cpp" in cmake
|
|
assert "Zsg::PathTest::Start(" in read(SOURCE_DIR / "boxes" / "connection_box.cpp")
|
|
assert "offerConnectionCheck();" in read(SOURCE_DIR / "window" / "window_connecting_widget.cpp")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
for name, value in list(globals().items()):
|
|
if name.startswith("test_") and callable(value):
|
|
value()
|