diff --git a/backend/src/test/proxy-parsers/uri.spec.js b/backend/src/test/proxy-parsers/uri.spec.js index 8fd98705..2557eb51 100644 --- a/backend/src/test/proxy-parsers/uri.spec.js +++ b/backend/src/test/proxy-parsers/uri.spec.js @@ -97,6 +97,37 @@ describe('Proxy URI parser coverage', function () { }); }); + it('parses shadowsocks v2ray-plugin URI flags for sni, skip-cert-verify, and mux', function () { + const userInfo = encodeURIComponent( + Base64.encode('aes-128-gcm:secret'), + ); + const plugin = encodeURIComponent( + 'v2ray-plugin;obfs=websocket;host=cdn.example.com;path=/socket;tls;sni=sni.example.com;skip-cert-verify=1;mux=1', + ); + const proxy = parseOne( + `ss://${userInfo}@ss.example.com:443/?plugin=${plugin}#SS%20V2ray%20Flags`, + ); + + expectSubset(proxy, { + type: 'ss', + name: 'SS V2ray Flags', + server: 'ss.example.com', + port: 443, + cipher: 'aes-128-gcm', + password: 'secret', + plugin: 'v2ray-plugin', + 'plugin-opts': { + mode: 'websocket', + host: 'cdn.example.com', + path: '/socket', + tls: true, + sni: 'sni.example.com', + 'skip-cert-verify': true, + mux: 1, + }, + }); + }); + it('parses v2ray-plugin paths containing escaped equals signs', function () { const userInfo = encodeURIComponent( Base64.encode('aes-128-gcm:secret'), diff --git a/backend/src/test/proxy-producers/structured.spec.js b/backend/src/test/proxy-producers/structured.spec.js index 709e736d..1611646b 100644 --- a/backend/src/test/proxy-producers/structured.spec.js +++ b/backend/src/test/proxy-producers/structured.spec.js @@ -520,6 +520,57 @@ describe('Proxy structured producers', function () { }); }); + it('normalizes 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: true, + }, + }); + expectSubset(internal[1], { + name: `${platform} Mux Off`, + 'plugin-opts': { + tls: true, + 'skip-cert-verify': true, + mux: false, + }, + }); + } + }); + it('skips invalid Egern nodes and keeps the rest of the subscription', function () { const proxies = [ { @@ -558,6 +609,55 @@ describe('Proxy structured producers', function () { }); }); + it('keeps normalized 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=true'); + + 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=false'); + }); + it('emits sing-box outbounds with reality tls and websocket transport', function () { const output = loadProducedJson('sing-box', { type: 'vless', diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index 6f51052e..dcda9a2e 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -241,6 +241,36 @@ describe('Proxy text producers', function () { expect(output).to.not.include('Forced Mihomo=tuic-v5'); }); + it('produces URI shadowsocks links with v2ray-plugin mux and tls flags', function () { + const plugin = encodeURIComponent( + 'v2ray-plugin;obfs=websocket;obfs-host=cdn.example.com;host=cdn.example.com;path=/socket;tls;sni=sni.example.com;skip-cert-verify=true;mux=0', + ); + const output = produceExternal('URI', { + type: 'ss', + name: 'SS V2ray Flags', + server: 'ss.example.com', + port: 443, + cipher: 'aes-128-gcm', + password: 'secret', + plugin: 'v2ray-plugin', + 'plugin-opts': { + mode: 'websocket', + host: 'cdn.example.com', + path: '/socket', + tls: true, + sni: 'sni.example.com', + 'skip-cert-verify': true, + mux: 0, + }, + }); + + expect(output).to.equal( + `ss://${Base64.encode( + 'aes-128-gcm:secret', + )}@ss.example.com:443/?plugin=${plugin}#SS%20V2ray%20Flags`, + ); + }); + it('produces URI VLESS reality websocket links', function () { const output = produceExternal('URI', { type: 'vless',