feat: add declarative sing-box egress control plane
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from vpn_egressctl.renderer_1_13_19 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_13_19"), "real sing-box 1.13.19 binary is not configured")
|
||||
def test_real_binary_accepts_golden_config(self) -> None:
|
||||
binary = os.environ["SING_BOX_1_13_19"]
|
||||
version = probe_version(binary)
|
||||
self.assertEqual(version.version, "1.13.19")
|
||||
self.assertIn("with_quic", version.tags)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
policy = make_policy(root)
|
||||
endpoint = parse_hysteria2_uri(
|
||||
"hysteria2://auth@example.com:443?obfs=salamander&obfs-password=obfs"
|
||||
)
|
||||
config = root / "config.json"
|
||||
config.write_bytes(render_bytes(policy, endpoint))
|
||||
command = "check" if "linux/" in version.environment else "format"
|
||||
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()
|
||||
Reference in New Issue
Block a user