mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-30 00:10:30 +00:00
- 新增 Surge h2-connect 节点解析与导出能力,完整支持 root headers 透传 - 支持 Surge/TrustTunnel/HTTP/HTTPS 的 headers 配置解析,支持占位符文本原样保留 - 统一在输出阶段对 headers 与 h2-connect 做平台能力判断,不支持时默认过滤并输出错误提示 - Egern 的 HTTP/HTTPS 透传 root headers,不再静默丢失 - Mihomo 明确过滤不支持的 h2-connect / TrustTunnel header 变体,并保留 `include-unsupported-proxy` 可选行为 - 修复并扩展 parser/producer 的结构化与文本测试覆盖,覆盖 include-unsupported-proxy 下边界行为 - 补充本次需求的 brainstorm 文档,记录验收标准与兼容性边界
2583 lines
81 KiB
JavaScript
2583 lines
81 KiB
JavaScript
import { expect } from 'chai';
|
||
import { describe, it } from 'mocha';
|
||
|
||
import $ from '@/core/app';
|
||
import { ProxyUtils } from '@/core/proxy-utils';
|
||
import {
|
||
UUID,
|
||
expectSubset,
|
||
loadProducedJson,
|
||
loadProducedYaml,
|
||
produceExternal,
|
||
produceInternal,
|
||
} from './helpers';
|
||
|
||
function captureWarns(fn) {
|
||
const originalWarn = $.warn;
|
||
const warnings = [];
|
||
$.warn = (message) => warnings.push(message);
|
||
try {
|
||
const result = fn();
|
||
return { result, warnings };
|
||
} finally {
|
||
$.warn = originalWarn;
|
||
}
|
||
}
|
||
|
||
function captureErrors(fn) {
|
||
const originalError = $.error;
|
||
const errors = [];
|
||
$.error = (message) => errors.push(message);
|
||
try {
|
||
const result = fn();
|
||
return { result, errors };
|
||
} finally {
|
||
$.error = originalError;
|
||
}
|
||
}
|
||
|
||
describe('Proxy structured producers', function () {
|
||
it('filters unsupported Clash proxies by default and normalizes vmess ws early data', function () {
|
||
const proxies = [
|
||
{
|
||
type: 'vmess',
|
||
name: 'Clash VMess',
|
||
server: 'vmess.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
cipher: 'chacha20',
|
||
aead: true,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/ws?a=1&ed=2048&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
},
|
||
},
|
||
{
|
||
type: 'vless',
|
||
name: 'Clash Reality',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
flow: 'xtls-rprx-vision',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
},
|
||
];
|
||
|
||
const internal = produceInternal('Clash', proxies);
|
||
const external = loadProducedYaml('Clash', proxies);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expect(external.proxies).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
type: 'vmess',
|
||
name: 'Clash VMess',
|
||
cipher: 'auto',
|
||
alterId: 0,
|
||
servername: 'sni.example.com',
|
||
'ws-opts': {
|
||
path: '/ws?a=1&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
'early-data-header-name': 'Sec-WebSocket-Protocol',
|
||
'max-early-data': 2048,
|
||
},
|
||
});
|
||
});
|
||
|
||
it('keeps unsupported Clash proxies when include-unsupported-proxy is enabled', function () {
|
||
const internal = produceInternal(
|
||
'Clash',
|
||
{
|
||
type: 'vless',
|
||
name: 'Clash Reality',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
flow: 'xtls-rprx-vision',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
},
|
||
{ 'include-unsupported-proxy': true },
|
||
);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
type: 'vless',
|
||
name: 'Clash Reality',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('keeps only websocket shadowsocks v2ray-plugin modes for Mihomo and Stash by default', function () {
|
||
const buildProxy = (name, mode) => ({
|
||
type: 'ss',
|
||
name,
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
plugin: 'v2ray-plugin',
|
||
'plugin-opts': {
|
||
mode,
|
||
host: 'cdn.example.com',
|
||
path: '/socket',
|
||
tls: true,
|
||
},
|
||
});
|
||
|
||
const proxies = [
|
||
buildProxy('WS', 'websocket'),
|
||
buildProxy('QUIC', 'quic'),
|
||
];
|
||
|
||
for (const platform of ['Mihomo', 'Stash']) {
|
||
const internal = produceInternal(platform, proxies);
|
||
const external = loadProducedYaml(platform, proxies, {
|
||
'include-unsupported-proxy': true,
|
||
});
|
||
|
||
expect(internal, platform).to.have.length(1);
|
||
expect(internal[0].name, platform).to.equal('WS');
|
||
expect(
|
||
external.proxies.map((proxy) => proxy.name),
|
||
platform,
|
||
).to.deep.equal(['WS', 'QUIC']);
|
||
}
|
||
});
|
||
|
||
it('keeps only supported shadowsocks v2ray-plugin modes for Shadowrocket by default', function () {
|
||
const buildProxy = (name, mode) => ({
|
||
type: 'ss',
|
||
name,
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
plugin: 'v2ray-plugin',
|
||
'plugin-opts': {
|
||
mode,
|
||
host: 'cdn.example.com',
|
||
path: '/socket',
|
||
tls: true,
|
||
},
|
||
});
|
||
|
||
const proxies = [
|
||
buildProxy('WS', 'websocket'),
|
||
buildProxy('QUIC', 'quic'),
|
||
buildProxy('HTTP2', 'http2'),
|
||
buildProxy('MKCP', 'mkcp'),
|
||
buildProxy('GRPC', 'grpc'),
|
||
buildProxy('TLS', 'tls'),
|
||
];
|
||
|
||
const internal = produceInternal('Shadowrocket', proxies);
|
||
const external = loadProducedYaml('Shadowrocket', proxies, {
|
||
'include-unsupported-proxy': true,
|
||
});
|
||
|
||
expect(internal.map((proxy) => proxy.name)).to.deep.equal([
|
||
'WS',
|
||
'QUIC',
|
||
'HTTP2',
|
||
'MKCP',
|
||
'GRPC',
|
||
]);
|
||
expect(external.proxies.map((proxy) => proxy.name)).to.deep.equal([
|
||
'WS',
|
||
'QUIC',
|
||
'HTTP2',
|
||
'MKCP',
|
||
'GRPC',
|
||
'TLS',
|
||
]);
|
||
});
|
||
|
||
it('adds Clash.Meta reality defaults and preserves websocket early data', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'Reality',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
flow: 'xtls-rprx-vision',
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/ws?a=1&ed=2048&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
},
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('ClashMeta', proxy)[0];
|
||
const external = loadProducedYaml('ClashMeta', proxy);
|
||
|
||
expectSubset(internal, {
|
||
type: 'vless',
|
||
name: 'Reality',
|
||
'client-fingerprint': 'chrome',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
'ws-opts': {
|
||
path: '/ws?a=1&b=2',
|
||
'early-data-header-name': 'Sec-WebSocket-Protocol',
|
||
'max-early-data': 2048,
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
type: 'vless',
|
||
name: 'Reality',
|
||
'client-fingerprint': 'chrome',
|
||
});
|
||
});
|
||
|
||
it('normalizes websocket early data query params for Stash and Shadowrocket', function () {
|
||
const proxy = {
|
||
type: 'vmess',
|
||
name: 'WS Early Query',
|
||
server: 'vmess.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
cipher: 'auto',
|
||
alterId: 0,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/ws?a=1&ed=2048&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
},
|
||
};
|
||
|
||
for (const platform of ['Stash', 'Shadowrocket']) {
|
||
const internal = produceInternal(platform, proxy)[0];
|
||
expectSubset(internal, {
|
||
name: 'WS Early Query',
|
||
'ws-opts': {
|
||
path: '/ws?a=1&b=2',
|
||
'early-data-header-name': 'Sec-WebSocket-Protocol',
|
||
'max-early-data': 2048,
|
||
},
|
||
});
|
||
}
|
||
});
|
||
|
||
it('leaves unsafe websocket early data query params untouched', function () {
|
||
const proxy = {
|
||
type: 'vmess',
|
||
name: 'WS Unsafe Early Query',
|
||
server: 'vmess.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
cipher: 'auto',
|
||
alterId: 0,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/ws?a=1&ed=999999999999999999999&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
},
|
||
};
|
||
|
||
const wsOpts = produceInternal('Clash', proxy)[0]['ws-opts'];
|
||
|
||
expect(wsOpts.path).to.equal('/ws?a=1&ed=999999999999999999999&b=2');
|
||
expect(wsOpts).to.not.have.property('early-data-header-name');
|
||
expect(wsOpts).to.not.have.property('max-early-data');
|
||
});
|
||
|
||
it('keeps explicit websocket early data fields over stale path query values', function () {
|
||
const proxy = {
|
||
type: 'vmess',
|
||
name: 'WS Explicit Early Fields',
|
||
server: 'vmess.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
cipher: 'auto',
|
||
alterId: 0,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/ws?a=1&ed=2048&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
'max-early-data': 4096,
|
||
'early-data-header-name': 'X-Data',
|
||
},
|
||
};
|
||
|
||
for (const platform of [
|
||
'Clash',
|
||
'ClashMeta',
|
||
'Stash',
|
||
'Shadowrocket',
|
||
]) {
|
||
const wsOpts = loadProducedYaml(platform, proxy).proxies[0][
|
||
'ws-opts'
|
||
];
|
||
|
||
expect(wsOpts.path, platform).to.equal('/ws?a=1&b=2');
|
||
expect(wsOpts['max-early-data'], platform).to.equal(4096);
|
||
expect(wsOpts['early-data-header-name'], platform).to.equal(
|
||
'X-Data',
|
||
);
|
||
}
|
||
});
|
||
|
||
it('normalizes httpupgrade path early data as httpupgrade metadata', function () {
|
||
const proxy = {
|
||
type: 'vmess',
|
||
name: 'HTTPUpgrade Early Query',
|
||
server: 'vmess.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
cipher: 'auto',
|
||
alterId: 0,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/upgrade?a=1&ed=2048&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
'v2ray-http-upgrade': true,
|
||
},
|
||
};
|
||
|
||
for (const platform of [
|
||
'Clash',
|
||
'ClashMeta',
|
||
'Stash',
|
||
'Shadowrocket',
|
||
]) {
|
||
const wsOpts = produceInternal(platform, proxy, {
|
||
'include-unsupported-proxy': true,
|
||
})[0]['ws-opts'];
|
||
|
||
expect(wsOpts.path).to.equal('/upgrade?a=1&b=2');
|
||
expect(wsOpts['v2ray-http-upgrade']).to.equal(true);
|
||
expect(wsOpts['v2ray-http-upgrade-fast-open']).to.equal(true);
|
||
expect(wsOpts['_v2ray-http-upgrade-ed']).to.equal('2048');
|
||
expect(wsOpts).to.not.have.property('early-data-header-name');
|
||
expect(wsOpts).to.not.have.property('max-early-data');
|
||
|
||
const externalWsOpts = loadProducedYaml(platform, proxy, {
|
||
'include-unsupported-proxy': true,
|
||
}).proxies[0]['ws-opts'];
|
||
expect(externalWsOpts.path).to.equal('/upgrade?a=1&b=2');
|
||
expect(externalWsOpts['v2ray-http-upgrade-fast-open']).to.equal(
|
||
true,
|
||
);
|
||
expect(externalWsOpts).to.not.have.property(
|
||
'_v2ray-http-upgrade-ed',
|
||
);
|
||
}
|
||
});
|
||
|
||
it('keeps explicit httpupgrade early data over stale path query values', function () {
|
||
const proxy = {
|
||
type: 'vmess',
|
||
name: 'HTTPUpgrade Explicit Early',
|
||
server: 'vmess.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
cipher: 'auto',
|
||
alterId: 0,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/upgrade?a=1&ed=1024&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
'v2ray-http-upgrade': true,
|
||
'v2ray-http-upgrade-fast-open': true,
|
||
'_v2ray-http-upgrade-ed': '4096',
|
||
},
|
||
};
|
||
|
||
for (const platform of [
|
||
'Clash',
|
||
'ClashMeta',
|
||
'Stash',
|
||
'Shadowrocket',
|
||
]) {
|
||
const wsOpts = produceInternal(platform, proxy, {
|
||
'include-unsupported-proxy': true,
|
||
})[0]['ws-opts'];
|
||
|
||
expect(wsOpts.path, platform).to.equal('/upgrade?a=1&b=2');
|
||
expect(wsOpts['_v2ray-http-upgrade-ed'], platform).to.equal('4096');
|
||
}
|
||
});
|
||
|
||
it('does not emit websocket early data fields for httpupgrade transports', function () {
|
||
const directProxy = {
|
||
type: 'vmess',
|
||
name: 'HTTPUpgrade Legacy Fields',
|
||
server: 'vmess.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
cipher: 'auto',
|
||
alterId: 0,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/upgrade',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
'v2ray-http-upgrade': true,
|
||
'v2ray-http-upgrade-fast-open': true,
|
||
'max-early-data': 1024,
|
||
'early-data-header-name': 'X-Upgrade',
|
||
},
|
||
};
|
||
const directProxyWithoutPath = {
|
||
type: 'vmess',
|
||
name: 'HTTPUpgrade Legacy Fields Without Path',
|
||
server: 'vmess.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
cipher: 'auto',
|
||
alterId: 0,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
'v2ray-http-upgrade': true,
|
||
'v2ray-http-upgrade-fast-open': true,
|
||
'max-early-data': 2048,
|
||
'early-data-header-name': 'X-Upgrade',
|
||
},
|
||
};
|
||
const parsedVlessProxy = ProxyUtils.parse(
|
||
`vless://${UUID}@vless-upgrade.example.com:443?type=httpupgrade&host=upgrade.example.com&path=%2Fupgrade&ed=1024&eh=X-Upgrade#VLESS%20Upgrade`,
|
||
)[0];
|
||
|
||
for (const proxy of [
|
||
directProxy,
|
||
directProxyWithoutPath,
|
||
parsedVlessProxy,
|
||
]) {
|
||
for (const platform of [
|
||
'Clash',
|
||
'ClashMeta',
|
||
'Stash',
|
||
'Shadowrocket',
|
||
]) {
|
||
const externalWsOpts = loadProducedYaml(platform, proxy, {
|
||
'include-unsupported-proxy': true,
|
||
}).proxies[0]['ws-opts'];
|
||
|
||
expect(externalWsOpts['v2ray-http-upgrade']).to.equal(true);
|
||
expect(externalWsOpts).to.not.have.property(
|
||
'early-data-header-name',
|
||
);
|
||
expect(externalWsOpts).to.not.have.property('max-early-data');
|
||
expect(externalWsOpts).to.not.have.property(
|
||
'_v2ray-http-upgrade-ed',
|
||
);
|
||
}
|
||
}
|
||
});
|
||
|
||
it('emits Mihomo VLESS xhttp proxies and preserves xhttp options', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
mode: 'stream-up',
|
||
'no-grpc-header': true,
|
||
'x-padding-bytes': '64-128',
|
||
'sc-min-posts-interval-ms': 300,
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
const external = loadProducedYaml('Mihomo', proxy);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expect(external.proxies).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
type: 'vless',
|
||
name: 'XHTTP',
|
||
network: 'xhttp',
|
||
servername: 'sni.example.com',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
mode: 'stream-up',
|
||
'no-grpc-header': true,
|
||
'x-padding-bytes': '64-128',
|
||
'sc-min-posts-interval-ms': 300,
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
type: 'vless',
|
||
name: 'XHTTP',
|
||
network: 'xhttp',
|
||
servername: 'sni.example.com',
|
||
'xhttp-opts': {
|
||
'sc-min-posts-interval-ms': 300,
|
||
},
|
||
});
|
||
});
|
||
|
||
it('warns when Mihomo ECH sidecar DNS fields are exported', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'Mihomo ECH DNS',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
'ech-opts': {
|
||
enable: true,
|
||
_dns: 'https://1.1.1.1/dns-query',
|
||
'query-server-name': 'ech.example.com',
|
||
},
|
||
network: 'xhttp',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
mode: 'stream-up',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
'ech-opts': {
|
||
enable: true,
|
||
_dns: 'https://dns.example.com/dns-query',
|
||
'query-server-name': 'download-ech.example.com',
|
||
},
|
||
},
|
||
},
|
||
};
|
||
|
||
const { result: external, warnings } = captureWarns(() =>
|
||
loadProducedYaml('Mihomo', proxy),
|
||
);
|
||
|
||
expect(external.proxies).to.have.length(1);
|
||
expect(warnings).to.have.length(2);
|
||
expect(warnings[0]).to.include(
|
||
'mihomo 不支持在 ech-opts 中配置 ECH DNS',
|
||
);
|
||
expect(warnings[0]).to.include(
|
||
'dns["nameserver-policy"]["ech.example.com"] = ["https://1.1.1.1/dns-query"]',
|
||
);
|
||
expect(warnings[1]).to.include(
|
||
'dns["nameserver-policy"]["download-ech.example.com"] = ["https://dns.example.com/dns-query"]',
|
||
);
|
||
});
|
||
|
||
it('emits Mihomo VLESS xhttp download settings with scMinPostsIntervalMs', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP Download',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
mode: 'stream-up',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
servername: 'download-sni.example.com',
|
||
path: '/download',
|
||
host: 'download-host.example.com',
|
||
'sc-min-posts-interval-ms': 300,
|
||
'reuse-settings': {
|
||
'max-connections': '8',
|
||
'h-max-reusable-secs': '900',
|
||
},
|
||
},
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
const external = loadProducedYaml('Mihomo', proxy);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expect(external.proxies).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
type: 'vless',
|
||
name: 'XHTTP Download',
|
||
network: 'xhttp',
|
||
servername: 'sni.example.com',
|
||
'xhttp-opts': {
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
servername: 'download-sni.example.com',
|
||
path: '/download',
|
||
host: 'download-host.example.com',
|
||
'sc-min-posts-interval-ms': 300,
|
||
'reuse-settings': {
|
||
'max-connections': '8',
|
||
'h-max-reusable-secs': '900',
|
||
},
|
||
},
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
type: 'vless',
|
||
name: 'XHTTP Download',
|
||
network: 'xhttp',
|
||
servername: 'sni.example.com',
|
||
'xhttp-opts': {
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
servername: 'download-sni.example.com',
|
||
path: '/download',
|
||
host: 'download-host.example.com',
|
||
'sc-min-posts-interval-ms': 300,
|
||
'reuse-settings': {
|
||
'max-connections': '8',
|
||
'h-max-reusable-secs': '900',
|
||
},
|
||
},
|
||
},
|
||
});
|
||
});
|
||
|
||
it('skips Mihomo VLESS xhttp stream-one proxies when download-settings are present', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP Stream One Download',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
mode: 'stream-one',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
path: '/download',
|
||
},
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
const external = ProxyUtils.produce([proxy], 'Mihomo', 'external');
|
||
|
||
expect(internal).to.have.length(0);
|
||
expect(external.trim()).to.equal('proxies:');
|
||
});
|
||
|
||
it('keeps VLESS xhttp proxy when download-settings reality-opts has empty public-key and main reality is valid', function () {
|
||
// 上行(主代理)有合法 reality-opts,下行(download-settings)用
|
||
// reality-opts: { public-key: '' } 取消继承上行 Reality,合法配置。
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP Reality Cancel',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
mode: 'stream-up',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
servername: 'download-sni.example.com',
|
||
'reality-opts': { 'public-key': '' },
|
||
},
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
expect(internal).to.have.length(1);
|
||
expect(internal[0].name).to.equal('XHTTP Reality Cancel');
|
||
});
|
||
|
||
it('filters out VLESS xhttp proxy when download-settings reality-opts is empty object (broken URI) even with valid main reality', function () {
|
||
// 下行 download-settings.reality-opts 为 {} (没有 public-key 字段),
|
||
// 代表 URI 里声明了 security=reality 但 pbk 缺失,属于残缺配置,应过滤。
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP Broken Reality',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
mode: 'stream-up',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
'reality-opts': {},
|
||
},
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
expect(internal).to.have.length(0);
|
||
});
|
||
|
||
it('filters out VLESS xhttp proxy when download-settings reality-opts has empty public-key and main has no valid reality', function () {
|
||
// 下行 download-settings 有 reality-opts: { public-key: '' },
|
||
// 但上行主代理本身没有合法 Reality,属于无效配置,应被过滤。
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP Invalid Reality',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
mode: 'stream-up',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
'reality-opts': { 'public-key': '' },
|
||
},
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
expect(internal).to.have.length(0);
|
||
});
|
||
|
||
it('filters out VLESS proxy when main reality-opts has empty public-key', function () {
|
||
// 主代理 reality-opts.public-key 为空,无论下行如何,都应被过滤。
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'Reality Empty Key',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'tcp',
|
||
'reality-opts': { 'public-key': '' },
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
expect(internal).to.have.length(0);
|
||
});
|
||
|
||
it('does not let include-unsupported-proxy bypass malformed VLESS Reality validation', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'Reality Empty Key',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'tcp',
|
||
'reality-opts': { 'public-key': '' },
|
||
};
|
||
|
||
const { result, errors } = captureErrors(() =>
|
||
produceInternal('Mihomo', proxy, {
|
||
'include-unsupported-proxy': true,
|
||
}),
|
||
);
|
||
|
||
expect(result).to.have.length(0);
|
||
expect(errors).to.have.length(1);
|
||
expect(errors[0]).to.include(
|
||
'Skipping VLESS Reality proxy Reality Empty Key: empty reality-opts.public-key',
|
||
);
|
||
});
|
||
|
||
it('normalizes Stash TUIC defaults and external yaml wrapper', function () {
|
||
const proxy = {
|
||
type: 'tuic',
|
||
name: 'TUIC',
|
||
server: 'tuic.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
password: 'secret',
|
||
tfo: true,
|
||
};
|
||
|
||
const internal = produceInternal('Stash', proxy)[0];
|
||
const external = loadProducedYaml('Stash', proxy);
|
||
|
||
expectSubset(internal, {
|
||
type: 'tuic',
|
||
name: 'TUIC',
|
||
alpn: ['h3'],
|
||
'fast-open': true,
|
||
version: 5,
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
type: 'tuic',
|
||
name: 'TUIC',
|
||
alpn: ['h3'],
|
||
'fast-open': true,
|
||
version: 5,
|
||
});
|
||
});
|
||
|
||
it('emits Stash VLESS TCP REALITY proxies without validating flow values', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'Stash Reality Custom Flow',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'tcp',
|
||
flow: 'xtls-rprx-unknown',
|
||
sni: 'sni.example.com',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Stash', proxy);
|
||
const external = loadProducedYaml('Stash', proxy);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expect(external.proxies).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
type: 'vless',
|
||
name: 'Stash Reality Custom Flow',
|
||
network: 'tcp',
|
||
flow: 'xtls-rprx-unknown',
|
||
servername: 'sni.example.com',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
type: 'vless',
|
||
name: 'Stash Reality Custom Flow',
|
||
network: 'tcp',
|
||
flow: 'xtls-rprx-unknown',
|
||
servername: 'sni.example.com',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('keeps default-tcp Stash VLESS REALITY proxies when network is omitted', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'Implicit TCP Reality',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Stash', proxy);
|
||
const external = loadProducedYaml('Stash', proxy);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expect(external.proxies).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
type: 'vless',
|
||
name: 'Implicit TCP Reality',
|
||
servername: 'sni.example.com',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
});
|
||
expect(external.proxies[0]).to.not.have.property('network');
|
||
});
|
||
|
||
it('keeps Stash VLESS TCP REALITY proxies when URI input omits flow', function () {
|
||
const proxies = ProxyUtils.parse(
|
||
`vless://${UUID}@vless.example.com:443?type=tcp&security=reality&sni=sni.example.com&pbk=pubkey&sid=08#No%20Flow`,
|
||
);
|
||
|
||
const internal = produceInternal('Stash', proxies);
|
||
const external = loadProducedYaml('Stash', proxies);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expect(external.proxies).to.have.length(1);
|
||
expect(internal[0]).to.not.have.property('flow');
|
||
expectSubset(internal[0], {
|
||
type: 'vless',
|
||
name: 'No Flow',
|
||
network: 'tcp',
|
||
servername: 'sni.example.com',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
type: 'vless',
|
||
name: 'No Flow',
|
||
network: 'tcp',
|
||
servername: 'sni.example.com',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('keeps Stash VLESS TCP REALITY nodes while still filtering non-tcp and unsupported variants', function () {
|
||
const proxies = [
|
||
{
|
||
type: 'vless',
|
||
name: 'Supported Reality',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'tcp',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
},
|
||
{
|
||
type: 'vless',
|
||
name: 'Custom Flow',
|
||
server: 'unsupported-flow.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'tcp',
|
||
flow: 'xtls-rprx-unknown',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
},
|
||
{
|
||
type: 'vless',
|
||
name: 'Reality WS',
|
||
server: 'vless-ws.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/ws',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
},
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
},
|
||
{
|
||
type: 'vless',
|
||
name: 'XHTTP',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'xhttp',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
},
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
},
|
||
{
|
||
type: 'vless',
|
||
name: 'Encrypted VLESS',
|
||
server: 'encrypted.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'tcp',
|
||
encryption: 'aes-128-gcm',
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
},
|
||
];
|
||
|
||
const internal = produceInternal('Stash', proxies);
|
||
const external = loadProducedYaml('Stash', proxies);
|
||
|
||
expect(internal).to.have.length(2);
|
||
expect(external.proxies).to.have.length(2);
|
||
expect(internal.map((proxy) => proxy.name)).to.deep.equal([
|
||
'Supported Reality',
|
||
'Custom Flow',
|
||
]);
|
||
expect(external.proxies.map((proxy) => proxy.name)).to.deep.equal([
|
||
'Supported Reality',
|
||
'Custom Flow',
|
||
]);
|
||
expectSubset(internal[0], {
|
||
type: 'vless',
|
||
name: 'Supported Reality',
|
||
});
|
||
expectSubset(internal[1], {
|
||
type: 'vless',
|
||
name: 'Custom Flow',
|
||
flow: 'xtls-rprx-unknown',
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
type: 'vless',
|
||
name: 'Supported Reality',
|
||
});
|
||
expectSubset(external.proxies[1], {
|
||
type: 'vless',
|
||
name: 'Custom Flow',
|
||
flow: 'xtls-rprx-unknown',
|
||
});
|
||
});
|
||
|
||
it('promotes shadow-tls fields for Shadowrocket', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'ShadowTLS SS',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
'shadow-tls-password': 'shadow-pass',
|
||
'shadow-tls-sni': 'mask.example.com',
|
||
'shadow-tls-version': 3,
|
||
'skip-cert-verify': true,
|
||
};
|
||
|
||
const internal = produceInternal('Shadowrocket', proxy)[0];
|
||
const external = loadProducedYaml('Shadowrocket', proxy);
|
||
|
||
expectSubset(internal, {
|
||
type: 'ss',
|
||
name: 'ShadowTLS SS',
|
||
plugin: 'shadow-tls',
|
||
'plugin-opts': {
|
||
host: 'mask.example.com',
|
||
password: 'shadow-pass',
|
||
version: 3,
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
type: 'ss',
|
||
plugin: 'shadow-tls',
|
||
});
|
||
});
|
||
|
||
it('maps canonical shadowsocks tls fields into Shadowrocket structured output', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS',
|
||
server: 'ss.example.com',
|
||
port: 443,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
tls: true,
|
||
sni: 'a.com',
|
||
'skip-cert-verify': true,
|
||
};
|
||
|
||
const internal = produceInternal('Shadowrocket', proxy)[0];
|
||
const external = loadProducedYaml('Shadowrocket', proxy);
|
||
|
||
expectSubset(internal, {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS',
|
||
tls: true,
|
||
servername: 'a.com',
|
||
'skip-cert-verify': true,
|
||
});
|
||
// expect(internal).to.not.have.property('sni');
|
||
expectSubset(external.proxies[0], {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS',
|
||
tls: true,
|
||
servername: 'a.com',
|
||
'skip-cert-verify': true,
|
||
});
|
||
// expect(external.proxies[0]).to.not.have.property('sni');
|
||
});
|
||
|
||
it('keeps canonical shadowsocks tls nodes without servername in Shadowrocket output when sni is absent', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS No Host',
|
||
server: 'ss.example.com',
|
||
port: 443,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
tls: true,
|
||
};
|
||
|
||
const internal = produceInternal('Shadowrocket', proxy)[0];
|
||
const external = loadProducedYaml('Shadowrocket', proxy);
|
||
|
||
expectSubset(internal, {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS No Host',
|
||
tls: true,
|
||
});
|
||
expect(internal).to.not.have.property('sni');
|
||
expect(internal).to.not.have.property('servername');
|
||
expectSubset(external.proxies[0], {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS No Host',
|
||
tls: true,
|
||
});
|
||
expect(external.proxies[0]).to.not.have.property('sni');
|
||
expect(external.proxies[0]).to.not.have.property('servername');
|
||
});
|
||
|
||
it('maps canonical shadowsocks tcp tls fields into Shadowrocket structured output', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS TCP',
|
||
server: 'ss.example.com',
|
||
port: 443,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
tls: true,
|
||
sni: 'a.com',
|
||
network: 'tcp',
|
||
};
|
||
|
||
const internal = produceInternal('Shadowrocket', proxy)[0];
|
||
const external = loadProducedYaml('Shadowrocket', proxy);
|
||
|
||
expectSubset(internal, {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS TCP',
|
||
tls: true,
|
||
network: 'tcp',
|
||
servername: 'a.com',
|
||
});
|
||
// expect(internal).to.not.have.property('sni');
|
||
expectSubset(external.proxies[0], {
|
||
type: 'ss',
|
||
name: 'Shadowrocket SS TLS TCP',
|
||
tls: true,
|
||
network: 'tcp',
|
||
servername: 'a.com',
|
||
});
|
||
// expect(external.proxies[0]).to.not.have.property('sni');
|
||
});
|
||
|
||
it('maps shadowsocks shadow-tls fields into Egern nested structures', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'ShadowTLS SS',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
'shadow-tls-password': 'shadow-pass',
|
||
'shadow-tls-sni': 'mask.example.com',
|
||
'shadow-tls-version': 3,
|
||
};
|
||
|
||
const internal = produceInternal('Egern', proxy)[0];
|
||
const external = loadProducedYaml('Egern', proxy);
|
||
|
||
expectSubset(internal, {
|
||
shadowsocks: {
|
||
name: 'ShadowTLS SS',
|
||
method: 'aes-128-gcm',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
password: 'secret',
|
||
shadow_tls: {
|
||
password: 'shadow-pass',
|
||
sni: 'mask.example.com',
|
||
},
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
shadowsocks: {
|
||
name: 'ShadowTLS SS',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('emits Egern HTTP and HTTPS root headers', function () {
|
||
const proxies = [
|
||
{
|
||
type: 'http',
|
||
name: 'Egern HTTP Headers',
|
||
server: 'http.example.com',
|
||
port: 8080,
|
||
username: 'user',
|
||
password: 'pass',
|
||
headers: {
|
||
'X-Client': 'Egern',
|
||
'X-Token': 'abc',
|
||
},
|
||
},
|
||
{
|
||
type: 'http',
|
||
name: 'Egern HTTPS Headers',
|
||
server: 'https.example.com',
|
||
port: 443,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
headers: {
|
||
'X-Padding': '<random-string(16-32)>',
|
||
},
|
||
},
|
||
];
|
||
|
||
const internal = produceInternal('Egern', proxies);
|
||
const external = loadProducedYaml('Egern', proxies);
|
||
|
||
expectSubset(internal[0], {
|
||
http: {
|
||
name: 'Egern HTTP Headers',
|
||
headers: {
|
||
'X-Client': 'Egern',
|
||
'X-Token': 'abc',
|
||
},
|
||
},
|
||
});
|
||
expectSubset(internal[1], {
|
||
https: {
|
||
name: 'Egern HTTPS Headers',
|
||
headers: {
|
||
'X-Padding': '<random-string(16-32)>',
|
||
},
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
http: {
|
||
headers: {
|
||
'X-Client': 'Egern',
|
||
'X-Token': 'abc',
|
||
},
|
||
},
|
||
});
|
||
expectSubset(external.proxies[1], {
|
||
https: {
|
||
headers: {
|
||
'X-Padding': '<random-string(16-32)>',
|
||
},
|
||
},
|
||
});
|
||
});
|
||
|
||
it('keeps Mihomo HTTP headers and filters unsupported h2-connect/trusttunnel header variants', function () {
|
||
const { result, errors } = captureErrors(() =>
|
||
produceInternal('Mihomo', [
|
||
{
|
||
type: 'http',
|
||
name: 'Mihomo HTTPS Headers',
|
||
server: 'https.example.com',
|
||
port: 443,
|
||
tls: true,
|
||
headers: {
|
||
'X-Token': 'abc',
|
||
},
|
||
},
|
||
{
|
||
type: 'h2-connect',
|
||
name: 'Mihomo H2 Headers',
|
||
server: 'h2.example.com',
|
||
port: 443,
|
||
headers: {
|
||
'X-Padding': '<random-string(16)>',
|
||
},
|
||
},
|
||
{
|
||
type: 'trusttunnel',
|
||
name: 'Mihomo Trust Headers',
|
||
server: 'trust.example.com',
|
||
port: 443,
|
||
headers: {
|
||
'X-Client': 'Surge',
|
||
},
|
||
},
|
||
]),
|
||
);
|
||
|
||
expect(result).to.have.length(1);
|
||
expectSubset(result[0], {
|
||
type: 'http',
|
||
name: 'Mihomo HTTPS Headers',
|
||
headers: {
|
||
'X-Token': 'abc',
|
||
},
|
||
});
|
||
expect(errors).to.have.length(2);
|
||
expect(errors[0]).to.include(
|
||
'Target platform Mihomo does not support headers for HTTP/2 CONNECT proxy Mihomo H2 Headers',
|
||
);
|
||
expect(errors[1]).to.include(
|
||
'Target platform Mihomo does not support headers for TrustTunnel proxy Mihomo Trust Headers',
|
||
);
|
||
});
|
||
|
||
it('keeps Mihomo h2-connect/trusttunnel header variants when include-unsupported-proxy is enabled', function () {
|
||
const { result, errors } = captureErrors(() =>
|
||
produceInternal(
|
||
'Mihomo',
|
||
[
|
||
{
|
||
type: 'h2-connect',
|
||
name: 'Mihomo H2 Headers',
|
||
server: 'h2.example.com',
|
||
port: 443,
|
||
headers: {
|
||
'X-Padding': '<random-string(16)>',
|
||
},
|
||
},
|
||
{
|
||
type: 'trusttunnel',
|
||
name: 'Mihomo Trust Headers',
|
||
server: 'trust.example.com',
|
||
port: 443,
|
||
headers: {
|
||
'X-Client': 'Surge',
|
||
},
|
||
},
|
||
],
|
||
{ 'include-unsupported-proxy': true },
|
||
),
|
||
);
|
||
|
||
expect(result).to.have.length(2);
|
||
expectSubset(result[0], {
|
||
type: 'h2-connect',
|
||
name: 'Mihomo H2 Headers',
|
||
headers: {
|
||
'X-Padding': '<random-string(16)>',
|
||
},
|
||
});
|
||
expectSubset(result[1], {
|
||
type: 'trusttunnel',
|
||
name: 'Mihomo Trust Headers',
|
||
headers: {
|
||
'X-Client': 'Surge',
|
||
},
|
||
});
|
||
expect(errors).to.have.length(0);
|
||
});
|
||
|
||
it('preserves supported HTTP root headers for sing-box and JSON outputs', function () {
|
||
const buildProxy = (name) => ({
|
||
type: 'http',
|
||
name,
|
||
server: 'http.example.com',
|
||
port: 8080,
|
||
username: 'user',
|
||
password: 'pass',
|
||
headers: {
|
||
'X-Token': 'abc',
|
||
},
|
||
});
|
||
|
||
const singBoxInternal = produceInternal(
|
||
'sing-box',
|
||
buildProxy('sing-box HTTP Headers'),
|
||
);
|
||
const singBoxExternal = loadProducedJson(
|
||
'sing-box',
|
||
buildProxy('sing-box HTTP Headers'),
|
||
);
|
||
const jsonExternal = loadProducedJson(
|
||
'JSON',
|
||
buildProxy('JSON HTTP Headers'),
|
||
);
|
||
|
||
expect(singBoxInternal).to.have.length(1);
|
||
expectSubset(singBoxInternal[0], {
|
||
type: 'http',
|
||
tag: 'sing-box HTTP Headers',
|
||
headers: {
|
||
'X-Token': 'abc',
|
||
},
|
||
});
|
||
expectSubset(singBoxExternal.outbounds[0], {
|
||
type: 'http',
|
||
tag: 'sing-box HTTP Headers',
|
||
headers: {
|
||
'X-Token': 'abc',
|
||
},
|
||
});
|
||
expectSubset(jsonExternal[0], {
|
||
type: 'http',
|
||
name: 'JSON HTTP Headers',
|
||
headers: {
|
||
'X-Token': 'abc',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('maps shadowsocks obfs plugin fields into Egern nested structures', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Egern SS Obfs TLS',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
plugin: 'obfs',
|
||
'plugin-opts': {
|
||
mode: 'tls',
|
||
host: 'legacy.example.com',
|
||
path: '/legacy',
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Egern', proxy)[0];
|
||
const external = loadProducedYaml('Egern', proxy);
|
||
|
||
expectSubset(internal, {
|
||
shadowsocks: {
|
||
name: 'Egern SS Obfs TLS',
|
||
method: 'aes-128-gcm',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
password: 'secret',
|
||
obfs: 'tls',
|
||
obfs_host: 'legacy.example.com',
|
||
obfs_uri: '/legacy',
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
shadowsocks: {
|
||
name: 'Egern SS Obfs TLS',
|
||
obfs: 'tls',
|
||
obfs_host: 'legacy.example.com',
|
||
obfs_uri: '/legacy',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('preserves numeric v2ray-plugin mux values across Clash-family YAML producers', function () {
|
||
const buildProxy = (name, mux) => ({
|
||
type: 'ss',
|
||
name,
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
'skip-cert-verify': false,
|
||
plugin: 'v2ray-plugin',
|
||
'plugin-opts': {
|
||
mode: 'websocket',
|
||
host: 'cdn.example.com',
|
||
path: '/socket',
|
||
tls: true,
|
||
'skip-cert-verify': true,
|
||
mux,
|
||
},
|
||
});
|
||
|
||
for (const platform of [
|
||
'Clash',
|
||
'ClashMeta',
|
||
'Shadowrocket',
|
||
'Stash',
|
||
]) {
|
||
const internal = produceInternal(platform, [
|
||
buildProxy(`${platform} Mux On`, 1),
|
||
buildProxy(`${platform} Mux Off`, 0),
|
||
]);
|
||
|
||
expect(internal, platform).to.have.length(2);
|
||
expectSubset(internal[0], {
|
||
name: `${platform} Mux On`,
|
||
'plugin-opts': {
|
||
tls: true,
|
||
'skip-cert-verify': true,
|
||
mux: 1,
|
||
},
|
||
});
|
||
expectSubset(internal[1], {
|
||
name: `${platform} Mux Off`,
|
||
'plugin-opts': {
|
||
tls: true,
|
||
'skip-cert-verify': true,
|
||
mux: 0,
|
||
},
|
||
});
|
||
}
|
||
});
|
||
|
||
it('keeps legacy single-line proxy output by default for Clash-style YAML producers', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Legacy YAML',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
};
|
||
|
||
for (const platform of [
|
||
'Clash',
|
||
'ClashMeta',
|
||
'Shadowrocket',
|
||
'Stash',
|
||
'Egern',
|
||
]) {
|
||
const output = produceExternal(platform, proxy);
|
||
|
||
expect(output, platform).to.match(/\n {2}- \{/);
|
||
}
|
||
});
|
||
|
||
it('emits pretty yaml for Clash-style YAML producers when prettyYaml is enabled', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Real YAML',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
};
|
||
|
||
for (const platform of [
|
||
'Clash',
|
||
'ClashMeta',
|
||
'Shadowrocket',
|
||
'Stash',
|
||
'Egern',
|
||
]) {
|
||
const output = produceExternal(platform, proxy, {
|
||
prettyYaml: true,
|
||
});
|
||
const external = loadProducedYaml(platform, proxy, {
|
||
prettyYaml: true,
|
||
});
|
||
|
||
expect(output, platform).to.not.match(/\n {2}- \{/);
|
||
expect(external.proxies, platform).to.have.length(1);
|
||
|
||
if (platform === 'Egern') {
|
||
expectSubset(external.proxies[0], {
|
||
shadowsocks: {
|
||
name: 'Real YAML',
|
||
},
|
||
});
|
||
} else {
|
||
expectSubset(external.proxies[0], {
|
||
type: 'ss',
|
||
name: 'Real YAML',
|
||
});
|
||
}
|
||
}
|
||
});
|
||
|
||
it('emits WireGuard interface CIDR suffixes for Mihomo and Shadowrocket outputs', function () {
|
||
const proxies = [
|
||
{
|
||
type: 'wireguard',
|
||
name: 'WG Explicit CIDR',
|
||
server: 'wg-explicit.example.com',
|
||
port: 51820,
|
||
'private-key': 'private-key-1',
|
||
'public-key': 'public-key-1',
|
||
ip: '10.0.0.2',
|
||
ipv6: 'fd00::2',
|
||
'ip-cidr': 24,
|
||
'ipv6-cidr': 64,
|
||
},
|
||
{
|
||
type: 'wireguard',
|
||
name: 'WG Default CIDR',
|
||
server: 'wg-default.example.com',
|
||
port: 51820,
|
||
'private-key': 'private-key-2',
|
||
'public-key': 'public-key-2',
|
||
ip: '10.0.0.3',
|
||
ipv6: 'fd00::3',
|
||
},
|
||
];
|
||
|
||
for (const platform of ['Mihomo', 'Shadowrocket']) {
|
||
const output = loadProducedYaml(platform, proxies);
|
||
const explicit = output.proxies.find(
|
||
(proxy) => proxy.name === 'WG Explicit CIDR',
|
||
);
|
||
const defaults = output.proxies.find(
|
||
(proxy) => proxy.name === 'WG Default CIDR',
|
||
);
|
||
|
||
expectSubset(explicit, {
|
||
ip: '10.0.0.2/24',
|
||
ipv6: 'fd00::2/64',
|
||
});
|
||
expectSubset(defaults, {
|
||
ip: '10.0.0.3/32',
|
||
ipv6: 'fd00::3/128',
|
||
});
|
||
expect(explicit).to.not.have.property('ip-cidr');
|
||
expect(explicit).to.not.have.property('ipv6-cidr');
|
||
expect(defaults).to.not.have.property('ip-cidr');
|
||
expect(defaults).to.not.have.property('ipv6-cidr');
|
||
}
|
||
});
|
||
|
||
it('emits WireGuard address CIDR suffixes for sing-box exports', function () {
|
||
const output = loadProducedJson('sing-box', [
|
||
{
|
||
type: 'wireguard',
|
||
name: 'Sing-box WG Explicit CIDR',
|
||
server: 'wg-explicit.example.com',
|
||
port: 51820,
|
||
'private-key': 'private-key-1',
|
||
'public-key': 'public-key-1',
|
||
ip: '10.0.0.2',
|
||
ipv6: 'fd00::2',
|
||
'ip-cidr': 24,
|
||
'ipv6-cidr': 64,
|
||
},
|
||
{
|
||
type: 'wireguard',
|
||
name: 'Sing-box WG Default CIDR',
|
||
server: 'wg-default.example.com',
|
||
port: 51820,
|
||
'private-key': 'private-key-2',
|
||
'public-key': 'public-key-2',
|
||
ip: '10.0.0.3',
|
||
ipv6: 'fd00::3',
|
||
},
|
||
]);
|
||
|
||
const explicit = output.endpoints.find(
|
||
(endpoint) => endpoint.tag === 'Sing-box WG Explicit CIDR',
|
||
);
|
||
const defaults = output.endpoints.find(
|
||
(endpoint) => endpoint.tag === 'Sing-box WG Default CIDR',
|
||
);
|
||
|
||
expectSubset(explicit, {
|
||
type: 'wireguard',
|
||
address: ['10.0.0.2/24', 'fd00::2/64'],
|
||
});
|
||
expectSubset(defaults, {
|
||
type: 'wireguard',
|
||
address: ['10.0.0.3/32', 'fd00::3/128'],
|
||
});
|
||
});
|
||
|
||
it('emits Tailscale endpoint fields for sing-box exports', function () {
|
||
const output = loadProducedJson('sing-box', {
|
||
type: 'tailscale',
|
||
name: 'Mihomo TS',
|
||
'state-dir': './mihomo-ts',
|
||
'auth-key': 'tskey-auth-test',
|
||
'control-url': 'https://headscale.example.com',
|
||
ephemeral: true,
|
||
hostname: 'sub-store',
|
||
udp: true,
|
||
'accept-routes': true,
|
||
'exit-node': '100.64.0.1',
|
||
'exit-node-allow-lan-access': true,
|
||
'dialer-proxy': 'proxy-out',
|
||
'udp-timeout': '30s',
|
||
});
|
||
|
||
const mihomo = output.endpoints.find(
|
||
(endpoint) => endpoint.tag === 'Mihomo TS',
|
||
);
|
||
|
||
expectSubset(mihomo, {
|
||
type: 'tailscale',
|
||
state_directory: './mihomo-ts',
|
||
auth_key: 'tskey-auth-test',
|
||
control_url: 'https://headscale.example.com',
|
||
ephemeral: true,
|
||
hostname: 'sub-store',
|
||
accept_routes: true,
|
||
exit_node: '100.64.0.1',
|
||
exit_node_allow_lan_access: true,
|
||
detour: 'proxy-out',
|
||
udp_timeout: '30s',
|
||
});
|
||
expect(mihomo).to.not.have.property('udp');
|
||
});
|
||
|
||
it('does not mix Tailscale control_http_client with legacy sing-box dialer fields', function () {
|
||
const output = loadProducedJson('sing-box', {
|
||
type: 'tailscale',
|
||
name: 'Tailscale Control Client',
|
||
'control-http-client': {
|
||
detour: 'control-out',
|
||
},
|
||
'dialer-proxy': 'legacy-out',
|
||
});
|
||
|
||
const tailscale = output.endpoints.find(
|
||
(endpoint) => endpoint.tag === 'Tailscale Control Client',
|
||
);
|
||
|
||
expect(tailscale.control_http_client).to.deep.equal({
|
||
detour: 'control-out',
|
||
});
|
||
expect(tailscale).to.not.have.property('detour');
|
||
});
|
||
|
||
it('emits WireGuard interface CIDR suffixes for Egern exports', function () {
|
||
const proxies = [
|
||
{
|
||
type: 'wireguard',
|
||
name: 'Egern WG Explicit CIDR',
|
||
server: 'wg-explicit.example.com',
|
||
port: 51820,
|
||
'private-key': 'private-key-1',
|
||
'public-key': 'public-key-1',
|
||
ip: '10.0.0.2',
|
||
ipv6: 'fd00::2',
|
||
'ip-cidr': 24,
|
||
'ipv6-cidr': 64,
|
||
},
|
||
{
|
||
type: 'wireguard',
|
||
name: 'Egern WG Default CIDR',
|
||
server: 'wg-default.example.com',
|
||
port: 51820,
|
||
'private-key': 'private-key-2',
|
||
'public-key': 'public-key-2',
|
||
ip: '10.0.0.3',
|
||
ipv6: 'fd00::3',
|
||
},
|
||
];
|
||
|
||
const internal = produceInternal('Egern', proxies);
|
||
const external = loadProducedYaml('Egern', proxies);
|
||
|
||
const explicitInternal = internal.find(
|
||
(proxy) => proxy.wireguard?.name === 'Egern WG Explicit CIDR',
|
||
);
|
||
const defaultsInternal = internal.find(
|
||
(proxy) => proxy.wireguard?.name === 'Egern WG Default CIDR',
|
||
);
|
||
const explicitExternal = external.proxies.find(
|
||
(proxy) => proxy.wireguard?.name === 'Egern WG Explicit CIDR',
|
||
);
|
||
const defaultsExternal = external.proxies.find(
|
||
(proxy) => proxy.wireguard?.name === 'Egern WG Default CIDR',
|
||
);
|
||
|
||
for (const proxy of [
|
||
explicitInternal,
|
||
defaultsInternal,
|
||
explicitExternal,
|
||
defaultsExternal,
|
||
]) {
|
||
expect(proxy.wireguard).to.not.have.property('ip-cidr');
|
||
expect(proxy.wireguard).to.not.have.property('ipv6-cidr');
|
||
}
|
||
|
||
expectSubset(explicitInternal, {
|
||
wireguard: {
|
||
local_ipv4: '10.0.0.2/24',
|
||
local_ipv6: 'fd00::2/64',
|
||
},
|
||
});
|
||
expectSubset(defaultsInternal, {
|
||
wireguard: {
|
||
local_ipv4: '10.0.0.3/32',
|
||
local_ipv6: 'fd00::3/128',
|
||
},
|
||
});
|
||
expectSubset(explicitExternal, {
|
||
wireguard: {
|
||
local_ipv4: '10.0.0.2/24',
|
||
local_ipv6: 'fd00::2/64',
|
||
},
|
||
});
|
||
expectSubset(defaultsExternal, {
|
||
wireguard: {
|
||
local_ipv4: '10.0.0.3/32',
|
||
local_ipv6: 'fd00::3/128',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('filters canonical shadowsocks over-tls nodes for unsupported client targets by default', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Unsupported SS TLS',
|
||
server: 'ss.example.com',
|
||
port: 443,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
tls: true,
|
||
sni: 'a.com',
|
||
};
|
||
|
||
for (const platform of [
|
||
'Clash',
|
||
'ClashMeta',
|
||
'Mihomo',
|
||
'Stash',
|
||
'Loon',
|
||
'Surge',
|
||
'SurgeMac',
|
||
'Surfboard',
|
||
'Egern',
|
||
'sing-box',
|
||
'URI',
|
||
'V2Ray',
|
||
]) {
|
||
expect(produceInternal(platform, proxy), platform).to.have.length(
|
||
0,
|
||
);
|
||
}
|
||
|
||
expect(ProxyUtils.produce([proxy], 'Clash', 'external')).to.equal(
|
||
'proxies:\n',
|
||
);
|
||
expect(ProxyUtils.produce([proxy], 'Loon', 'external')).to.equal('');
|
||
expect(ProxyUtils.produce([proxy], 'URI', 'external')).to.equal('');
|
||
expect(produceInternal('QX', proxy), 'QX').to.have.length(1);
|
||
expect(
|
||
produceInternal('Shadowrocket', proxy),
|
||
'Shadowrocket',
|
||
).to.have.length(1);
|
||
});
|
||
|
||
it('keeps canonical shadowsocks over-tls nodes when include-unsupported-proxy is enabled for Clash', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Clash SS TLS',
|
||
server: 'ss.example.com',
|
||
port: 443,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
tls: true,
|
||
sni: 'a.com',
|
||
};
|
||
|
||
const internal = produceInternal('Clash', proxy, {
|
||
'include-unsupported-proxy': true,
|
||
});
|
||
|
||
expect(internal).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
type: 'ss',
|
||
name: 'Clash SS TLS',
|
||
tls: true,
|
||
sni: 'a.com',
|
||
});
|
||
});
|
||
|
||
it('still treats canonical shadowsocks tls nodes without sni as unsupported for disallowed targets', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Unsupported SS TLS No Host',
|
||
server: 'ss.example.com',
|
||
port: 443,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
tls: true,
|
||
};
|
||
|
||
expect(produceInternal('Clash', proxy)).to.have.length(0);
|
||
expect(produceExternal('Clash', proxy)).to.equal('proxies:\n');
|
||
});
|
||
|
||
it('still treats canonical shadowsocks tcp tls nodes as unsupported for disallowed targets', function () {
|
||
const proxy = {
|
||
type: 'ss',
|
||
name: 'Unsupported SS TLS TCP',
|
||
server: 'ss.example.com',
|
||
port: 443,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
tls: true,
|
||
sni: 'a.com',
|
||
network: 'tcp',
|
||
};
|
||
|
||
expect(produceInternal('Clash', proxy)).to.have.length(0);
|
||
expect(ProxyUtils.produce([proxy], 'URI', 'external')).to.equal('');
|
||
});
|
||
|
||
it('skips invalid Egern nodes and keeps the rest of the subscription', function () {
|
||
const proxies = [
|
||
{
|
||
type: 'vless',
|
||
name: 'Invalid VLESS',
|
||
server: 'invalid.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
encryption: 'aes-128-gcm',
|
||
},
|
||
{
|
||
type: 'ss',
|
||
name: 'Healthy SS',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
},
|
||
];
|
||
|
||
const internal = produceInternal('Egern', proxies);
|
||
const external = loadProducedYaml('Egern', proxies);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expect(external.proxies).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
shadowsocks: {
|
||
name: 'Healthy SS',
|
||
method: 'aes-128-gcm',
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
shadowsocks: {
|
||
name: 'Healthy SS',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('skips Egern shadowsocks proxies with unsupported plugins and keeps the rest of the subscription', function () {
|
||
const proxies = [
|
||
{
|
||
type: 'ss',
|
||
name: 'Invalid SS Plugin',
|
||
server: 'invalid.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
plugin: 'v2ray-plugin',
|
||
'plugin-opts': {
|
||
mode: 'websocket',
|
||
host: 'cdn.example.com',
|
||
path: '/socket',
|
||
tls: true,
|
||
},
|
||
},
|
||
{
|
||
type: 'ss',
|
||
name: 'Healthy SS',
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
},
|
||
];
|
||
|
||
const internal = produceInternal('Egern', proxies);
|
||
const external = loadProducedYaml('Egern', proxies);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expect(external.proxies).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
shadowsocks: {
|
||
name: 'Healthy SS',
|
||
method: 'aes-128-gcm',
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
shadowsocks: {
|
||
name: 'Healthy SS',
|
||
},
|
||
});
|
||
});
|
||
|
||
it('keeps numeric v2ray-plugin mux state in sing-box plugin opts', function () {
|
||
const buildProxy = (name, mux) => ({
|
||
type: 'ss',
|
||
name,
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
plugin: 'v2ray-plugin',
|
||
'plugin-opts': {
|
||
mode: 'websocket',
|
||
host: 'cdn.example.com',
|
||
path: '/socket',
|
||
tls: true,
|
||
mux,
|
||
},
|
||
});
|
||
|
||
const output = loadProducedJson('sing-box', [
|
||
buildProxy('Sing-box Mux On', 1),
|
||
buildProxy('Sing-box Mux Off', 0),
|
||
]);
|
||
const muxOn = output.outbounds.find(
|
||
(outbound) => outbound.tag === 'Sing-box Mux On',
|
||
);
|
||
const muxOff = output.outbounds.find(
|
||
(outbound) => outbound.tag === 'Sing-box Mux Off',
|
||
);
|
||
|
||
expect(output.outbounds).to.have.length(2);
|
||
expectSubset(muxOn, {
|
||
tag: 'Sing-box Mux On',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
multiplex: {
|
||
enabled: true,
|
||
},
|
||
});
|
||
expect(muxOn.plugin_opts).to.include('mux=1');
|
||
|
||
expectSubset(muxOff, {
|
||
tag: 'Sing-box Mux Off',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
});
|
||
expect(muxOff).to.not.have.property('multiplex');
|
||
expect(muxOff.plugin_opts).to.include('mux=0');
|
||
});
|
||
|
||
it('normalizes boolean v2ray-plugin mux state in sing-box plugin opts', function () {
|
||
const buildProxy = (name, mux) => ({
|
||
type: 'ss',
|
||
name,
|
||
server: 'ss.example.com',
|
||
port: 8388,
|
||
cipher: 'aes-128-gcm',
|
||
password: 'secret',
|
||
plugin: 'v2ray-plugin',
|
||
'plugin-opts': {
|
||
mode: 'websocket',
|
||
host: 'cdn.example.com',
|
||
path: '/socket',
|
||
tls: true,
|
||
mux,
|
||
},
|
||
});
|
||
|
||
const output = loadProducedJson('sing-box', [
|
||
buildProxy('Sing-box Boolean Mux On', true),
|
||
buildProxy('Sing-box Boolean Mux Off', false),
|
||
]);
|
||
const muxOn = output.outbounds.find(
|
||
(outbound) => outbound.tag === 'Sing-box Boolean Mux On',
|
||
);
|
||
const muxOff = output.outbounds.find(
|
||
(outbound) => outbound.tag === 'Sing-box Boolean Mux Off',
|
||
);
|
||
|
||
expectSubset(muxOn, {
|
||
tag: 'Sing-box Boolean Mux On',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
multiplex: {
|
||
enabled: true,
|
||
},
|
||
});
|
||
expect(muxOn.plugin_opts).to.include('mux=1');
|
||
|
||
expectSubset(muxOff, {
|
||
tag: 'Sing-box Boolean Mux Off',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
});
|
||
expect(muxOff).to.not.have.property('multiplex');
|
||
expect(muxOff.plugin_opts).to.include('mux=0');
|
||
});
|
||
|
||
it('round-trips Clash-style boolean v2ray-plugin mux flags into sing-box exports', function () {
|
||
const proxies = ProxyUtils.parse(`proxies:
|
||
- name: Clash Boolean Mux On
|
||
type: ss
|
||
server: ss.example.com
|
||
port: 8388
|
||
cipher: aes-128-gcm
|
||
password: secret
|
||
plugin: v2ray-plugin
|
||
plugin-opts:
|
||
mode: websocket
|
||
host: cdn.example.com
|
||
path: /socket
|
||
tls: true
|
||
mux: true
|
||
- name: Clash Boolean Mux Off
|
||
type: ss
|
||
server: ss.example.com
|
||
port: 8388
|
||
cipher: aes-128-gcm
|
||
password: secret
|
||
plugin: v2ray-plugin
|
||
plugin-opts:
|
||
mode: websocket
|
||
host: cdn.example.com
|
||
path: /socket
|
||
tls: true
|
||
mux: false
|
||
`);
|
||
|
||
const output = loadProducedJson('sing-box', proxies);
|
||
const muxOn = output.outbounds.find(
|
||
(outbound) => outbound.tag === 'Clash Boolean Mux On',
|
||
);
|
||
const muxOff = output.outbounds.find(
|
||
(outbound) => outbound.tag === 'Clash Boolean Mux Off',
|
||
);
|
||
|
||
expectSubset(muxOn, {
|
||
tag: 'Clash Boolean Mux On',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
multiplex: {
|
||
enabled: true,
|
||
},
|
||
});
|
||
expect(muxOn.plugin_opts).to.include('mux=1');
|
||
|
||
expectSubset(muxOff, {
|
||
tag: 'Clash Boolean Mux Off',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
});
|
||
expect(muxOff).to.not.have.property('multiplex');
|
||
expect(muxOff.plugin_opts).to.include('mux=0');
|
||
});
|
||
|
||
it('round-trips Clash-style string boolean v2ray-plugin mux flags into sing-box exports', function () {
|
||
const proxies = ProxyUtils.parse(`proxies:
|
||
- name: Clash String Mux On
|
||
type: ss
|
||
server: ss.example.com
|
||
port: 8388
|
||
cipher: aes-128-gcm
|
||
password: secret
|
||
plugin: v2ray-plugin
|
||
plugin-opts:
|
||
mode: websocket
|
||
host: cdn.example.com
|
||
path: /socket
|
||
tls: true
|
||
mux: ' TRUE '
|
||
- name: Clash String Mux Off
|
||
type: ss
|
||
server: ss.example.com
|
||
port: 8388
|
||
cipher: aes-128-gcm
|
||
password: secret
|
||
plugin: v2ray-plugin
|
||
plugin-opts:
|
||
mode: websocket
|
||
host: cdn.example.com
|
||
path: /socket
|
||
tls: true
|
||
mux: ' false '
|
||
`);
|
||
|
||
const output = loadProducedJson('sing-box', proxies);
|
||
const muxOn = output.outbounds.find(
|
||
(outbound) => outbound.tag === 'Clash String Mux On',
|
||
);
|
||
const muxOff = output.outbounds.find(
|
||
(outbound) => outbound.tag === 'Clash String Mux Off',
|
||
);
|
||
|
||
expectSubset(muxOn, {
|
||
tag: 'Clash String Mux On',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
multiplex: {
|
||
enabled: true,
|
||
},
|
||
});
|
||
expect(muxOn.plugin_opts).to.include('mux=1');
|
||
|
||
expectSubset(muxOff, {
|
||
tag: 'Clash String Mux Off',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
});
|
||
expect(muxOff).to.not.have.property('multiplex');
|
||
expect(muxOff.plugin_opts).to.include('mux=0');
|
||
});
|
||
|
||
it('treats string v2ray-plugin mux values from legacy JSON payloads as disabled in sing-box exports', function () {
|
||
const legacy = 'YWVzLTEyOC1nY206c2VjcmV0QHNzLmV4YW1wbGUuY29tOjgzODg=';
|
||
const plugin =
|
||
'eyJtb2RlIjoid2Vic29ja2V0IiwiaG9zdCI6ImNkbi5leGFtcGxlLmNvbSIsInBhdGgiOiIvc29ja2V0IiwidGxzIjp0cnVlLCJtdXgiOiIwIn0=';
|
||
|
||
const proxies = ProxyUtils.parse(
|
||
`ss://${legacy}?v2ray-plugin=${plugin}#Legacy%20JSON%20Mux%20Off`,
|
||
);
|
||
const output = loadProducedJson('sing-box', proxies);
|
||
const outbound = output.outbounds.find(
|
||
(item) => item.tag === 'Legacy JSON Mux Off',
|
||
);
|
||
|
||
expectSubset(outbound, {
|
||
tag: 'Legacy JSON Mux Off',
|
||
type: 'shadowsocks',
|
||
plugin: 'v2ray-plugin',
|
||
});
|
||
expect(outbound).to.not.have.property('multiplex');
|
||
expect(outbound.plugin_opts).to.include('mux=0');
|
||
});
|
||
|
||
it('emits sing-box outbounds with reality tls and websocket transport', function () {
|
||
const output = loadProducedJson('sing-box', {
|
||
type: 'vless',
|
||
name: 'Reality',
|
||
server: 'vless.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
flow: 'xtls-rprx-vision',
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/ws?a=1&ed=2048&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
},
|
||
'reality-opts': {
|
||
'public-key': 'pubkey',
|
||
'short-id': '08',
|
||
},
|
||
});
|
||
|
||
expect(output.outbounds).to.have.length(1);
|
||
expect(output.endpoints).to.have.length(0);
|
||
expectSubset(output.outbounds[0], {
|
||
tag: 'Reality',
|
||
type: 'vless',
|
||
server: 'vless.example.com',
|
||
server_port: 443,
|
||
flow: 'xtls-rprx-vision',
|
||
tls: {
|
||
enabled: true,
|
||
server_name: 'vless.example.com',
|
||
reality: {
|
||
enabled: true,
|
||
public_key: 'pubkey',
|
||
short_id: '08',
|
||
},
|
||
utls: {
|
||
enabled: true,
|
||
fingerprint: 'chrome',
|
||
},
|
||
},
|
||
transport: {
|
||
type: 'ws',
|
||
path: '/ws?a=1&b=2',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
early_data_header_name: 'Sec-WebSocket-Protocol',
|
||
max_early_data: 2048,
|
||
},
|
||
});
|
||
});
|
||
|
||
it('emits sing-box httpupgrade transport without websocket early data fields', function () {
|
||
const output = loadProducedJson('sing-box', {
|
||
type: 'vless',
|
||
name: 'Upgrade',
|
||
server: 'vless-upgrade.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'ws',
|
||
'ws-opts': {
|
||
path: '/upgrade?a=1&ed=2048&b=2',
|
||
headers: {
|
||
Host: 'upgrade.example.com',
|
||
},
|
||
'v2ray-http-upgrade': true,
|
||
},
|
||
});
|
||
|
||
expect(output.outbounds).to.have.length(1);
|
||
expectSubset(output.outbounds[0], {
|
||
tag: 'Upgrade',
|
||
type: 'vless',
|
||
transport: {
|
||
type: 'httpupgrade',
|
||
path: '/upgrade?a=1&b=2',
|
||
host: 'upgrade.example.com',
|
||
},
|
||
});
|
||
expect(output.outbounds[0].transport).to.not.have.property(
|
||
'early_data_header_name',
|
||
);
|
||
expect(output.outbounds[0].transport).to.not.have.property(
|
||
'max_early_data',
|
||
);
|
||
});
|
||
|
||
it('normalizes sing-box ech PEM config strings with escaped newlines', function () {
|
||
const output = loadProducedJson('sing-box', {
|
||
type: 'vless',
|
||
name: 'ECH PEM',
|
||
server: 'ech.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
'ech-opts': {
|
||
enable: true,
|
||
config: [
|
||
'-----BEGIN ECH CONFIGS-----\\nZWNoLWNvbmZpZw==\\n-----END ECH CONFIGS-----',
|
||
],
|
||
},
|
||
});
|
||
|
||
expectSubset(output.outbounds[0], {
|
||
tag: 'ECH PEM',
|
||
tls: {
|
||
enabled: true,
|
||
server_name: 'ech.example.com',
|
||
ech: {
|
||
enabled: true,
|
||
config: [
|
||
'-----BEGIN ECH CONFIGS-----',
|
||
'ZWNoLWNvbmZpZw==',
|
||
'-----END ECH CONFIGS-----',
|
||
],
|
||
},
|
||
},
|
||
});
|
||
});
|
||
|
||
it('omits xhttp proxies from sing-box exports', function () {
|
||
const output = loadProducedJson('sing-box', {
|
||
type: 'vless',
|
||
name: 'XHTTP',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
network: 'xhttp',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
headers: {
|
||
Host: 'cdn.example.com',
|
||
},
|
||
mode: 'stream-up',
|
||
},
|
||
});
|
||
|
||
expect(output.outbounds).to.have.length(0);
|
||
expect(output.endpoints).to.have.length(0);
|
||
});
|
||
|
||
it('stringifies JSON producer outputs as plain arrays', function () {
|
||
const proxy = {
|
||
type: 'http',
|
||
name: 'JSON HTTP',
|
||
server: 'http.example.com',
|
||
port: 8080,
|
||
username: 'user',
|
||
password: 'pass',
|
||
};
|
||
|
||
const internal = produceInternal('JSON', proxy);
|
||
const external = loadProducedJson('JSON', proxy);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
type: 'http',
|
||
name: 'JSON HTTP',
|
||
});
|
||
expect(external).to.have.length(1);
|
||
expectSubset(external[0], {
|
||
type: 'http',
|
||
name: 'JSON HTTP',
|
||
});
|
||
});
|
||
|
||
it('blocks Mihomo xhttp reality-opts inheritance when upload has reality-opts but download does not', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP Reality No Download Reality',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'reality-opts': {
|
||
'public-key': 'upload-pubkey',
|
||
'short-id': 'ab',
|
||
},
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
mode: 'stream-up',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
path: '/download',
|
||
},
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
const external = loadProducedYaml('Mihomo', proxy);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
'xhttp-opts': {
|
||
'download-settings': {
|
||
'reality-opts': { 'public-key': '' },
|
||
},
|
||
},
|
||
});
|
||
expectSubset(external.proxies[0], {
|
||
'xhttp-opts': {
|
||
'download-settings': {
|
||
'reality-opts': { 'public-key': '' },
|
||
},
|
||
},
|
||
});
|
||
});
|
||
|
||
it('does not inject reality-opts blocker when download-settings already has reality-opts', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP Reality Both',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'reality-opts': {
|
||
'public-key': 'upload-pubkey',
|
||
'short-id': 'ab',
|
||
},
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
mode: 'stream-up',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
path: '/download',
|
||
'reality-opts': {
|
||
'public-key': 'download-pubkey',
|
||
'short-id': 'cd',
|
||
},
|
||
},
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
|
||
expect(internal).to.have.length(1);
|
||
expectSubset(internal[0], {
|
||
'xhttp-opts': {
|
||
'download-settings': {
|
||
'reality-opts': {
|
||
'public-key': 'download-pubkey',
|
||
'short-id': 'cd',
|
||
},
|
||
},
|
||
},
|
||
});
|
||
});
|
||
|
||
it('does not inject reality-opts blocker when upload has no reality-opts', function () {
|
||
const proxy = {
|
||
type: 'vless',
|
||
name: 'XHTTP No Reality',
|
||
server: 'vless-xhttp.example.com',
|
||
port: 443,
|
||
uuid: UUID,
|
||
tls: true,
|
||
sni: 'sni.example.com',
|
||
network: 'xhttp',
|
||
'xhttp-opts': {
|
||
path: '/xhttp',
|
||
mode: 'stream-up',
|
||
'download-settings': {
|
||
server: 'download.example.com',
|
||
port: 8443,
|
||
tls: true,
|
||
path: '/download',
|
||
},
|
||
},
|
||
};
|
||
|
||
const internal = produceInternal('Mihomo', proxy);
|
||
|
||
expect(internal).to.have.length(1);
|
||
const ds = internal[0]['xhttp-opts']['download-settings'];
|
||
expect(ds).to.not.have.property('reality-opts');
|
||
});
|
||
});
|