66 lines
2 KiB
Python
66 lines
2 KiB
Python
import asyncio
|
|
|
|
import pytest
|
|
|
|
from app.core.errors import UnsupportedEngineError
|
|
from app.core.native import NativeEngineBackend
|
|
from app.models import EngineKind, ProxyAccess, ProxySettings, RunMode, RuntimeRequest
|
|
|
|
|
|
class Bridge:
|
|
def __init__(self) -> None:
|
|
self.calls: list[str] = []
|
|
|
|
async def get_runtime_state(self):
|
|
return {"state": "stopped"}
|
|
|
|
async def start_vpn(self, payload):
|
|
self.calls.append("start_vpn")
|
|
return {"state": "starting"}
|
|
|
|
async def start_proxy(self, payload):
|
|
self.calls.append("start_proxy")
|
|
return {"state": "starting"}
|
|
|
|
async def start_hotspot_proxy(self, payload):
|
|
self.calls.append("start_hotspot_proxy")
|
|
return {"state": "starting"}
|
|
|
|
|
|
def request(mode: RunMode, access: ProxyAccess = ProxyAccess.LOCAL) -> RuntimeRequest:
|
|
return RuntimeRequest(
|
|
engine=EngineKind.SIGNBOX,
|
|
mode=mode,
|
|
profile_id="profile",
|
|
proxy=ProxySettings(access=access),
|
|
)
|
|
|
|
|
|
def test_android_signbox_capabilities_match_pinned_libbox() -> None:
|
|
backend = NativeEngineBackend(EngineKind.SIGNBOX, Bridge())
|
|
assert backend.capabilities.supports_vpn
|
|
assert backend.capabilities.supports_proxy
|
|
assert backend.capabilities.supports_both
|
|
assert backend.capabilities.supports_socks
|
|
assert backend.capabilities.supports_http
|
|
|
|
|
|
def test_local_both_starts_one_vpn_owned_core() -> None:
|
|
async def run() -> None:
|
|
bridge = Bridge()
|
|
backend = NativeEngineBackend(EngineKind.SIGNBOX, bridge)
|
|
await backend.start(request(RunMode.BOTH))
|
|
assert bridge.calls == ["start_vpn"]
|
|
|
|
asyncio.run(run())
|
|
|
|
|
|
def test_hotspot_both_fails_before_starting_two_cores() -> None:
|
|
async def run() -> None:
|
|
bridge = Bridge()
|
|
backend = NativeEngineBackend(EngineKind.SIGNBOX, bridge)
|
|
with pytest.raises(UnsupportedEngineError):
|
|
await backend.start(request(RunMode.BOTH, ProxyAccess.HOTSPOT))
|
|
assert bridge.calls == []
|
|
|
|
asyncio.run(run())
|