Files
rw-visualizer/backend/tests/fixtures.py
T
2026-12-02 12:43:23 +05:00

97 lines
5.2 KiB
Python

"""Фикстура сети: вход RU-01 (профиль Bridge) + 6 выходных нод (профиль Default)."""
SC = ["domain:soundcloud.com", "domain:sndcdn.com", "domain:soundcloud.cloud"]
BRIDGE_IPS = ["100.106.180.60", "100.106.64.26", "100.106.214.118",
"100.106.134.18", "100.106.36.222", "100.106.221.7"]
EXIT_NAMES = ["FR-01", "NL-01", "FI-01", "NL-04", "CH-01", "BR-01"]
BRIDGE_UUID = "aaaaaaaa-0000-0000-0000-000000000001"
DEFAULT_UUID = "bbbbbbbb-0000-0000-0000-000000000002"
INB_BRIDGE = "inb-bridge" # RU_NODE_IN
INB_VLESS = "inb-def-vless" # DEFAULT_IN, 443
INB_SS = "inb-def-ss" # BRIDGE_SS_IN, 9999
def bridge_profile() -> dict:
rules = [
{"port": 25, "outboundTag": "BLOCK"},
{"ip": ["geoip:private"], "outboundTag": "BLOCK"},
{"domain": ["geosite:private"], "outboundTag": "BLOCK"},
{"protocol": ["bittorrent"], "outboundTag": "BLOCK"},
{"domain": ["geosite:category-ru", "domain:ru"], "outboundTag": "DIRECT"},
{"ip": ["geoip:ru"], "outboundTag": "DIRECT"},
*[{"vlessRoute": i, "outboundTag": f"BRIDGE_{i}"} for i in range(1, 7)],
{"vlessRoute": 7, "balancerTag": "BRIDGE_AUTO"},
{"inboundTag": ["RU_NODE_IN"], "balancerTag": "BRIDGE_AUTO"},
*[{"domain": SC, "vlessRoute": 7 + i, "outboundTag": f"BRIDGE_{i}"} for i in range(1, 7)],
{"domain": SC, "vlessRoute": 14, "balancerTag": "BRIDGE_AUTO"},
{"vlessRoute": "8-14", "balancerTag": "BRIDGE_AUTO"},
]
config = {
"inbounds": [{"tag": "RU_NODE_IN", "port": 443, "protocol": "vless",
"streamSettings": {"realitySettings": {"privateKey": "SECRET-KEY"}}}],
"outbounds": [{"tag": "DIRECT", "protocol": "freedom"},
{"tag": "BLOCK", "protocol": "blackhole"}] + [
{"tag": f"BRIDGE_{i + 1}", "protocol": "shadowsocks",
"settings": {"servers": [{"address": ip, "port": 9999, "password": "SECRET-PASS"}]}}
for i, ip in enumerate(BRIDGE_IPS)],
"routing": {"rules": rules, "balancers": [
{"tag": "BRIDGE_AUTO", "selector": ["BRIDGE_"], "strategy": {"type": "leastPing"},
"fallbackTag": "BRIDGE_1"}]},
}
return {"uuid": BRIDGE_UUID, "name": "BridgeOverNetbird", "config": config,
"inbounds": [{"uuid": INB_BRIDGE, "tag": "RU_NODE_IN", "type": "vless", "port": 443}]}
def default_profile() -> dict:
config = {
"inbounds": [
{"tag": "DEFAULT_IN", "port": 443, "protocol": "vless"},
{"tag": "BRIDGE_SS_IN", "port": 9999, "protocol": "shadowsocks",
"settings": {"password": "SECRET-SS"}},
],
"outbounds": [{"tag": "DIRECT", "protocol": "freedom"}, {"tag": "BLOCK", "protocol": "blackhole"}],
"routing": {"rules": [
{"protocol": ["bittorrent"], "outboundTag": "BLOCK"},
{"ip": ["geoip:private"], "outboundTag": "BLOCK"},
]},
}
return {"uuid": DEFAULT_UUID, "name": "Default", "config": config, "inbounds": [
{"uuid": INB_VLESS, "tag": "DEFAULT_IN", "type": "vless", "port": 443},
{"uuid": INB_SS, "tag": "BRIDGE_SS_IN", "type": "shadowsocks", "port": 9999}]}
def make_profiles() -> list[dict]:
return [default_profile(), bridge_profile()]
def make_nodes() -> list[dict]:
ru = {"uuid": "n-ru", "name": "RU-01", "address": "100.106.247.44", "countryCode": "RU",
"isConnected": True, "isDisabled": False,
"ips": [{"ip": "91.201.43.187", "status": "OUTBOUND"}, {"ip": "100.106.247.44", "status": "MANAGEMENT"}],
"configProfile": {"activeConfigProfileUuid": BRIDGE_UUID, "activeInbounds": [{"uuid": INB_BRIDGE}]},
"system": {"info": {"networkInterfaces": ["lo", "wt0"]}}}
exits = [{"uuid": f"n-{i}", "name": n, "address": ip, "countryCode": "XX",
"isConnected": True, "isDisabled": False,
"ips": [{"ip": ip, "status": "MANAGEMENT"}, {"ip": f"1.1.1.{i}", "status": "OUTBOUND"}],
"configProfile": {"activeConfigProfileUuid": DEFAULT_UUID,
"activeInbounds": [{"uuid": INB_VLESS}, {"uuid": INB_SS}]},
"system": {"info": {"networkInterfaces": ["lo", "wt0"]}}}
for i, (n, ip) in enumerate(zip(EXIT_NAMES, BRIDGE_IPS))]
unused = {"uuid": "n-us", "name": "US-01", "address": "78.153.155.226", "ips": [],
"configProfile": {"activeConfigProfileUuid": None, "activeInbounds": []}, "system": None}
return [ru, *exits, unused]
def make_hosts() -> list[dict]:
def host(uuid, remark, node, inbound, route=None):
return {"uuid": uuid, "remark": remark, "address": "node-ru.example", "port": 443,
"vlessRouteId": route, "nodes": [node],
"inbound": {"configProfileUuid": "x", "configProfileInboundUuid": inbound}}
return [
host("h3", "Bridge-Ivi", "n-ru", INB_BRIDGE, 3),
host("h7", "Bridge-Auto", "n-ru", INB_BRIDGE, 7),
host("h8", "Bridge-Mira-SC", "n-ru", INB_BRIDGE, 8),
host("hn", "Bridge-NoRoute", "n-ru", INB_BRIDGE, None),
host("hd", "Direct-FI", "n-2", INB_VLESS), # прямое подключение к выходной ноде
]