ps-core::links ports upstream's proxy_url_parsers.py and proxy_parsing.py: every scheme, each backend's refusals, XRay rendering, subscription decoding, tags and the server checks. Upstream's build-outbound tests are ported case for case, and tools/parity/links.py runs ~750 links through both implementations: no differences. config::privileged_changes names the edits only an administrator may make: anything that runs a program, passes arguments through, or names a local file, since the service runs as LocalSystem. Names that become paths or service names are validated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
437 lines
21 KiB
Rust
437 lines
21 KiB
Rust
//! Upstream's `scripts/test-build-outbound.py`, case for case.
|
|
|
|
use base64::Engine;
|
|
use base64::engine::general_purpose::{STANDARD, URL_SAFE_NO_PAD};
|
|
use serde_json::{Value, json};
|
|
|
|
use super::*;
|
|
|
|
fn sing(url: &str) -> Value {
|
|
build_outbound(url, "test-outbound", LinkBackend::SingBox).unwrap_or_else(|e| panic!("{url}: {e}"))
|
|
}
|
|
|
|
fn xray(url: &str) -> Value {
|
|
build_outbound(url, "test-outbound", LinkBackend::Xray).unwrap_or_else(|e| panic!("{url}: {e}"))
|
|
}
|
|
|
|
fn err(url: &str, backend: LinkBackend) -> String {
|
|
match build_outbound(url, "test-outbound", backend) {
|
|
Ok(ob) => panic!("{url} ({}) parsed: {ob}", backend.as_str()),
|
|
Err(e) => e.to_string(),
|
|
}
|
|
}
|
|
|
|
fn vmess_url(extra: Value) -> String {
|
|
let mut body = json!({ "add": "example.com", "port": 443, "id": "uuid", "net": "tcp" });
|
|
for (k, v) in extra.as_object().unwrap() {
|
|
body[k] = v.clone();
|
|
}
|
|
format!("vmess://{}", STANDARD.encode(body.to_string()))
|
|
}
|
|
|
|
const PBK: &str = "SbVKOEMjK0sIlbwg4akyBg5mL5KZwwB-ed4eEE7YnRc";
|
|
|
|
#[test]
|
|
fn vless_reality() {
|
|
let ob = sing(&format!(
|
|
"vless://uuid@example.com:443?security=reality&pbk={PBK}&fp=chrome&sni=cdn.example.com&sid=abcd"
|
|
));
|
|
assert_eq!(ob["type"], "vless");
|
|
assert_eq!(ob["server"], "example.com");
|
|
assert_eq!(ob["tls"]["reality"]["public_key"], PBK);
|
|
}
|
|
|
|
#[test]
|
|
fn vless_reality_germany_main_shape() {
|
|
let url = format!(
|
|
"vless://uuid@example.com:443?type=tcp&security=reality&pbk={PBK}&fp=qq&sni=last.fm&sid=8a54\
|
|
&spx=%2F-%2Fen%2Fgp%2Fbestsellers&flow=xtls-rprx-vision&encryption=none"
|
|
);
|
|
let ob = sing(&url);
|
|
assert_eq!(ob["server_port"], 443);
|
|
assert_eq!(ob["flow"], "xtls-rprx-vision");
|
|
assert_eq!(ob["tls"]["server_name"], "last.fm");
|
|
assert_eq!(ob["tls"]["utls"]["fingerprint"], "qq");
|
|
assert_eq!(ob["tls"]["reality"]["short_id"], "8a54");
|
|
assert!(ob["tls"]["reality"].get("spider_x").is_none());
|
|
assert!(ob.get("transport").is_none());
|
|
|
|
let ob = xray(&url);
|
|
assert_eq!(ob["protocol"], "vless");
|
|
assert_eq!(ob["settings"]["address"], "example.com");
|
|
assert_eq!(ob["settings"]["flow"], "xtls-rprx-vision");
|
|
assert_eq!(ob["streamSettings"]["network"], "raw");
|
|
assert_eq!(ob["streamSettings"]["sockopt"]["domainStrategy"], "UseIP");
|
|
assert_eq!(ob["streamSettings"]["realitySettings"]["serverName"], "last.fm");
|
|
assert_eq!(ob["streamSettings"]["realitySettings"]["fingerprint"], "qq");
|
|
assert_eq!(ob["streamSettings"]["realitySettings"]["spiderX"], "/-/en/gp/bestsellers");
|
|
}
|
|
|
|
#[test]
|
|
fn vless_raw_transport_is_tcp() {
|
|
let ob = sing(&format!("vless://uuid@example.com:443?type=raw&security=reality&pbk={PBK}&fp=chrome&sni=cdn.example.com"));
|
|
assert!(ob.get("transport").is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn at_sign_in_query_does_not_eat_the_host() {
|
|
let ob = sing(&format!(
|
|
"vless://uuid@example.com:443?type=tcp&security=reality&pbk={PBK}&fp=chrome&sni=cdn.example.com&Telegram=@somechannel,@somechannel"
|
|
));
|
|
assert_eq!(ob["server"], "example.com");
|
|
assert_eq!(ob["server_port"], 443);
|
|
}
|
|
|
|
#[test]
|
|
fn trailing_path_is_not_part_of_the_port() {
|
|
let ob = sing(&format!("vless://uuid@example.com:23576/?type=tcp&security=reality&pbk={PBK}&fp=chrome&sni=cdn.example.com"));
|
|
assert_eq!(ob["server_port"], 23576);
|
|
}
|
|
|
|
#[test]
|
|
fn port_out_of_range_is_rejected() {
|
|
for url in ["vless://uuid@example.com:70000?type=tcp", "trojan://pw@example.com:0", "ss://YWVzLTI1Ni1nY206cHc@example.com:99999"] {
|
|
assert!(err(url, LinkBackend::SingBox).contains("out of range"), "{url}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn reality_empty_fingerprint_falls_back_to_chrome() {
|
|
let ob = sing(&format!("vless://uuid@example.com:443?type=tcp&security=reality&pbk={PBK}&fp=&sni=cdn.example.com"));
|
|
assert_eq!(ob["tls"]["utls"]["fingerprint"], "chrome");
|
|
}
|
|
|
|
#[test]
|
|
fn xray_only_fingerprint_rejected_for_sing_box() {
|
|
let url = format!("vless://uuid@example.com:443?type=tcp&security=reality&pbk={PBK}&fp=hellochrome_120&sni=cdn.example.com");
|
|
err(&url, LinkBackend::SingBox);
|
|
assert_eq!(xray(&url)["streamSettings"]["realitySettings"]["fingerprint"], "hellochrome_120");
|
|
for fp in ["unsafe", "hellogolang", "bogus"] {
|
|
assert!(err(&url.replace("hellochrome_120", fp), LinkBackend::Xray).contains("XRay would refuse"), "{fp}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn values_a_backend_refuses_to_start_on_are_rejected() {
|
|
let reality = format!("vless://uuid@example.com:443?security=reality&sni=a.example.com&pbk={PBK}&sid=ab");
|
|
let tuic = "tuic://00000000-0000-0000-0000-000000000000:pw@example.com:443";
|
|
let k16 = STANDARD.encode(b"k".repeat(16));
|
|
let k32 = STANDARD.encode(b"k".repeat(32));
|
|
let cases: Vec<(String, &str, &str)> = vec![
|
|
(format!("{reality}&flow=xtls-rprx-direct"), "both", "flow"),
|
|
(format!("{reality}&flow=xtls-rprx-vision-udp443"), "sing-box", "flow"),
|
|
(reality.replace("pbk=SbVK", "pbk=SbV+"), "both", "pbk"),
|
|
(reality.replace(&format!("pbk={PBK}"), "pbk=pubkey"), "both", "pbk"),
|
|
(reality.replace("sid=ab", "sid=abc"), "both", "sid"),
|
|
(reality.replace("sid=ab", "sid=0123456789abcdef00"), "both", "sid"),
|
|
(reality.replace("sid=ab", "sid=zz"), "both", "sid"),
|
|
(format!("{reality}&spx=nopath"), "xray", "spx"),
|
|
(format!("{reality}&spx=%2F%25zz"), "xray", "spx"),
|
|
(format!("{reality}&spx=%2Fa%01b"), "xray", "spx"),
|
|
(reality.replace("uuid@", &format!("{}@", "x".repeat(31))), "xray", "VLESS id"),
|
|
("vless://uuid@example.com:443?type=xhttp&security=tls&mode=bogus".into(), "xray", "xhttp mode"),
|
|
("vless://uuid@example.com:443?type=h2&security=tls".into(), "xray", "transport"),
|
|
("vless://uuid@example.com:443?type=quic&security=tls".into(), "xray", "transport"),
|
|
("trojan://pw@example.com:443?security=tls&fp=bogus".into(), "both", "fingerprint"),
|
|
(vmess_url(json!({ "scy": "aes-128-ctr" })), "sing-box", "VMess security"),
|
|
(vmess_url(json!({ "scy": "bogus" })), "sing-box", "VMess security"),
|
|
(vmess_url(json!({ "id": 123 })), "both", "VMess id"),
|
|
(vmess_url(json!({ "id": null })), "xray", "VMess id"),
|
|
(format!("{tuic}?congestion_control=reno"), "sing-box", "congestion_control"),
|
|
("tuic://not-a-uuid:pw@example.com:443".into(), "sing-box", "TUIC uuid"),
|
|
("hy2://pw@example.com:443?mport=a-b".into(), "both", "mport"),
|
|
("hy2://pw@example.com:443?mport=1-70000".into(), "both", "mport"),
|
|
("hy2://pw@example.com:443?mport=0-5".into(), "both", "mport"),
|
|
("hy2://pw@example.com:443?mport=30000-20000".into(), "both", "mport"),
|
|
("hy2://pw@example.com:443?insecure=1&pinSHA256=abcd".into(), "xray", "pinSHA256"),
|
|
("trojan://@example.com:443?security=tls".into(), "both", "password is empty"),
|
|
("hy2://pw@example.com:443?obfs=salamander".into(), "both", "obfs-password"),
|
|
("ss://plain:pw@example.com:8388".into(), "both", "method"),
|
|
("ss://aes-128-ctr:pw@example.com:8388".into(), "xray", "method"),
|
|
("ss://chacha20-poly1305:pw@example.com:8388".into(), "sing-box", "method"),
|
|
("ss://2022-blake3-aes-128-gcm:pw@example.com:8388".into(), "both", "base64 key"),
|
|
(format!("ss://2022-blake3-aes-128-gcm:{k32}@example.com:8388"), "both", "base64 key"),
|
|
(format!("ss://2022-blake3-chacha20-poly1305:{k16}%3A{k16}@example.com:8388"), "both", "single key"),
|
|
];
|
|
for (url, backends, message) in cases {
|
|
let list: &[LinkBackend] = match backends {
|
|
"both" => &[LinkBackend::SingBox, LinkBackend::Xray],
|
|
"sing-box" => &[LinkBackend::SingBox],
|
|
_ => &[LinkBackend::Xray],
|
|
};
|
|
for &backend in list {
|
|
let e = err(&url, backend);
|
|
assert!(e.contains(message), "{url} ({}): {e:?} lacks {message:?}", backend.as_str());
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn values_one_backend_takes_still_parse() {
|
|
let reality = format!("vless://uuid@example.com:443?security=reality&sni=a.example.com&pbk={PBK}&sid=0123456789ABCDEF");
|
|
assert_eq!(xray(&format!("{reality}&flow=xtls-rprx-vision-udp443"))["settings"]["flow"], "xtls-rprx-vision-udp443");
|
|
assert_eq!(sing(&reality)["tls"]["reality"]["short_id"], "0123456789ABCDEF");
|
|
assert_eq!(xray(&vmess_url(json!({ "scy": "aes-128-ctr" })))["settings"]["security"], "aes-128-ctr");
|
|
assert_eq!(sing(&vmess_url(json!({ "scy": "aes-128-cfb" })))["security"], "aes-128-cfb");
|
|
// XRay takes a space (and non-ASCII) in spiderX; only control characters and bad escapes kill it.
|
|
let spx = xray(&format!("{reality}&spx=%2Fa%20b%C3%A9"));
|
|
assert_eq!(spx["streamSettings"]["realitySettings"]["spiderX"], "/a b\u{e9}");
|
|
assert_eq!(xray("ss://chacha20-poly1305:pw@example.com:8388")["settings"]["method"], "chacha20-poly1305");
|
|
assert_eq!(sing("ss://aes-128-ctr:pw@example.com:8388")["method"], "aes-128-ctr");
|
|
let k16 = STANDARD.encode(b"k".repeat(16));
|
|
let ss2022 = sing(&format!("ss://2022-blake3-aes-128-gcm:{k16}%3A{k16}@example.com:8388"));
|
|
assert_eq!(ss2022["password"], format!("{k16}:{k16}"));
|
|
}
|
|
|
|
#[test]
|
|
fn hysteria2_port_hopping_takes_lone_ports() {
|
|
let ob = sing("hy2://pw@example.com:443?mport=443, 20000-30000");
|
|
assert_eq!(ob["server_ports"], json!(["443:443", "20000:30000"]));
|
|
let remote = xray("hy2://pw@example.com:443?mport=443,20000-30000");
|
|
assert_eq!(remote["streamSettings"]["finalmask"]["udp"][0]["settings"]["remotePorts"], "443-443,20000-30000");
|
|
}
|
|
|
|
#[test]
|
|
fn hysteria2_pin_replaces_insecure_for_xray() {
|
|
let pin = vec!["AB"; 32].join(":");
|
|
let url = format!("hy2://pw@example.com:443?sni=a.example.com&insecure=1&pinSHA256={pin}");
|
|
let ob = xray(&url);
|
|
assert_eq!(ob["streamSettings"]["tlsSettings"]["pinnedPeerCertSha256"], "ab".repeat(32));
|
|
// sing-box pins only a public key: the link stays insecure there.
|
|
assert_eq!(sing(&url)["tls"]["insecure"], true);
|
|
}
|
|
|
|
#[test]
|
|
fn reality_without_pbk_is_rejected_clearly() {
|
|
assert!(err("vless://uuid@example.com:443?security=reality&type=tcp", LinkBackend::SingBox).contains("pbk"));
|
|
}
|
|
|
|
#[test]
|
|
fn vless_httpupgrade_and_quic_transports() {
|
|
let ob = sing("vless://uuid@example.com:443?type=httpupgrade&security=tls&sni=cdn.example.com&host=cdn.example.com&path=%2Fupgrade");
|
|
assert_eq!(ob["transport"], json!({ "type": "httpupgrade", "host": "cdn.example.com", "path": "/upgrade" }));
|
|
let ob = sing("vless://uuid@example.com:443?type=quic&security=tls&sni=cdn.example.com");
|
|
assert_eq!(ob["transport"]["type"], "quic");
|
|
}
|
|
|
|
#[test]
|
|
fn vless_xhttp_fails_loudly_on_sing_box() {
|
|
assert!(
|
|
err("vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com", LinkBackend::SingBox)
|
|
.contains("unsupported VLESS transport 'xhttp'")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn xray_vless_xhttp() {
|
|
let ob = xray("vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com&host=cdn.example.com&path=%2Fx");
|
|
assert_eq!(ob["settings"]["id"], "uuid");
|
|
assert_eq!(ob["streamSettings"]["network"], "xhttp");
|
|
assert_eq!(ob["streamSettings"]["xhttpSettings"]["path"], "/x");
|
|
}
|
|
|
|
fn quote(s: &str) -> String {
|
|
percent_encoding::utf8_percent_encode(s, percent_encoding::NON_ALPHANUMERIC).to_string()
|
|
}
|
|
|
|
#[test]
|
|
fn xray_xhttp_extra_keeps_ordinary_settings() {
|
|
let extra = json!({ "xPaddingBytes": "100-1000", "downloadSettings": { "address": "dl.example.com" } });
|
|
let ob = xray(&format!(
|
|
"vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com&extra={}",
|
|
quote(&extra.to_string())
|
|
));
|
|
assert_eq!(ob["streamSettings"]["xhttpSettings"]["extra"]["xPaddingBytes"], "100-1000");
|
|
}
|
|
|
|
#[test]
|
|
fn xray_xhttp_extra_cannot_name_local_files() {
|
|
let extra = json!({ "downloadSettings": { "tlsSettings": { "masterKeyLog": "/etc/x", "certificates": [{ "keyFile": "/root/k" }] } } });
|
|
let e = err(
|
|
&format!("vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com&extra={}", quote(&extra.to_string())),
|
|
LinkBackend::Xray,
|
|
);
|
|
assert!(e.contains("keyfile, masterkeylog"), "{e}");
|
|
}
|
|
|
|
#[test]
|
|
fn xray_xhttp_extra_cannot_set_socket_options() {
|
|
let cases = [
|
|
(
|
|
json!({ "downloadSettings": { "address": "dl.example.com", "sockopt": { "mark": 0, "tcpFastOpen": true } } }),
|
|
json!({ "downloadSettings": { "address": "dl.example.com", "sockopt": { "tcpFastOpen": true } } }),
|
|
),
|
|
(json!({ "downloadSettings": { "sockopt": { "customSockopt": [], "TProxy": "redirect" } } }), json!({ "downloadSettings": { "sockopt": {} } })),
|
|
(json!({ "downloadSettings": { "sockopt": { "dialerProxy": "direct", "interface": "eth0" } } }), json!({ "downloadSettings": { "sockopt": {} } })),
|
|
(json!({ "Mark": 1, "xPaddingBytes": "100-1000" }), json!({ "xPaddingBytes": "100-1000" })),
|
|
// The Kelvin sign, which Go folds to k as Python's lower() does.
|
|
(json!({ "downloadSettings": { "sockopt": { "mar\u{212a}": 0 } } }), json!({ "downloadSettings": { "sockopt": {} } })),
|
|
];
|
|
for (extra, left) in cases {
|
|
let ob = xray(&format!(
|
|
"vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com&extra={}",
|
|
quote(&extra.to_string())
|
|
));
|
|
assert_eq!(ob["streamSettings"]["xhttpSettings"]["extra"], left, "{extra}");
|
|
}
|
|
// Go's JSON decoding folds U+017F to s: a non-ASCII key is refused outright.
|
|
let extra = json!({ "downloadSettings": { "tlsSettings": { "ma\u{17f}terKeyLog": "/etc/x" } } });
|
|
let e = err(
|
|
&format!("vless://uuid@example.com:443?type=xhttp&security=tls&sni=cdn.example.com&extra={}", quote(&extra.to_string())),
|
|
LinkBackend::Xray,
|
|
);
|
|
assert!(e.contains("names local files"), "{e}");
|
|
}
|
|
|
|
#[test]
|
|
fn xray_vless_ech() {
|
|
let ob = xray("vless://uuid@example.com:443?type=tcp&security=tls&sni=cdn.example.com&ech=udp%3A%2F%2F1.1.1.1");
|
|
assert_eq!(ob["streamSettings"]["tlsSettings"]["echConfigList"], "udp://1.1.1.1");
|
|
assert!(
|
|
err("vless://uuid@example.com:443?type=tcp&security=tls&sni=cdn.example.com&ech=blob", LinkBackend::SingBox)
|
|
.contains("unsupported VLESS parameter 'ech'")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn xray_socks_and_shadowsocks_use_flat_settings() {
|
|
let ob = xray("socks5://user:pass@example.com:1080");
|
|
assert_eq!(ob["protocol"], "socks");
|
|
assert_eq!(ob["settings"]["address"], "example.com");
|
|
assert_eq!(ob["settings"]["user"], "user");
|
|
assert!(ob["settings"].get("servers").is_none());
|
|
let creds = URL_SAFE_NO_PAD.encode("chacha20-ietf-poly1305:passw0rd");
|
|
let ob = xray(&format!("ss://{creds}@ss.example.com:8388"));
|
|
assert_eq!(ob["protocol"], "shadowsocks");
|
|
assert_eq!(ob["settings"]["method"], "chacha20-ietf-poly1305");
|
|
}
|
|
|
|
#[test]
|
|
fn vmess_forms() {
|
|
let payload = json!({
|
|
"add": "vmess.example.com", "port": "443", "id": "00000000-0000-0000-0000-000000000000", "aid": "0",
|
|
"scy": "auto", "net": "ws", "host": "cdn.example.com", "path": "/ws", "tls": "tls", "sni": "cdn.example.com",
|
|
});
|
|
let ob = sing(&format!("vmess://{}", STANDARD.encode(payload.to_string())));
|
|
assert_eq!(ob["transport"]["type"], "ws");
|
|
assert_eq!(ob["tls"]["server_name"], "cdn.example.com");
|
|
|
|
let payload = json!({ "add": "vmess.example.com", "port": "443", "id": "00000000-0000-0000-0000-000000000000", "aid": "0", "scy": "auto" });
|
|
let ob = sing(&format!("vmess://{}#Subscription Remark", URL_SAFE_NO_PAD.encode(payload.to_string())));
|
|
assert_eq!(ob["server"], "vmess.example.com");
|
|
|
|
let payload = json!({ "add": "vmess.example.com", "port": 443, "id": "u", "aid": "", "scy": "" });
|
|
let ob = sing(&format!("vmess://{}", STANDARD.encode(payload.to_string())));
|
|
assert_eq!((ob["alter_id"].clone(), ob["security"].clone()), (json!(0), json!("auto")));
|
|
|
|
let as_list = sing(&vmess_url(json!({ "tls": "tls", "alpn": ["h2", "http/1.1"] })));
|
|
let as_text = sing(&vmess_url(json!({ "tls": "tls", "alpn": "h2, http/1.1" })));
|
|
assert_eq!(as_list["tls"]["alpn"], json!(["h2", "http/1.1"]));
|
|
assert_eq!(as_text["tls"]["alpn"], json!(["h2", "http/1.1"]));
|
|
|
|
assert!(err(&vmess_url(json!({ "net": "kcp" })), LinkBackend::SingBox).contains("unsupported VMess transport 'kcp'"));
|
|
}
|
|
|
|
#[test]
|
|
fn socks4_keeps_its_bare_userid() {
|
|
let ob = sing("socks4://me@10.0.0.1:1080");
|
|
assert_eq!((ob["version"].clone(), ob["username"].clone()), (json!("4"), json!("me")));
|
|
assert!(ob.get("password").is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn blank_parameters_fall_back_to_the_server() {
|
|
let ob = sing("vless://uuid@example.com:443?security=tls&sni=&type=ws&host=&path=");
|
|
assert_eq!(ob["tls"]["server_name"], "example.com");
|
|
assert_eq!(ob["transport"]["headers"]["Host"], "example.com");
|
|
assert_eq!(ob["transport"]["path"], "/");
|
|
let tuic = sing("tuic://00000000-0000-0000-0000-000000000000:pw@example.com:443?alpn=&congestion_control=&udp_relay_mode=");
|
|
assert_eq!(tuic["tls"]["alpn"], json!(["h3"]));
|
|
assert_eq!((tuic["congestion_control"].clone(), tuic["udp_relay_mode"].clone()), (json!("bbr"), json!("native")));
|
|
}
|
|
|
|
#[test]
|
|
fn trojan_shadowsocks_and_friends() {
|
|
let ob = sing("trojan://secret@example.com:443?sni=tls.example.com&fp=chrome");
|
|
assert_eq!(ob["password"], "secret");
|
|
assert_eq!(ob["tls"]["server_name"], "tls.example.com");
|
|
|
|
let creds = URL_SAFE_NO_PAD.encode("chacha20-ietf-poly1305:passw0rd");
|
|
assert_eq!(sing(&format!("ss://{creds}@ss.example.com:8388"))["method"], "chacha20-ietf-poly1305");
|
|
|
|
let legacy = URL_SAFE_NO_PAD.encode("chacha20-ietf-poly1305:passw0rd@legacy.example.com:8388");
|
|
let ob = sing(&format!("ss://{legacy}#Legacy Server"));
|
|
assert_eq!((ob["server"].clone(), ob["server_port"].clone()), (json!("legacy.example.com"), json!(8388)));
|
|
assert_eq!(ob["password"], "passw0rd");
|
|
|
|
let ob = sing("ss://none:plain%20pass@plain.example.com:8388");
|
|
assert_eq!((ob["method"].clone(), ob["password"].clone()), (json!("none"), json!("plain pass")));
|
|
|
|
let legacy = URL_SAFE_NO_PAD.encode("none:pass@[2001:db8::1]:8388");
|
|
assert_eq!(sing(&format!("ss://{legacy}#Legacy IPv6"))["server"], "2001:db8::1");
|
|
}
|
|
|
|
#[test]
|
|
fn hysteria2_both_backends() {
|
|
let ob = sing("hy2://secret@example.com:443?sni=hy.example.com&insecure=1&obfs=salamander&obfs-password=mask");
|
|
assert_eq!(ob["tls"]["insecure"], true);
|
|
assert_eq!(ob["obfs"]["password"], "mask");
|
|
let ob = xray("hy2://secret@example.com:443?sni=hy.example.com&obfs=salamander&obfs-password=mask");
|
|
assert_eq!(ob["protocol"], "hysteria");
|
|
assert!(ob["settings"].get("password").is_none());
|
|
assert_eq!(ob["streamSettings"]["network"], "hysteria");
|
|
assert_eq!(ob["streamSettings"]["tlsSettings"]["serverName"], "hy.example.com");
|
|
assert_eq!(ob["streamSettings"]["hysteriaSettings"]["auth"], "secret");
|
|
assert_eq!(ob["streamSettings"]["finalmask"]["udp"], json!([{ "type": "salamander", "settings": { "password": "mask" } }]));
|
|
assert!(err("hy2://secret@example.com:443?sni=hy.example.com&insecure=1", LinkBackend::Xray).contains("allowInsecure"));
|
|
}
|
|
|
|
#[test]
|
|
fn tuic_anytls_naive_and_plain_proxies() {
|
|
let ob = sing("tuic://00000000-0000-0000-0000-000000000000:secret@example.com:443?sni=tuic.example.com&alpn=h3,hq-29");
|
|
assert_eq!(ob["tls"]["alpn"], json!(["h3", "hq-29"]));
|
|
|
|
let ob = sing("anytls://p%40ss@example.com:443?sni=a.example.com&insecure=1&fp=chrome#name");
|
|
assert_eq!(ob["password"], "p@ss");
|
|
assert_eq!(
|
|
ob["tls"],
|
|
json!({ "enabled": true, "server_name": "a.example.com", "insecure": true, "utls": { "enabled": true, "fingerprint": "chrome" } })
|
|
);
|
|
assert!(err("anytls://pw@example.com:443", LinkBackend::Xray).contains("unsupported XRay outbound type"));
|
|
|
|
let ob = sing("naive+https://user:pass@example.com:443#name");
|
|
assert_eq!((ob["type"].clone(), ob["username"].clone(), ob["password"].clone()), (json!("naive"), json!("user"), json!("pass")));
|
|
assert!(ob.get("quic").is_none());
|
|
assert_eq!(sing("naive+quic://user:pass@example.com:443")["quic"], true);
|
|
|
|
let ob = sing("socks5://user:p@ss@example.com:1080");
|
|
assert_eq!((ob["username"].clone(), ob["password"].clone(), ob["server"].clone()), (json!("user"), json!("p@ss"), json!("example.com")));
|
|
let ob = sing("https://proxy.example.com:8443");
|
|
assert_eq!(ob["type"], "http");
|
|
assert_eq!(ob["tls"]["server_name"], "proxy.example.com");
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_scheme_and_transports_fail_loudly() {
|
|
assert!(err("wireguard://example.com", LinkBackend::SingBox).contains("unsupported scheme"));
|
|
let url = "trojan://pw@example.com:443?security=tls&type=xhttp&path=/p";
|
|
assert!(err(url, LinkBackend::SingBox).contains("unsupported Trojan transport 'xhttp'"));
|
|
assert_eq!(xray(url)["streamSettings"]["network"], "xhttp");
|
|
}
|
|
|
|
#[test]
|
|
fn xray_only_fingerprint_for_trojan_and_vmess() {
|
|
let trojan = "trojan://pw@example.com:443?security=tls&fp=unsafe";
|
|
err(trojan, LinkBackend::SingBox);
|
|
assert_eq!(xray(trojan)["streamSettings"]["tlsSettings"]["fingerprint"], "unsafe");
|
|
let vmess = vmess_url(json!({ "tls": "tls", "fp": "unsafe" }));
|
|
err(&vmess, LinkBackend::SingBox);
|
|
assert_eq!(xray(&vmess)["streamSettings"]["tlsSettings"]["fingerprint"], "unsafe");
|
|
}
|
|
|
|
#[test]
|
|
fn local_file_keys_catch_what_upstream_does() {
|
|
let v = json!({ "a": { "certificatePath": 1, "path": "/", "x": [{ "torrc": 1, "logFile": 2 }] }, "ß": 0 });
|
|
assert_eq!(local_file_keys(&v), ["certificatepath", "logfile", "torrc", "ß"]);
|
|
}
|