Preserve VLESS WebSocket variants during subscription refresh
Build and Deploy Gateway / build-and-push (push) Successful in 18s
Build and Deploy Gateway / deploy (push) Successful in 13s

This commit is contained in:
2026-08-09 12:42:05 +03:00
parent 90433d7cd8
commit f40221969b
7 changed files with 198 additions and 21 deletions
+73
View File
@@ -5,6 +5,7 @@ import {
parseSubscriptionBody,
selectRefreshedServer,
} from '../../dist/server/subscription.js';
import { createServerId } from '../../dist/shared/serverIdentity.js';
const parse = (outbounds) => parseSubscriptionBody(JSON.stringify({ outbounds }));
const outbound = (tag, server, server_port = 443) => ({
@@ -86,3 +87,75 @@ test('subscription parser rejects JSON primitives and arrays', () => {
);
}
});
test('mixed Base64 VLESS feed keeps Reality TCP and TLS WebSocket servers', () => {
const reality = 'vless://00000000-0000-4000-8000-000000000001@reality.example.test:443?security=reality&type=tcp&pbk=public-key&sid=short-id&sni=cover.example.test&fp=chrome#Reality';
const websocket = 'vless://00000000-0000-4000-8000-000000000002@ws.example.test:8443?encryption=none&security=tls&sni=edge.example.test&fp=firefox&alpn=h2%2Chttp%2F1.1&type=ws&host=edge.example.test&path=%2Fsocket%3Fed%3D2048#TLS%20WS';
const websocketVariant = 'vless://00000000-0000-4000-8000-000000000002@ws.example.test:8443?encryption=none&security=tls&sni=edge.example.test&fp=firefox&alpn=h2%2Chttp%2F1.1&type=ws&host=edge.example.test&path=%2Fsecond#TLS%20WS%202';
const { config, servers } = parseSubscriptionBody(
Buffer.from(`${reality}\n${websocket}\n${websocketVariant}`).toString('base64'),
);
const [realityOutbound, websocketOutbound, websocketVariantOutbound] = config.outbounds;
const singleton = parseSubscriptionBody(Buffer.from(websocket).toString('base64'));
const reordered = parseSubscriptionBody(
Buffer.from(`${websocketVariant.replace('TLS%20WS%202', 'Renamed')}\n${websocket.replace('TLS%20WS', 'Also%20renamed')}\n${reality}`).toString('base64'),
);
const idsByPath = (outbounds) => Object.fromEntries(outbounds
.filter((outbound) => outbound.transport?.type === 'ws')
.map((outbound) => [outbound.transport.path, outbound.tag]));
assert.equal(servers.length, 3);
assert.notEqual(websocketOutbound.tag, websocketVariantOutbound.tag);
assert.equal(singleton.servers[0].id, websocketOutbound.tag);
assert.notEqual(singleton.servers[0].id, createServerId(singleton.config.outbounds[0]));
assert.deepEqual(idsByPath(reordered.config.outbounds), idsByPath(config.outbounds));
assert.deepEqual(realityOutbound.tls.reality, {
enabled: true,
public_key: 'public-key',
short_id: 'short-id',
});
assert.equal(realityOutbound.transport, undefined);
assert.deepEqual(websocketOutbound.tls, {
enabled: true,
server_name: 'edge.example.test',
alpn: ['h2', 'http/1.1'],
utls: { enabled: true, fingerprint: 'firefox' },
});
assert.deepEqual(websocketOutbound.transport, {
type: 'ws',
path: '/socket?ed=2048',
headers: { Host: 'edge.example.test' },
});
assert.equal(websocketOutbound.packet_encoding, 'xudp');
assert.equal(websocketVariantOutbound.transport.path, '/second');
const legacyWebsocketId = createServerId(singleton.config.outbounds[0]);
const legacyWebsocket = [{ ...singleton.servers[0], id: legacyWebsocketId }];
assert.equal(selectRefreshedServer(
legacyWebsocketId,
legacyWebsocket,
singleton.servers,
), singleton.servers[0].id);
assert.equal(selectRefreshedServer(
legacyWebsocketId,
legacyWebsocket,
servers.slice(1),
), '');
assert.equal(selectRefreshedServer(
legacyWebsocketId,
legacyWebsocket,
[legacyWebsocket[0], singleton.servers[0]],
), '');
assert.equal(selectRefreshedServer(
websocketOutbound.tag,
servers,
[servers[0], servers[2]],
), '');
assert.throws(
() => parseSubscriptionBody('vless://00000000-0000-4000-8000-000000000003@grpc.example.test:443?security=tls&type=grpc&pbk=public-key&sid=short-id'),
(error) => error.code === 'SUBSCRIPTION_INVALID',
);
assert.equal(
parseSubscriptionBody(reality.replace('type=tcp', 'type=raw')).config.outbounds[0].transport,
undefined,
);
});