zapret-kvn/tests/test_xray_plain_transport.py
loop-uh 9f0dca6f89
Some checks failed
Windows project source guards / test (push) Failing after 11s
Go 1.27.3 toolchain pin; plain VLESS/Trojan to a public address gets a clear reason
Xray 26.11 refuses VLESS/Trojan without TLS/Reality/encryption unless the server address is private.
The pool pre-check now reports that reason for such a node, mirroring Xray's rule, instead of relying on
the start failing first. The core lock moves the Amnezia build toolchain to go1.27.3 (needed by the
Android Xray v26.11.9 build; the pair shares one toolchain).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:33:15 -05:00

44 lines
2.4 KiB
Python

from __future__ import annotations
import unittest
from xray_fluent.engines.xray_outbound_compat import xray_outbound_incompatibility
def _vless(address: str, *, security: str = "none", encryption: str = "none", flat: bool = False) -> dict:
user = {"id": "11111111-1111-1111-1111-111111111111", "encryption": encryption}
settings = {"address": address, "port": 443, **user} if flat else {"vnext": [{"address": address, "port": 443, "users": [user]}]}
return {"protocol": "vless", "settings": settings, "streamSettings": {"network": "ws", "security": security}}
class PlainTransportTests(unittest.TestCase):
"""Xray 26.11 refuses plain VLESS/Trojan to a public address (field check 2026-11-09)."""
def test_public_domain_and_ip_without_security_are_flagged(self) -> None:
for address in ("vpn.example.net", "203.0.113.7", "2001:4860::1"):
with self.subTest(address=address):
self.assertIn("без TLS", xray_outbound_incompatibility(_vless(address)))
def test_private_addresses_are_allowed(self) -> None:
for address in ("192.168.1.10", "10.0.0.5", "172.20.1.1", "127.0.0.1", "169.254.1.1", "fd00::1",
"router", "nas.lan", "vpn.example", "host.internal", "x.home.arpa", "localhost"):
with self.subTest(address=address):
self.assertEqual(xray_outbound_incompatibility(_vless(address)), "")
def test_tls_reality_or_encryption_make_a_public_address_fine(self) -> None:
self.assertEqual(xray_outbound_incompatibility(_vless("vpn.example.net", security="tls")), "")
self.assertEqual(xray_outbound_incompatibility(_vless("vpn.example.net", security="reality")), "")
self.assertEqual(xray_outbound_incompatibility(_vless("vpn.example.net", encryption="mlkem768x25519plus.native.0rtt.abc")), "")
def test_flat_settings_form_is_checked_too(self) -> None:
self.assertIn("VLESS", xray_outbound_incompatibility(_vless("vpn.example.net", flat=True)))
def test_trojan_without_tls_is_flagged_and_other_protocols_are_not(self) -> None:
trojan = {"protocol": "trojan", "settings": {"servers": [{"address": "vpn.example.net", "port": 443}]},
"streamSettings": {"security": "none"}}
self.assertIn("TROJAN", xray_outbound_incompatibility(trojan))
self.assertEqual(xray_outbound_incompatibility({"protocol": "vmess", "settings": {}}), "")
if __name__ == "__main__":
unittest.main()