fix(cli): make Desktop attachment checks portable

Avoid a false-positive session-prefix match in the architecture guard without changing endpoint validation. Pass a null pointer as an integer to the native Windows pipe fixture, and name oversized-input cases explicitly so pytest does not exceed the Windows environment-variable limit.

Keep the real owner-authenticated roundtrip and oversized-payload assertions. Local CLI, architecture and gateway checks pass; native Windows verification is rerun in CI.
This commit is contained in:
Xubin Ren committed 2026-09-08 10:04:15 +08:00
1 parent d641026fc8
commit ddf095938e
3 files changed
+11 -7

No files matched your search

+4 -4
View File
@@ -45,8 +45,8 @@ def _connection(target: DesktopTarget, gateway_id: str | None = None) -> dict[st
uuid.UUID(identity)
except ValueError as exc:
raise DesktopTargetError("Invalid gateway identity") from exc
api = _endpoint(value.get("apiUrl"), websocket=False)
ws = _endpoint(value.get("wsUrl"), websocket=True)
api = _endpoint(value.get("apiUrl"), use_ws=False)
ws = _endpoint(value.get("wsUrl"), use_ws=True)
if (api.hostname, api.port or 80) != (ws.hostname, ws.port or 80) or api.path not in {"", "/"}:
raise DesktopTargetError("Terminal endpoints must share the same loopback listener")
for key in ("wsToken", "apiToken"):
@@ -61,7 +61,7 @@ def _connection(target: DesktopTarget, gateway_id: str | None = None) -> dict[st
)}
def _endpoint(value: object, *, websocket: bool):
def _endpoint(value: object, *, use_ws: bool):
if not isinstance(value, str) or "\\" in value or any(
ord(char) < 33 or ord(char) == 127 for char in value
):
@@ -72,7 +72,7 @@ def _endpoint(value: object, *, websocket: bool):
except ValueError as exc:
raise DesktopTargetError("Invalid terminal endpoint") from exc
if (
parsed.scheme != ("ws" if websocket else "http")
parsed.scheme != ("ws" if use_ws else "http")
or parsed.hostname not in {"127.0.0.1", "::1"}
or port == 0
or parsed.username is not None or parsed.password is not None
+1 -1
View File
@@ -133,7 +133,7 @@ def test_native_windows_pipe_roundtrip():
rf"\\.\pipe\{address}",
winapi.PIPE_ACCESS_DUPLEX | winapi.FILE_FLAG_OVERLAPPED,
0, # PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT
1, 8192, 8192, 1000, None,
1, 8192, 8192, 1000, 0,
)
connected = winapi.ConnectNamedPipe(handle, overlapped=True)
received = []
+6 -2
View File
@@ -68,7 +68,8 @@ def test_windows_uses_pipe_not_argv_or_browser_override(launcher, capsys, url):
@pytest.mark.parametrize("url", [
"javascript:alert(1)", "file:///tmp/secret", "http:///", "http://[invalid/",
"http://localhost/\nsecret", "http://localhost/\rsecret", "http://localhost/\x00",
"http://localhost/\ud800", "http://localhost/" + "x" * browser._MAX_URL_BYTES,
"http://localhost/\ud800",
pytest.param("http://localhost/" + "x" * browser._MAX_URL_BYTES, id="oversized-url"),
])
def test_invalid_input_does_not_spawn_a_helper(launcher, url, capsys):
_, spawn = launcher
@@ -205,7 +206,10 @@ def test_helper_owns_file_until_expiry_and_cleans_every_exit(helper_file, monkey
assert ("retained" in events) == (failure in {None, "interrupted"})
@pytest.mark.parametrize("data", [b"", b"http://localhost/", b"x" * 65537 + b"\n"])
@pytest.mark.parametrize("data", [
b"", b"http://localhost/",
pytest.param(b"x" * 65537 + b"\n", id="oversized-message"),
])
def test_helper_rejects_incomplete_or_oversized_pipe_message(helper_file, data):
assert browser._serve(io.BytesIO(data), io.BytesIO()) == 1
assert helper_file == []