Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7575a45a42 | ||
|
|
d87492ea9f | ||
|
|
71c3324006 |
No files matched your search
@@ -0,0 +1,132 @@
|
||||
name: cold-pool-hunt (one UDP e2e of the SOCKS5 line, repeated, with the engine's SOCKS logs)
|
||||
|
||||
# test_webrtc_realness.py::test_a_gather_after_the_page_loaded_through_the_gateway_costs_only_the_road_to_the_server was red once in 41 on Windows
|
||||
# in the gate of run 43188313516: the srflx came at 1024 ms, four steps of 250 ms, as if the PeerConnection had opened a new association instead
|
||||
# of taking a ready one. This job repeats THAT test on the engine of that run, in a fresh pytest process each time, with the engine's logs
|
||||
# (MOZ_LOG timestamp,sync,append,SOCKS,SOCKS-UDP,signaling) in one folder per repetition and the wall-clock times of what the test gateway sees
|
||||
# (tests/_hunt_plugin.py), keeps the red repetitions and three green ones as an artifact, and prints red/total and, for each red one, the sequence
|
||||
# with times (scripts/cold_pool_report.py): first SOCKS5 connection, associations OK, PeerConnection, push of the UDP layer, and how many
|
||||
# associations were ready at each push. A hunt, not a gate: it starts on a push that touches this file, and its verdict is the printed numbers.
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '.github/workflows/cold-pool-hunt.yml'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
engine_run_id:
|
||||
description: 'run of feder-cr/firefox_antidetect_patch whose asset-win-x86_64 artifact is the engine'
|
||||
required: false
|
||||
default: ''
|
||||
core_ref:
|
||||
description: 'ref of feder-cr/invisible_core that run built the engine with'
|
||||
required: false
|
||||
default: ''
|
||||
repetitions:
|
||||
description: 'how many times the test runs'
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
ENGINE_RUN_ID: ${{ inputs.engine_run_id || '43188313516' }}
|
||||
ENGINE_REPO: feder-cr/firefox_antidetect_patch
|
||||
CORE_REF: ${{ inputs.core_ref || 'candidate/core-63-r5' }}
|
||||
# The wrapper that drives this engine: the tests come from this branch (a branch of udp/wrapper-r5), the package under them from udp/wrapper-r5.
|
||||
WRAPPER_REF: udp/wrapper-r5
|
||||
SEAL_TAG: firefox-63-candidate
|
||||
REPETITIONS: ${{ inputs.repetitions || '150' }}
|
||||
TEST_ID: tests/test_webrtc_realness.py::test_a_gather_after_the_page_loaded_through_the_gateway_costs_only_the_road_to_the_server
|
||||
# The core under test is the one the engine was built with, whatever this wrapper pins.
|
||||
INVISIBLE_CORE_AUTOFIX: 'off'
|
||||
INVISIBLE_CORE_PIN: allow
|
||||
|
||||
jobs:
|
||||
hunt:
|
||||
name: cold-pool hunt (windows-2022, engine of run ${{ inputs.engine_run_id || '43188313516' }})
|
||||
runs-on: windows-2022
|
||||
timeout-minutes: 240
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
with: { fetch-depth: 1 }
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
|
||||
with: { python-version: '3.11' }
|
||||
- name: The core of the run, then the wrapper, then the core again over it
|
||||
run: |
|
||||
CORE_GIT="git+https://github.com/feder-cr/invisible_core@$CORE_REF"
|
||||
python -m pip install --quiet --upgrade pip
|
||||
python -m pip install --quiet "$CORE_GIT"
|
||||
python -m pip install --quiet ".[dev]"
|
||||
python -m pip install --quiet --force-reinstall --no-deps "git+https://github.com/feder-cr/invisible_playwright@$WRAPPER_REF"
|
||||
python -m pip install --quiet --force-reinstall "$CORE_GIT"
|
||||
python -c "import importlib.metadata as m; print('installed: invisible-playwright', m.version('invisible-playwright'), '| invisible-core', m.version('invisible-core'))"
|
||||
python - <<'PY'
|
||||
import json, os, subprocess, sys
|
||||
from importlib.metadata import distribution, version
|
||||
ref = os.environ["CORE_REF"]
|
||||
rows = [line.split() for line in subprocess.run(
|
||||
["git", "ls-remote", "https://github.com/feder-cr/invisible_core", ref, ref + "^{}"],
|
||||
capture_output=True, text=True, check=True).stdout.splitlines() if line.strip()]
|
||||
peeled = [s for s, r in rows if r.endswith("^{}")]
|
||||
want = (peeled or [s for s, _ in rows] or [""])[0]
|
||||
import invisible_playwright # noqa: F401 - the import-time pin check runs here, as under pytest
|
||||
raw = distribution("invisible-core").read_text("direct_url.json")
|
||||
got = (json.loads(raw).get("vcs_info") or {}).get("commit_id") if raw else None
|
||||
print("core under test: %s from %s" % (version("invisible-core"), got or "the index"))
|
||||
if not want or got != want:
|
||||
sys.exit("THE CORE UNDER TEST IS NOT CORE_REF %s: installed from %s, the ref is %s" % (ref, got or "the index", want or "unknown"))
|
||||
PY
|
||||
- name: The engine of the run
|
||||
run: |
|
||||
mkdir -p engine
|
||||
gh run download "$ENGINE_RUN_ID" --repo "$ENGINE_REPO" --name asset-win-x86_64 --dir engine/archive
|
||||
ls -la engine/archive
|
||||
python - <<'PY'
|
||||
import glob, zipfile
|
||||
z = glob.glob("engine/archive/*.zip")[0]
|
||||
zipfile.ZipFile(z).extractall("engine/x")
|
||||
print("extracted", z)
|
||||
PY
|
||||
python -m invisible_core seal --binary engine/x/firefox.exe --tag "$SEAL_TAG" -o "$PWD/engine/seal.json"
|
||||
echo "INVPW_BINARY_PATH=$PWD/engine/x/firefox.exe" >> "$GITHUB_ENV"
|
||||
echo "STEALTHFOX_E2E_BINARY=$PWD/engine/x/firefox.exe" >> "$GITHUB_ENV"
|
||||
echo "INVISIBLE_SEAL_FILE=$PWD/engine/seal.json" >> "$GITHUB_ENV"
|
||||
- name: The test once, as the gate runs it (is the machine able to run it at all)
|
||||
run: |
|
||||
python -m pytest "$TEST_ID" -m e2e -p no:cacheprovider -q -rA || echo "the single run was red or skipped, the hunt goes on"
|
||||
- name: The hunt
|
||||
id: hunt
|
||||
run: python scripts/cold_pool_hunt.py --test "$TEST_ID" --repetitions "$REPETITIONS" --out hunt --greens 3 | tee hunt-report.txt
|
||||
- name: The numbers in the summary
|
||||
if: always()
|
||||
run: |
|
||||
{
|
||||
echo '### cold-pool hunt'
|
||||
echo
|
||||
echo "engine run $ENGINE_RUN_ID, core $CORE_REF, $REPETITIONS repetitions"
|
||||
echo
|
||||
echo '```'
|
||||
grep -E '^=== [0-9]+ red' hunt-report.txt || echo 'no summary line: the hunt did not finish'
|
||||
echo '```'
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
- name: Upload the logs of the red repetitions and of three green ones
|
||||
if: always()
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
|
||||
with:
|
||||
name: cold-pool-hunt-${{ github.run_id }}
|
||||
path: |
|
||||
hunt
|
||||
hunt-report.txt
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
@@ -3,7 +3,7 @@
|
||||
{"id": "wrapper.e2e.web", "giro": "G2", "os": ["linux", "windows"], "min_tests": 27, "exact": true, "tests": ["tests/test_networkidle_through_a_served_browser_with_routes_e2e.py", "tests/test_http3_through_the_proxy_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The networkidle e2e with routes and the HTTP/3 e2e, split from wrapper.e2e.udp (about 260 s of 500 on Linux; the whole suite did not fit the 15 minutes of Windows)."},
|
||||
{"id": "wrapper.e2e.doh", "giro": "G2", "os": ["linux", "windows"], "min_tests": 19, "exact": true, "tests": ["tests/test_the_hosts_file_of_the_host_is_never_read_e2e.py", "tests/test_resolver_race_e2e.py", "tests/test_doh_under_stress_e2e.py", "tests/test_context_proxy_only_resolves_by_doh_e2e.py", "tests/test_doh_through_the_proxy_e2e.py", "tests/test_ice_names_by_the_context_proxy_e2e.py"], "marker": "e2e", "needs_root": ["linux"], "note": "Linux needs root: the resolver trap of the file (ResolverTrap) points /etc/resolv.conf at a counting resolver on port 53. Su Windows il resolver trap non gira: l'asserzione sul resolver di sistema è l'unica omessa. Run it without xdist (port 53 is one per host). On the Linux leg the gate exports INVPW_REQUIRE_TRAP=1: a trap that cannot run or bind port 53 is a failure, not a skipped assertion."},
|
||||
{"id": "wrapper.e2e.realness", "giro": "G2", "os": ["linux", "windows"], "min_tests": 32, "exact": true, "tests": ["tests/test_realness_behind_a_declared_exit_e2e.py"], "marker": "e2e", "needs_root": ["linux"], "note": "The realness check without a real proxy: six declared exits, the values a page reads, and the roads. Linux runs as root without xdist like the DoH suite (the resolver trap); on Windows the trap does not exist and the assertion on the system resolver is the only one omitted."},
|
||||
{"id": "wrapper.unit.udp", "giro": "G1", "os": ["linux", "windows"], "min_tests": 173, "exact": true, "tests": ["tests/test_the_doh_e2e_have_a_screen_on_linux.py", "tests/test_the_realness_helpers.py", "tests/test_the_h3_line_helpers.py", "tests/test_the_fake_doh_delays_and_refuses.py", "tests/test_the_host_address_helper.py", "tests/test_the_udp_chain_helper.py", "tests/test_the_fake_doh_answers.py", "tests/test_doh_session_prefs_unit.py", "tests/test_the_leak_watcher_sees_a_direct_connection.py", "tests/test_the_http_proxy_helper_asks_for_credentials.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_the_network_declaration_reaches_the_engine.py", "tests/test_the_resolver_trap_is_required_by_the_gate.py", "tests/test_the_exit_of_a_context_is_discovered_through_its_own_gateway.py"], "marker": "unit", "needs_root": false, "note": "92 = 6+32+21+7+8+3+9+6. The leak watcher file defines exactly one of its two resolver-trap tests per host (7 everywhere), so no test is skipped. `exact`: min_tests is raised by hand when a test is added."},
|
||||
{"id": "wrapper.unit.udp", "giro": "G1", "os": ["linux", "windows"], "min_tests": 176, "exact": true, "tests": ["tests/test_the_doh_e2e_have_a_screen_on_linux.py", "tests/test_the_realness_helpers.py", "tests/test_the_h3_line_helpers.py", "tests/test_the_fake_doh_delays_and_refuses.py", "tests/test_the_host_address_helper.py", "tests/test_the_udp_chain_helper.py", "tests/test_the_fake_doh_answers.py", "tests/test_doh_session_prefs_unit.py", "tests/test_the_leak_watcher_sees_a_direct_connection.py", "tests/test_the_http_proxy_helper_asks_for_credentials.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_the_network_declaration_reaches_the_engine.py", "tests/test_the_resolver_trap_is_required_by_the_gate.py", "tests/test_the_exit_of_a_context_is_discovered_through_its_own_gateway.py"], "marker": "unit", "needs_root": false, "note": "92 = 6+32+21+7+8+3+9+6. The leak watcher file defines exactly one of its two resolver-trap tests per host (7 everywhere), so no test is skipped. `exact`: min_tests is raised by hand when a test is added."},
|
||||
{"id": "wrapper.e2e.page", "giro": "G2", "os": ["linux", "windows"], "min_tests": 114, "exact": true, "tests": ["tests/test_a_page_that_moves_on_e2e.py", "tests/test_a_popup_is_reported_when_the_engine_says_it_is_ready_as_playwright_does_e2e.py", "tests/test_a_popup_of_a_link_reaches_the_client_e2e.py", "tests/test_popup_destinations_e2e.py", "tests/test_popups_reach_the_client_e2e.py", "tests/test_route_superseded_e2e.py"], "marker": "e2e", "needs_root": false, "note": "114 = 100 + the 14 of test_a_page_that_moves_on_e2e.py (a navigation the page overtook with location.replace ends; the engine fix 860ef8a6d9 is proved by it). 100 counted at the collection; was 96 = 10+32+16+34+4 before the popup tests of 6200bc2). A page is handed over when the engine says Page.ready; a popup reaches the client (link, noopener, window.open; own site and another; with and without a route; in-process and over launch_server) as Playwright's does; a superseded route. Needs the candidate binary, and the stock Playwright client of the dev extra."},
|
||||
{"id": "wrapper.unit.page", "giro": "G1", "os": ["linux", "windows"], "min_tests": 34, "exact": true, "tests": ["tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_page_number_follows_the_call.py"], "marker": "unit", "needs_root": false, "note": "24 (counted at the collection; was 20 = 3+8+1+8 before 6200bc2). The page dispatcher's wait for Page.ready and what it hands over; the drive gate goes through the core (the engine waits for the session's road)."}
|
||||
]
|
||||
@@ -0,0 +1,91 @@
|
||||
"""Repeats ONE e2e test many times with the engine's SOCKS logs, one log folder per repetition, and reports the red ones with their times.
|
||||
|
||||
python scripts/cold_pool_hunt.py --test <nodeid> --repetitions 150 --out hunt [--greens 3]
|
||||
|
||||
For each repetition i the test runs alone in a fresh pytest process with
|
||||
MOZ_LOG="timestamp,sync,append,SOCKS:5,SOCKS-UDP:5,signaling:5" MOZ_LOG_FILE=<out>/rep-<i>/moz.log HUNT_EVENTS=<out>/rep-<i>/gateway.jsonl
|
||||
(`tests/_hunt_plugin.py` writes the wall-clock times of what the test gateway sees). A red repetition keeps its folder; the first
|
||||
`--greens` green ones keep theirs for comparison; the others are removed, so the artifact stays small. `append` keeps the logs of both engine
|
||||
launches of a repetition (the test launches two) in one file, told apart by the process id in each line.
|
||||
|
||||
It prints "red/total", and for every red repetition the sequence with times (see scripts/cold_pool_report.py). Exit 0: a red test is the
|
||||
finding, not a failure of the hunt; only a hunt that could not run at all (no pytest, no repetition finished) exits 1.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
ROOT = HERE.parent
|
||||
sys.path.insert(0, str(HERE))
|
||||
import cold_pool_report # noqa: E402
|
||||
|
||||
MOZ_LOG = "timestamp,sync,append,SOCKS:5,SOCKS-UDP:5,signaling:5"
|
||||
|
||||
|
||||
def one(test, folder, timeout):
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
env = dict(os.environ, MOZ_LOG=MOZ_LOG, MOZ_LOG_FILE=str(folder / "moz.log"), HUNT_EVENTS=str(folder / "gateway.jsonl"),
|
||||
PYTHONPATH=os.pathsep.join([str(ROOT / "tests"), os.environ.get("PYTHONPATH", "")]).rstrip(os.pathsep))
|
||||
cmd = [sys.executable, "-m", "pytest", test, "-m", "e2e", "-p", "_hunt_plugin", "-p", "no:cacheprovider", "-q", "-s", "-rA",
|
||||
"--timeout", str(timeout), "--timeout-method", "thread"]
|
||||
t0 = time.time()
|
||||
try:
|
||||
r = subprocess.run(cmd, cwd=str(ROOT), env=env, capture_output=True, text=True, timeout=timeout + 60)
|
||||
rc, out = r.returncode, r.stdout + r.stderr
|
||||
except subprocess.TimeoutExpired as e:
|
||||
rc, out = 124, "TIMEOUT\n%s" % ((e.stdout or b"").decode("utf-8", "replace") if isinstance(e.stdout, bytes) else (e.stdout or ""))
|
||||
(folder / "pytest.log").write_text(out, encoding="utf-8", errors="replace")
|
||||
(folder / "result.json").write_text(json.dumps({"rc": rc, "seconds": round(time.time() - t0, 1)}), encoding="utf-8")
|
||||
return rc
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--test", required=True)
|
||||
ap.add_argument("--repetitions", type=int, default=150)
|
||||
ap.add_argument("--out", default="hunt")
|
||||
ap.add_argument("--greens", type=int, default=3)
|
||||
ap.add_argument("--timeout", type=int, default=120, help="seconds one repetition may take")
|
||||
a = ap.parse_args()
|
||||
out = Path(a.out)
|
||||
shutil.rmtree(out, ignore_errors=True)
|
||||
out.mkdir(parents=True)
|
||||
reds, greens, errors, kept_green = [], 0, [], 0
|
||||
for i in range(1, a.repetitions + 1):
|
||||
folder = out / ("rep-%03d" % i)
|
||||
rc = one(a.test, folder, a.timeout)
|
||||
if rc == 0:
|
||||
greens += 1
|
||||
if kept_green < a.greens:
|
||||
kept_green += 1
|
||||
else:
|
||||
shutil.rmtree(folder, ignore_errors=True)
|
||||
elif rc == 1:
|
||||
reds.append(i)
|
||||
else:
|
||||
errors.append((i, rc))
|
||||
reds.append(i) # kept as well: a repetition that did not finish is not a green one
|
||||
print("repetition %03d: rc %s%s" % (i, rc, " (kept)" if folder.exists() else ""), flush=True)
|
||||
done = greens + len(reds)
|
||||
print("\n=== %d red / %d repetitions (%d green; %d ended with something other than pass/fail: %s)"
|
||||
% (len(reds), done, greens, len(errors), errors[:10]))
|
||||
summary = {"repetitions": done, "red": reds, "green": greens, "other": errors}
|
||||
(out / "summary.json").write_text(json.dumps(summary, indent=1), encoding="utf-8")
|
||||
for i in reds:
|
||||
print()
|
||||
print(cold_pool_report.report(out / ("rep-%03d" % i)))
|
||||
for folder in sorted(p for p in out.glob("rep-*") if p.name[4:] and int(p.name[4:]) not in reds):
|
||||
print()
|
||||
print("--- a green one, for comparison")
|
||||
print(cold_pool_report.report(folder))
|
||||
return 0 if done else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,112 @@
|
||||
"""The sequence with times of one repetition of the cold-pool hunt (scripts/cold_pool_hunt.py).
|
||||
|
||||
python scripts/cold_pool_report.py hunt/rep-007
|
||||
|
||||
Merges, on the wall clock, the engine's log (MOZ_LOG with `timestamp`, modules SOCKS, SOCKS-UDP, signaling) and the gateway's events
|
||||
(tests/_hunt_plugin.py): the first SOCKS5 connection, every UDP ASSOCIATE the gateway sees and every one the engine says is OK, the
|
||||
PeerConnection, every UDP layer pushed onto a socket, and for each push how many associations were ready (OK before it, minus the pushes
|
||||
before it, per engine process): 0 is a cold pool, the push had to open a new association. "Warm received" is not logged by the engine
|
||||
(nsSOCKSUDPIOLayerWarm has no log line): the associations that follow the first connection are its trace.
|
||||
"""
|
||||
import datetime
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
LINE = re.compile(r"^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d+) UTC - \[(\w+) (\d+):[^\]]*\]: (\w)/(\S+) (.*)$")
|
||||
|
||||
|
||||
def epoch(stamp):
|
||||
return datetime.datetime.strptime(stamp, "%Y-%m-%d %H:%M:%S.%f").replace(tzinfo=datetime.timezone.utc).timestamp()
|
||||
|
||||
|
||||
def engine_events(path):
|
||||
out = []
|
||||
if not path.exists():
|
||||
return out
|
||||
for raw in path.read_text(encoding="utf-8", errors="replace").splitlines():
|
||||
m = LINE.match(raw)
|
||||
if not m:
|
||||
continue
|
||||
stamp, process, pid, level, module, text = m.groups()
|
||||
out.append({"t": epoch(stamp), "process": process, "pid": int(pid), "level": level, "module": module, "text": text})
|
||||
return out
|
||||
|
||||
|
||||
def gateway_events(path):
|
||||
if not path.exists():
|
||||
return []
|
||||
return [json.loads(l) for l in path.read_text(encoding="utf-8").splitlines() if l.strip()]
|
||||
|
||||
|
||||
def classify(e):
|
||||
t = e["text"]
|
||||
if e["module"] == "SOCKS-UDP":
|
||||
if "UDP ASSOCIATE OK" in t:
|
||||
return "associate_ok"
|
||||
if "layer pushed onto fd" in t:
|
||||
return "pushed"
|
||||
if e["level"] == "E" or "failed" in t or "rejected" in t:
|
||||
return "udp_error"
|
||||
if e["module"] == "SOCKS" and "trying proxy server" in t:
|
||||
return "socks_tcp_first_try"
|
||||
if e["module"] == "SOCKS" and e["level"] == "E":
|
||||
return "socks_error"
|
||||
if e["module"] == "signaling" and "PeerConnectionImpl constructor" in t:
|
||||
return "peerconnection"
|
||||
return None
|
||||
|
||||
|
||||
def report(folder):
|
||||
folder = Path(folder)
|
||||
log = engine_events(folder / "moz.log")
|
||||
log += [e for p in sorted(folder.glob("moz.log.*")) for e in engine_events(p)] # child-process files, when the engine writes them
|
||||
gw = gateway_events(folder / "gateway.jsonl")
|
||||
rows = [] # (t, who, what, pid)
|
||||
for e in log:
|
||||
kind = classify(e)
|
||||
if kind:
|
||||
rows.append((e["t"], "engine %s %d" % (e["process"], e["pid"]), kind + (" " + e["text"][:70] if kind.endswith("error") else ""), e["pid"], kind))
|
||||
for e in gw:
|
||||
rows.append((e["t"], "gateway", e["kind"] + (" %s:%s" % (e.get("host"), e.get("port")) if e["kind"] == "connect" else ""), None, e["kind"]))
|
||||
rows.sort()
|
||||
result = {}
|
||||
try:
|
||||
result = json.loads((folder / "result.json").read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
lines = ["=== %s: rc %s, %s s" % (folder.name, result.get("rc"), result.get("seconds"))]
|
||||
pytest_log = (folder / "pytest.log")
|
||||
if pytest_log.exists():
|
||||
for l in pytest_log.read_text(encoding="utf-8", errors="replace").splitlines():
|
||||
if l.startswith("[page first]") or l.startswith("E ") and "srflx" in l:
|
||||
lines.append(" " + l[:260])
|
||||
if not rows:
|
||||
lines.append(" (no event: the engine wrote no log line and the gateway saw nothing)")
|
||||
return "\n".join(lines)
|
||||
t0 = next((r[0] for r in rows if r[4] in ("connect", "socks_tcp_first_try")), rows[0][0])
|
||||
ready = {} # pid -> associations OK minus pushes so far
|
||||
cold = []
|
||||
for t, who, what, pid, kind in rows:
|
||||
note = ""
|
||||
if kind == "associate_ok":
|
||||
ready[pid] = ready.get(pid, 0) + 1
|
||||
elif kind == "pushed":
|
||||
had = ready.get(pid, 0)
|
||||
note = " <- %d ready association(s) at this push%s" % (had, " COLD" if had < 1 else "")
|
||||
if had < 1:
|
||||
cold.append(t - t0)
|
||||
ready[pid] = max(0, had - 1)
|
||||
lines.append(" %+8.3f s %-24s %s%s" % (t - t0, who, what, note))
|
||||
first = lambda k: next((r[0] - t0 for r in rows if r[4] == k), None)
|
||||
fmt = lambda v: "-" if v is None else "%.3f s" % v
|
||||
lines.append(" summary: first SOCKS5 connection %s (gateway) | first association OK %s | PeerConnection %s | first push %s | cold pushes: %s"
|
||||
% (fmt(first("connect")), fmt(first("associate_ok")), fmt(first("peerconnection")), fmt(first("pushed")),
|
||||
", ".join("%.3f s" % c for c in cold) or "none"))
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for arg in sys.argv[1:]:
|
||||
print(report(arg))
|
||||
+7
-2
@@ -20,7 +20,7 @@ import ssl
|
||||
import tempfile
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
def _certificate(address: str, directory: Path):
|
||||
@@ -143,6 +143,9 @@ class H3Server:
|
||||
self.address = address
|
||||
#: The address each QUIC connection came from.
|
||||
self.quic_peers: List[str] = []
|
||||
#: The same peers with the port they sent from: (address, port). On a machine where a gateway's relay sends from an address of
|
||||
#: this host (Windows cannot send from 127.0.0.1 to it) the address cannot tell the relay from a client that came direct; its port can.
|
||||
self.quic_peer_addrs: List[Tuple[str, int]] = []
|
||||
#: The paths of the requests that were answered over HTTP/3, and over TCP.
|
||||
self.h3_requests: List[str] = []
|
||||
self.tcp_requests: List[str] = []
|
||||
@@ -185,7 +188,9 @@ class H3Server:
|
||||
def quic_event_received(self, event):
|
||||
if isinstance(event, ProtocolNegotiated):
|
||||
self._http = H3Connection(self._quic)
|
||||
server.quic_peers.append(self._quic._network_paths[0].addr[0])
|
||||
peer = self._quic._network_paths[0].addr
|
||||
server.quic_peers.append(peer[0])
|
||||
server.quic_peer_addrs.append((peer[0], peer[1]))
|
||||
if self._http is not None:
|
||||
for http_event in self._http.handle_event(event):
|
||||
if isinstance(http_event, HeadersReceived):
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"""A pytest plugin for the cold-pool hunt (scripts/cold_pool_hunt.py): the wall-clock time of what the test gateway sees.
|
||||
|
||||
python -m pytest -p _hunt_plugin ... with HUNT_EVENTS=<file>
|
||||
|
||||
Appends one JSON line per event to HUNT_EVENTS: {"t": epoch seconds, "kind": ..., ...}. `connect` is a SOCKS5 CONNECT reaching the gateway,
|
||||
`associate` a UDP ASSOCIATE reaching it, `stun` a STUN request the fake server answers, `test_start` / `test_end` bracket the test. The gateway is
|
||||
only observed: nothing it does changes.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
_LOCK = threading.Lock()
|
||||
|
||||
|
||||
def _emit(kind, **fields):
|
||||
path = os.environ.get("HUNT_EVENTS")
|
||||
if not path:
|
||||
return
|
||||
with _LOCK, open(path, "a", encoding="utf-8") as fh:
|
||||
fh.write(json.dumps(dict(t=time.time(), kind=kind, **fields)) + "\n")
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
import _socks_servers as sv
|
||||
|
||||
connect, associate = sv.Gateway._connect, sv.Gateway._associate
|
||||
|
||||
def seen_connect(self, c, host, port):
|
||||
_emit("connect", host=host, port=port)
|
||||
return connect(self, c, host, port)
|
||||
|
||||
def seen_associate(self, c):
|
||||
_emit("associate")
|
||||
return associate(self, c)
|
||||
|
||||
sv.Gateway._connect, sv.Gateway._associate = seen_connect, seen_associate
|
||||
stun = getattr(sv, "FakeStun", None)
|
||||
if stun is not None and hasattr(stun, "_serve"):
|
||||
serve = stun._serve
|
||||
|
||||
def seen_serve(self, *a, **k):
|
||||
_emit("stun_server_up")
|
||||
return serve(self, *a, **k)
|
||||
|
||||
stun._serve = seen_serve
|
||||
|
||||
|
||||
def pytest_runtest_setup(item):
|
||||
_emit("test_start", test=item.nodeid)
|
||||
|
||||
|
||||
def pytest_runtest_teardown(item):
|
||||
_emit("test_end", test=item.nodeid)
|
||||
+45
-18
@@ -50,7 +50,7 @@ import socket
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
from typing import List, Optional, Tuple
|
||||
from typing import List, Optional, Set, Tuple
|
||||
|
||||
#: The name the product's STUN probe sends through the relay. The relay maps it
|
||||
#: to the fake STUN server; every other destination is forwarded for real.
|
||||
@@ -89,12 +89,14 @@ def _recv_exact(s: socket.socket, n: int) -> bytes:
|
||||
class FakeStun:
|
||||
"""A UDP STUN server that answers every binding request with ``mapped_ip``."""
|
||||
|
||||
def __init__(self, mapped_ip: str, mapped_port: int = 40000):
|
||||
def __init__(self, mapped_ip: str, mapped_port: int = 40000, bind_host: str = "127.0.0.1"):
|
||||
self.mapped_ip = mapped_ip
|
||||
self.mapped_port = mapped_port
|
||||
self.requests = 0
|
||||
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self._sock.bind(("127.0.0.1", 0))
|
||||
# On the address the relay sends from: Windows sends neither from an address of the host to loopback (WinError 10049) nor
|
||||
# from loopback to an address of the host (10051), so a relay that leaves from the host's address needs its STUN there too.
|
||||
self._sock.bind((bind_host, 0))
|
||||
self.address: Tuple[str, int] = self._sock.getsockname()
|
||||
self._thread = threading.Thread(target=self._serve, daemon=True)
|
||||
self._thread.start()
|
||||
@@ -147,7 +149,7 @@ class Gateway:
|
||||
self.tcp_data_delay = tcp_data_delay
|
||||
self.tcp_exit = tcp_exit
|
||||
self.user, self.password = user, password
|
||||
self.stun = FakeStun(udp_exit)
|
||||
self.stun = FakeStun(udp_exit, bind_host="127.0.0.1" if exit_host.startswith("127.") else exit_host)
|
||||
#: Every CONNECT, as (host, port), in order.
|
||||
self.connects: List[Tuple[str, int]] = []
|
||||
#: Every UDP ASSOCIATE request, answered or refused.
|
||||
@@ -164,6 +166,14 @@ class Gateway:
|
||||
self.datagram_log: List[Tuple[str, int, int, float]] = []
|
||||
#: Every datagram the relay carried out, as (host, port, payload).
|
||||
self.datagrams: List[Tuple[str, int, bytes]] = []
|
||||
#: The local port of the socket each granted association sends from: what a server behind the gateway sees as the port
|
||||
#: of the relay, and what tells a datagram that went by the relay from one that came direct from this host.
|
||||
self.exit_ports: List[int] = []
|
||||
#: A datagram the relay could not send (a socket that raised): said here and in the report of a test, never mute.
|
||||
self.send_errors: List[str] = []
|
||||
#: The hosts the relay forwards a datagram to (the fake STUN server aside); None: any host. A test that sends from an
|
||||
#: address of this host keeps its lab closed: the browser's own background QUIC does not leave the machine.
|
||||
self.forward_only_to: Optional[Set[str]] = None
|
||||
self._listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self._listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self._listener.bind(("127.0.0.1", 0))
|
||||
@@ -343,19 +353,22 @@ class Gateway:
|
||||
up.close()
|
||||
|
||||
# --- the UDP side --------------------------------------------------------
|
||||
def _later(self, fn) -> None:
|
||||
"""Run ``fn`` after half the round trip (at once on loopback), ignoring a socket that is already closed."""
|
||||
def _later(self, fn, what: str = "a datagram") -> None:
|
||||
"""Run ``fn`` after half the round trip (at once on loopback). A send that fails is RECORDED in ``send_errors`` (a
|
||||
silent one hid that Windows cannot send from 127.0.0.1 to an address of its own host: WinError 10051), except on a gateway
|
||||
that is already closed."""
|
||||
def run() -> None:
|
||||
try:
|
||||
fn()
|
||||
except OSError:
|
||||
pass
|
||||
except OSError as e:
|
||||
if not self._closed:
|
||||
self.send_errors.append("%s: %s %s" % (what, type(e).__name__, e))
|
||||
threading.Timer(self.rtt / 2, run).start() if self.rtt else run()
|
||||
|
||||
def _deliver(self, relay: socket.socket, to: Tuple[str, int], host: str, port: int, payload: bytes) -> None:
|
||||
"""Wrap ``payload`` as coming from ``host``:``port`` (an IPv4 literal) and send it back to the client."""
|
||||
data = b"\x00\x00\x00\x01" + socket.inet_aton(host) + struct.pack("!H", port) + payload
|
||||
self._later(lambda: relay.sendto(data, to))
|
||||
self._later(lambda: relay.sendto(data, to), "the answer to the client")
|
||||
|
||||
def _route(self, host: str, dport: int, atyp: int, payload: bytes, out_port: int,
|
||||
answer) -> Optional[Tuple[Tuple[str, int], Optional[Tuple[str, int]]]]:
|
||||
@@ -371,6 +384,8 @@ class Gateway:
|
||||
# A real server answers from the address it was asked at; the fake STUN server is mapped, so its reply is
|
||||
# reported as from the asked address (only when that was a literal: a name has no address to report).
|
||||
return self.stun.address, ((host, dport) if atyp == 1 else None)
|
||||
if self.forward_only_to is not None and host not in self.forward_only_to:
|
||||
return None
|
||||
return (host, dport), None
|
||||
|
||||
def _associate(self, c: socket.socket) -> None:
|
||||
@@ -384,6 +399,12 @@ class Gateway:
|
||||
relay.bind((self.relay_host, 0))
|
||||
out = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
out.bind((self.exit_host, 0))
|
||||
self.exit_ports.append(out.getsockname()[1])
|
||||
if hasattr(socket, "SIO_UDP_CONNRESET"):
|
||||
# Windows: an ICMP "port unreachable" to a send makes the NEXT recvfrom raise WinError 10054 and, uncaught, ends the
|
||||
# thread that reads: a relay that stops carrying answers because one datagram found nobody. Off, as a real relay has it.
|
||||
for sock in (relay, out):
|
||||
sock.ioctl(socket.SIO_UDP_CONNRESET, False)
|
||||
client: List[Optional[Tuple[str, int]]] = [None]
|
||||
#: Where a mapped destination really is -> the address the client is told it answered from.
|
||||
asked_at: dict = {}
|
||||
@@ -397,6 +418,8 @@ class Gateway:
|
||||
while True:
|
||||
try:
|
||||
d, peer = relay.recvfrom(65536)
|
||||
except ConnectionResetError:
|
||||
continue
|
||||
except OSError:
|
||||
return
|
||||
if len(d) < 10 or d[2] != 0:
|
||||
@@ -420,12 +443,14 @@ class Gateway:
|
||||
target, reported = routed
|
||||
if reported is not None:
|
||||
asked_at[target] = reported
|
||||
self._later(lambda p=payload, t=target: out.sendto(p, t))
|
||||
self._later(lambda p=payload, t=target: out.sendto(p, t), "the datagram to %s:%d" % target)
|
||||
|
||||
def outbound() -> None: # world -> client
|
||||
while True:
|
||||
try:
|
||||
d, src = out.recvfrom(65536)
|
||||
except ConnectionResetError:
|
||||
continue
|
||||
except OSError:
|
||||
return
|
||||
if client[0] is None:
|
||||
@@ -453,33 +478,35 @@ OTHER_EXIT = "198.51.100.4"
|
||||
|
||||
|
||||
def coherent(*, exit_ip: str = EXIT, user: Optional[str] = None,
|
||||
password: Optional[str] = None, relay_host: str = "127.0.0.1", rtt_ms: int = 0) -> Gateway:
|
||||
password: Optional[str] = None, relay_host: str = "127.0.0.1", rtt_ms: int = 0,
|
||||
exit_host: str = "127.0.0.1") -> Gateway:
|
||||
"""TCP and UDP both work, and both leave from ``exit_ip``."""
|
||||
return Gateway(udp="relay", tcp_exit=exit_ip, udp_exit=exit_ip,
|
||||
user=user, password=password, relay_host=relay_host, rtt_ms=rtt_ms)
|
||||
user=user, password=password, relay_host=relay_host, rtt_ms=rtt_ms, exit_host=exit_host)
|
||||
|
||||
|
||||
def tcp_only(*, exit_ip: str = EXIT, user: Optional[str] = None,
|
||||
password: Optional[str] = None, relay_host: str = "127.0.0.1") -> Gateway:
|
||||
password: Optional[str] = None, relay_host: str = "127.0.0.1", exit_host: str = "127.0.0.1") -> Gateway:
|
||||
"""TCP works; UDP ASSOCIATE is refused with reply code 7."""
|
||||
return Gateway(udp="refuse", tcp_exit=exit_ip, udp_exit=exit_ip,
|
||||
user=user, password=password, relay_host=relay_host)
|
||||
user=user, password=password, relay_host=relay_host, exit_host=exit_host)
|
||||
|
||||
|
||||
def mismatched(*, tcp_exit: str = EXIT, udp_exit: str = OTHER_EXIT,
|
||||
user: Optional[str] = None, password: Optional[str] = None, relay_host: str = "127.0.0.1") -> Gateway:
|
||||
user: Optional[str] = None, password: Optional[str] = None, relay_host: str = "127.0.0.1",
|
||||
exit_host: str = "127.0.0.1") -> Gateway:
|
||||
"""UDP is granted and STUN answers, with an address that is not the TCP exit."""
|
||||
assert udp_exit != tcp_exit
|
||||
return Gateway(udp="relay", tcp_exit=tcp_exit, udp_exit=udp_exit,
|
||||
user=user, password=password, relay_host=relay_host)
|
||||
user=user, password=password, relay_host=relay_host, exit_host=exit_host)
|
||||
|
||||
|
||||
def silent_udp(*, exit_ip: str = EXIT, user: Optional[str] = None, password: Optional[str] = None,
|
||||
relay_host: str = "127.0.0.1") -> Gateway:
|
||||
relay_host: str = "127.0.0.1", exit_host: str = "127.0.0.1") -> Gateway:
|
||||
"""TCP works and UDP ASSOCIATE is granted, but no STUN request is ever answered: the core's measurement is
|
||||
``unmeasured``."""
|
||||
return Gateway(udp="relay", tcp_exit=exit_ip, udp_exit=exit_ip, user=user, password=password,
|
||||
relay_host=relay_host, stun_answers=False)
|
||||
relay_host=relay_host, exit_host=exit_host, stun_answers=False)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -77,7 +77,13 @@ def _gateway(road: str, host: str):
|
||||
make = {"socks5_coherent": coherent, "socks5_no_udp": tcp_only, "socks5_mismatched": mismatched,
|
||||
"socks5_unmeasured": silent_udp}[road]
|
||||
# The relay sits on the address of this host, as a real gateway's does: the engine's UDP sockets are bound to an interface.
|
||||
return make(user="alice", password="s3cret", relay_host=host)
|
||||
# Its datagrams leave from that address too, on every system: Windows cannot send from 127.0.0.1 to an address of its own host
|
||||
# (WinError 10051, which this test once read as "the server saw QUIC from []"). The relay is told from a client that came direct
|
||||
# by the PORT it sends from (``gateway.exit_ports``), and it forwards only to this host: the browser's own QUIC to the Internet
|
||||
# stays in the lab.
|
||||
gateway = make(user="alice", password="s3cret", relay_host=host, exit_host=host)
|
||||
gateway.forward_only_to = {host}
|
||||
return gateway
|
||||
|
||||
|
||||
def _visits(road, server, monkeypatch, discover, **launch):
|
||||
@@ -113,6 +119,8 @@ def _report(road, protocols, walls, server, gateway=None):
|
||||
server.tcp_alpn, server.quic_peers))
|
||||
if gateway is not None:
|
||||
said += "; datagrams the relay carried: %s" % sorted({(h, p) for h, p, _data in gateway.datagrams})
|
||||
if gateway.send_errors:
|
||||
said += "; sends of the relay that failed: %s" % sorted(set(gateway.send_errors))
|
||||
return said
|
||||
|
||||
|
||||
@@ -144,8 +152,10 @@ def test_a_page_behind_a_gateway_that_relays_udp_starts_on_h2_reaches_h3_within_
|
||||
problems = judge_visits("socks5_coherent", protocols, walls)
|
||||
assert not problems, "; ".join(problems) + ". " + said
|
||||
assert carried, "the QUIC datagrams did not go by the relay of the gateway. " + said
|
||||
assert server.quic_peers and set(server.quic_peers) == {"127.0.0.1"}, (
|
||||
"the QUIC server saw %s: only the relay of the gateway (127.0.0.1) may reach it. %s" % (server.quic_peers, said))
|
||||
assert not gateway.send_errors, "the relay of the gateway could not send. " + said
|
||||
assert server.quic_peer_addrs and {a for a, _p in server.quic_peer_addrs} == {host} and {p for _a, p in server.quic_peer_addrs} <= set(gateway.exit_ports), (
|
||||
"the QUIC server saw %s: only the relay of the gateway (%s, from the ports %s) may reach it. %s" % (
|
||||
server.quic_peer_addrs, host, gateway.exit_ports, said))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("road", ["socks5_no_udp", "socks5_mismatched", "socks5_unmeasured"])
|
||||
|
||||
@@ -18,7 +18,8 @@ import pytest
|
||||
|
||||
from _servers import LocalServer
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
# Bound to the engine that carries the UDP line: red on firefox-61/62 (the engine fix is in the 63): skips on the published engine; runs on the candidate.
|
||||
pytestmark = [pytest.mark.e2e, pytest.mark.usefixtures("the_udp_line")]
|
||||
|
||||
|
||||
def _stock_client(module):
|
||||
|
||||
@@ -26,7 +26,8 @@ from _socks_servers import STUN_NUMBER, STUN_PORT, coherent
|
||||
from _udp_line import egress_by_proxy
|
||||
from test_webrtc_realness import _e2e_binary, _launch # noqa: F401
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
# Bound to the engine that carries the UDP line: red before the UDP line (firefox-63): skips on the published engine; runs on the candidate.
|
||||
pytestmark = [pytest.mark.e2e, pytest.mark.usefixtures("the_udp_line")]
|
||||
|
||||
RTT_MS = 130
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import socket
|
||||
import ssl
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -262,3 +263,98 @@ def test_the_fake_doh_never_serves_a_type_65_with_data_and_the_check_reads_what_
|
||||
assert problems and "site.test" in problems[0]
|
||||
finally:
|
||||
server.close()
|
||||
|
||||
|
||||
# -- the relay of the gateway: a send that fails is said, and a relay that leaves from the host's address works ----------------
|
||||
# The e2e once read "the server saw QUIC from []" on Windows: the relay sent from 127.0.0.1 to an address of its own host (WinError 10051),
|
||||
# the send ran in a timer that ignored every OSError, and the relay had still logged the datagram as carried.
|
||||
def _associate(gateway):
|
||||
"""A SOCKS5 UDP ASSOCIATE on ``gateway`` with no credentials: the control connection (kept open) and the relay's address."""
|
||||
control = socket.create_connection(("127.0.0.1", gateway.port), timeout=5)
|
||||
control.sendall(b"\x05\x01\x00")
|
||||
assert control.recv(2) == b"\x05\x00"
|
||||
control.sendall(b"\x05\x03\x00\x01\x00\x00\x00\x00\x00\x00")
|
||||
reply = b""
|
||||
while len(reply) < 10:
|
||||
reply += control.recv(10 - len(reply))
|
||||
assert reply[1] == 0, "the association was refused: %r" % reply
|
||||
return control, (socket.inet_ntoa(reply[4:8]), int.from_bytes(reply[8:10], "big"))
|
||||
|
||||
|
||||
def _wrapped(host, port, payload):
|
||||
return b"\x00\x00\x00\x01" + socket.inet_aton(host) + port.to_bytes(2, "big") + payload
|
||||
|
||||
|
||||
def test_a_send_the_relay_cannot_make_is_recorded_and_the_report_of_the_e2e_says_it():
|
||||
import test_http3_through_the_proxy_e2e as e2e
|
||||
from _socks_servers import coherent
|
||||
|
||||
with coherent() as gateway:
|
||||
assert gateway.send_errors == []
|
||||
|
||||
def refused():
|
||||
raise OSError(10051, "A socket operation was attempted to an unreachable network")
|
||||
|
||||
gateway._later(refused, "the datagram to 203.0.113.9:443")
|
||||
assert len(gateway.send_errors) == 1 and gateway.send_errors[0].startswith("the datagram to 203.0.113.9:443: OSError")
|
||||
class Server:
|
||||
tcp_alpn, quic_peers = ["h2"], []
|
||||
said = e2e._report("socks5_coherent", ["h2"], [1], Server, gateway)
|
||||
assert "sends of the relay that failed" in said and "10051" in said
|
||||
|
||||
|
||||
def test_a_relay_that_leaves_from_the_address_of_the_host_reaches_a_server_on_it_and_is_told_by_its_port():
|
||||
from _host_address import this_host_address
|
||||
from _socks_servers import coherent
|
||||
|
||||
host = this_host_address()
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
server.bind((host, 0))
|
||||
server.settimeout(5)
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
client.bind((host, 0)) # an engine's UDP sockets are bound to an interface
|
||||
with coherent(relay_host=host, exit_host=host) as gateway:
|
||||
gateway.forward_only_to = {host}
|
||||
control, relay = _associate(gateway)
|
||||
try:
|
||||
client.sendto(_wrapped(host, server.getsockname()[1], b"quic" * 300), relay)
|
||||
data, peer = server.recvfrom(4096)
|
||||
assert data == b"quic" * 300
|
||||
assert peer[0] == host and peer[1] in gateway.exit_ports, "the relay's port is not in exit_ports: %s" % (gateway.exit_ports,)
|
||||
direct = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
direct.bind((host, 0))
|
||||
direct.sendto(b"direct", server.getsockname())
|
||||
data, peer = server.recvfrom(4096)
|
||||
assert data == b"direct" and peer[1] not in gateway.exit_ports, "a client that came direct looks like the relay"
|
||||
direct.close()
|
||||
# the browser's own QUIC to a public address is recorded as carried and goes nowhere: the lab stays closed
|
||||
client.sendto(_wrapped("203.0.113.9", 443, b"background"), relay)
|
||||
time.sleep(0.3)
|
||||
assert ("203.0.113.9", 443) in {(h, p) for h, p, _d in gateway.datagrams}
|
||||
assert gateway.send_errors == [], gateway.send_errors
|
||||
finally:
|
||||
control.close()
|
||||
client.close()
|
||||
server.close()
|
||||
|
||||
|
||||
def test_the_fake_stun_of_a_relay_that_leaves_from_the_address_of_the_host_answers_through_the_relay():
|
||||
from _host_address import this_host_address
|
||||
from _socks_servers import MEASURE_NUMBER, STUN_PORT, coherent
|
||||
|
||||
host = this_host_address()
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
client.bind((host, 0))
|
||||
client.settimeout(5)
|
||||
with coherent(relay_host=host, exit_host=host) as gateway:
|
||||
control, relay = _associate(gateway)
|
||||
try:
|
||||
request = b"\x00\x01\x00\x00\x21\x12\xa4\x42" + b"txid-of-12by"
|
||||
client.sendto(_wrapped(MEASURE_NUMBER, STUN_PORT, request), relay)
|
||||
answer, _peer = client.recvfrom(4096)
|
||||
assert answer[3] == 1 and socket.inet_ntoa(answer[4:8]) == MEASURE_NUMBER and int.from_bytes(answer[8:10], "big") == STUN_PORT
|
||||
assert answer[10:12] == b"\x01\x01", "not a STUN Binding success: %r" % answer[10:20]
|
||||
assert gateway.send_errors == [], gateway.send_errors
|
||||
finally:
|
||||
control.close()
|
||||
client.close()
|
||||
@@ -27,7 +27,8 @@ import pytest
|
||||
from _socks_servers import Socks5TcpOnly
|
||||
from test_webrtc_realness import _e2e_binary, _launch # noqa: F401
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
# Bound to the engine that carries the UDP line: red before the declared network (firefox-63): skips on the published engine; runs on the candidate.
|
||||
pytestmark = [pytest.mark.e2e, pytest.mark.usefixtures("the_udp_line")]
|
||||
|
||||
DECLARED = "v4=192.168.31.7;v6=0;p6="
|
||||
N_MS = 800
|
||||
|
||||
Reference in new issue
Block a user