45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from vpn_egressctl.renderer_1_14_0 import render_bytes
|
|
from vpn_egressctl.uri import parse_hysteria2_uri
|
|
from vpn_egressctl.version import probe_version
|
|
|
|
from tests.helpers import make_policy
|
|
|
|
|
|
class RealSingBoxIntegrationTests(unittest.TestCase):
|
|
@unittest.skipUnless(os.environ.get("SING_BOX_1_14_0"), "real sing-box 1.14.0 binary is not configured")
|
|
def test_real_binary_accepts_golden_configs(self) -> None:
|
|
binary = os.environ["SING_BOX_1_14_0"]
|
|
version = probe_version(binary)
|
|
self.assertEqual(version.version, "1.14.0")
|
|
self.assertIn("with_quic", version.tags)
|
|
self.assertIn("with_gvisor", version.tags)
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
policy = make_policy(root)
|
|
command = "check" if "linux/" in version.environment else "format"
|
|
for obfs in ("gecko", "salamander"):
|
|
with self.subTest(obfs=obfs):
|
|
endpoint = parse_hysteria2_uri(
|
|
f"hysteria2://auth@example.com:443?obfs={obfs}&obfs-password=obfs"
|
|
)
|
|
config = root / f"config-{obfs}.json"
|
|
config.write_bytes(render_bytes(policy, endpoint))
|
|
result = subprocess.run(
|
|
[binary, command, "-c", str(config)],
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|