mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-01 18:56:05 +03:00
feat(finalmask): header-custom variables, sudoku UDP mask and noise reset ranges
xray-core 26.6 grew the finalmask surface the editor could not express, and the finalmask watch drops any key without a registered field, so a config written by hand lost these keys on the next save: - header-custom items can capture their bytes into a variable, reuse one or emit a transform expression; a Kind select keeps each item to exactly one kind, as the core requires, and only parsed JSON reaches transform; - TCP header-custom gains the errors group (the reply sent when a client group does not match), UDP header-custom its prefix/standalone mode; - sudoku is offered as a UDP mask, and share links keep it in fm=; - the noise reset is an Int32Range, so it now takes "60-120" as well. The new golden fixture is saved unchanged by the outbound editor and built by xray-core in TestGoldenStreamFixturesBuildInXray.
This commit is contained in:
@@ -38,6 +38,107 @@ exports[`FinalMaskStreamSettingsSchema fixtures > parses combined byte-stably 1`
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`FinalMaskStreamSettingsSchema fixtures > parses header-custom-variables byte-stably 1`] = `
|
||||
{
|
||||
"tcp": [
|
||||
{
|
||||
"settings": {
|
||||
"clients": [
|
||||
[
|
||||
{
|
||||
"capture": "nonce",
|
||||
"delay": 0,
|
||||
"rand": 8,
|
||||
"type": "array",
|
||||
},
|
||||
{
|
||||
"delay": 0,
|
||||
"packet": "HELLO",
|
||||
"type": "str",
|
||||
},
|
||||
],
|
||||
],
|
||||
"errors": [
|
||||
[
|
||||
{
|
||||
"delay": 0,
|
||||
"packet": "DENIED",
|
||||
"type": "str",
|
||||
},
|
||||
],
|
||||
],
|
||||
"servers": [
|
||||
[
|
||||
{
|
||||
"delay": 0,
|
||||
"reuse": "nonce",
|
||||
},
|
||||
{
|
||||
"delay": 0,
|
||||
"transform": {
|
||||
"args": [
|
||||
{
|
||||
"bytes": "OK ",
|
||||
"type": "str",
|
||||
},
|
||||
{
|
||||
"reuse": "nonce",
|
||||
},
|
||||
],
|
||||
"op": "concat",
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
"type": "header-custom",
|
||||
},
|
||||
],
|
||||
"udp": [
|
||||
{
|
||||
"settings": {
|
||||
"client": [
|
||||
{
|
||||
"capture": "token",
|
||||
"rand": 8,
|
||||
"type": "array",
|
||||
},
|
||||
],
|
||||
"mode": "standalone",
|
||||
"server": [
|
||||
{
|
||||
"reuse": "token",
|
||||
},
|
||||
],
|
||||
},
|
||||
"type": "header-custom",
|
||||
},
|
||||
{
|
||||
"settings": {
|
||||
"ascii": "prefer_entropy",
|
||||
"paddingMax": 7,
|
||||
"paddingMin": 2,
|
||||
"password": "s3cr3t",
|
||||
},
|
||||
"type": "sudoku",
|
||||
},
|
||||
{
|
||||
"settings": {
|
||||
"noise": [
|
||||
{
|
||||
"delay": "10-16",
|
||||
"rand": "10-20",
|
||||
"type": "array",
|
||||
},
|
||||
],
|
||||
"reset": "60-120",
|
||||
},
|
||||
"type": "noise",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`FinalMaskStreamSettingsSchema fixtures > parses quic-params byte-stably 1`] = `
|
||||
{
|
||||
"quicParams": {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"tcp": [
|
||||
{
|
||||
"type": "header-custom",
|
||||
"settings": {
|
||||
"clients": [
|
||||
[
|
||||
{ "delay": 0, "type": "array", "rand": 8, "capture": "nonce" },
|
||||
{ "delay": 0, "type": "str", "packet": "HELLO" }
|
||||
]
|
||||
],
|
||||
"servers": [
|
||||
[
|
||||
{ "delay": 0, "reuse": "nonce" },
|
||||
{
|
||||
"delay": 0,
|
||||
"transform": {
|
||||
"op": "concat",
|
||||
"args": [{ "type": "str", "bytes": "OK " }, { "reuse": "nonce" }]
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"errors": [[{ "delay": 0, "type": "str", "packet": "DENIED" }]]
|
||||
}
|
||||
}
|
||||
],
|
||||
"udp": [
|
||||
{
|
||||
"type": "header-custom",
|
||||
"settings": {
|
||||
"mode": "standalone",
|
||||
"client": [{ "type": "array", "rand": 8, "capture": "token" }],
|
||||
"server": [{ "reuse": "token" }]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "sudoku",
|
||||
"settings": {
|
||||
"password": "s3cr3t",
|
||||
"ascii": "prefer_entropy",
|
||||
"paddingMin": 2,
|
||||
"paddingMax": 7
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "noise",
|
||||
"settings": {
|
||||
"reset": "60-120",
|
||||
"noise": [{ "type": "array", "rand": "10-20", "delay": "10-16" }]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -516,3 +516,135 @@ describe('OutboundFormModal UDP hop', () => {
|
||||
expect(payload.streamSettings.finalmask.quicParams?.congestion).toBe('bbr');
|
||||
});
|
||||
});
|
||||
|
||||
describe('OutboundFormModal finalmask variables', () => {
|
||||
function xhttpOutbound(finalmask: Record<string, unknown>) {
|
||||
return {
|
||||
protocol: 'vless',
|
||||
tag: 'masked',
|
||||
settings: {
|
||||
vnext: [
|
||||
{
|
||||
address: 'example.com',
|
||||
port: 443,
|
||||
users: [{ id: 'c9f0c2d0-0000-4000-8000-000000000000', encryption: 'none' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
streamSettings: {
|
||||
network: 'xhttp',
|
||||
security: 'none',
|
||||
xhttpSettings: { path: '/', mode: 'auto' },
|
||||
finalmask,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function saveFinalmask(
|
||||
finalmask: Record<string, unknown>,
|
||||
edit: () => void = () => {},
|
||||
): Promise<Record<string, unknown>> {
|
||||
const onConfirm = vi.fn();
|
||||
const queryClient = makeTestQueryClient();
|
||||
const tree = (open: boolean) => (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ThemeProvider>
|
||||
<OutboundFormModal
|
||||
open={open}
|
||||
outbound={xhttpOutbound(finalmask)}
|
||||
existingTags={[]}
|
||||
onClose={() => {}}
|
||||
onConfirm={onConfirm}
|
||||
/>
|
||||
</ThemeProvider>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
const { rerender } = render(tree(false));
|
||||
rerender(tree(true));
|
||||
await act(async () => {
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
});
|
||||
edit();
|
||||
await act(async () => {
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
});
|
||||
|
||||
const ok = document.querySelector('.ant-modal-footer .ant-btn-primary') as HTMLElement;
|
||||
await act(async () => {
|
||||
fireEvent.click(ok);
|
||||
});
|
||||
await act(async () => {
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
});
|
||||
expect(onConfirm).toHaveBeenCalledTimes(1);
|
||||
return (
|
||||
onConfirm.mock.calls[0][0] as { streamSettings: { finalmask: Record<string, unknown> } }
|
||||
).streamSettings.finalmask;
|
||||
}
|
||||
|
||||
function typeInto(label: string, value: string) {
|
||||
const input = formItemByLabel(label)?.querySelector('input, textarea');
|
||||
if (!input) throw new Error(`${label} input not found`);
|
||||
fireEvent.change(input, { target: { value } });
|
||||
}
|
||||
|
||||
// xray-core 26.6 header-custom variables, error replies and standalone UDP headers, plus
|
||||
// the sudoku UDP mask; the same fixture is built by Go's TestGoldenStreamFixturesBuildInXray.
|
||||
it('keeps every header-custom variable, sudoku UDP mask and noise reset range on save', async () => {
|
||||
const fixture = (await import('./golden/fixtures/finalmask/header-custom-variables.json'))
|
||||
.default as Record<string, unknown>;
|
||||
|
||||
expect(await saveFinalmask(structuredClone(fixture))).toEqual(fixture);
|
||||
});
|
||||
|
||||
// The core rejects an item carrying two kinds ("exactly one item kind must be set").
|
||||
it('drops the bytes of an item switched to reuse a variable', async () => {
|
||||
const finalmask = await saveFinalmask(
|
||||
{
|
||||
udp: [
|
||||
{
|
||||
type: 'header-custom',
|
||||
settings: { client: [{ type: 'array', rand: 4, randRange: '0-255' }], server: [] },
|
||||
},
|
||||
],
|
||||
},
|
||||
() => {
|
||||
chooseOptionByLabel('Kind', 'Reuse variable');
|
||||
typeInto('Reuse', 'nonce');
|
||||
},
|
||||
);
|
||||
|
||||
expect(finalmask.udp).toEqual([
|
||||
{ type: 'header-custom', settings: { client: [{ reuse: 'nonce' }], server: [] } },
|
||||
]);
|
||||
});
|
||||
|
||||
// A string transform fails the whole core config, so half-typed JSON must never be saved.
|
||||
it.each([
|
||||
['{"op": "be16", "args": [{"u64": 7}]}', [{ transform: { op: 'be16', args: [{ u64: 7 }] } }]],
|
||||
['{"op": "be16"', [{}]],
|
||||
])('saves the typed transform %s only once it parses', async (typed, client) => {
|
||||
const finalmask = await saveFinalmask(
|
||||
{
|
||||
udp: [
|
||||
{ type: 'header-custom', settings: { client: [{ type: 'array', rand: 4 }], server: [] } },
|
||||
],
|
||||
},
|
||||
() => {
|
||||
chooseOptionByLabel('Kind', 'Transform');
|
||||
typeInto('Transform', typed);
|
||||
},
|
||||
);
|
||||
|
||||
expect(finalmask.udp).toEqual([{ type: 'header-custom', settings: { client, server: [] } }]);
|
||||
});
|
||||
|
||||
it('saves a noise reset typed as a range', async () => {
|
||||
const finalmask = await saveFinalmask(
|
||||
{ udp: [{ type: 'noise', settings: { reset: 0, noise: [] } }] },
|
||||
() => typeInto('Reset', '60-120'),
|
||||
);
|
||||
|
||||
expect(finalmask.udp).toEqual([{ type: 'noise', settings: { reset: '60-120', noise: [] } }]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user