mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-13 01:14:59 +03:00
73a028f52d
Move the three Xray binary pins (DockerInit.sh, both release.yml
fetches) to v26.10.10, in lockstep with the xtls/xray-core module that
82c77111 already bumped to 701af60772cd.
xdns finalmask (#7090): a domain now takes a "names" list instead of a
single "name", and a resolver is an "addrs" list of udp:// or tcp://
URLs instead of {type, settings:{addr}}. The loader ignores the old
keys rather than failing, so every mask the 26.9.30 seeder wrote would
load with no domain and no resolver and the tunnel would carry nothing.
maskcompat.UpgradeLegacyXdns now lifts both the pre-26.9.30 string lists
and the 26.9.30 objects straight to names/addrs, dropping entries the
old loader refused. A new seeder (XdnsFinalmaskNamesAddrsFix) reruns it
over every stored finalmask, and the save path, GetXrayConfig, both
link importers and the mask editor's mount lift go through it. Template
outbounds now get the build-time heal too: a 26.9.30 template pasted
after the seeder passes the save check, since the core loads that shape
without error. The editor edits names and addrs as tag lists and no
longer requires record types, which the core now defaults (TXT on a
client, A/CNAME/TXT/AAAA on a server). The wire format did not change,
but clients on an older core cannot read the new config shape.
Lua scripts (#6823): dns.script, routing.script and dns servers[].id
are new. The xray page parsed the dns block with a strict schema, so
loading it dropped script and id and the next save deleted them; the
schema now keeps both and the DNS server modal carries the id through
an edit. The hot routing apply built routing in-process, and that build
now resolves the script file from the panel's working directory, so a
script beside the xray binary failed every rule change into a full
restart and broke the node bridge. RoutingService cannot change the
script anyway, so the panel no longer resolves it there.
TLS client roots (#7105): the core now verifies against its bundled
Mozilla roots instead of the OS store unless tlsSettings.useSystemCA is
set. The outbound TLS form gets a switch for it, so an outbound to a
server signed by a privately installed CA can opt back in.
142 lines
5.7 KiB
TypeScript
142 lines
5.7 KiB
TypeScript
import type { ReactNode } from 'react';
|
|
import { act, renderHook, waitFor } from '@testing-library/react';
|
|
import { QueryClientProvider } from '@tanstack/react-query';
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { useXraySetting } from '@/hooks/useXraySetting';
|
|
import { makeTestQueryClient } from '@/test/test-utils';
|
|
import { HttpUtil, Msg } from '@/utils';
|
|
|
|
function xrayPayload(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
xraySetting: {},
|
|
inboundTags: [],
|
|
clientReverseTags: [],
|
|
outboundTestUrl: 'https://test.example',
|
|
subscriptionOutbounds: [],
|
|
subscriptionOutboundTags: [],
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
vi.spyOn(HttpUtil, 'get').mockResolvedValue(new Msg(true, '', []));
|
|
});
|
|
|
|
describe('useXraySetting', () => {
|
|
it('refreshes server-derived outbounds while the editor is dirty', async () => {
|
|
let payload = xrayPayload({ subscriptionOutbounds: [{ tag: 'before' }] });
|
|
vi.spyOn(HttpUtil, 'post').mockImplementation(async (url) => {
|
|
if (url === '/panel/api/xray/') return new Msg(true, '', JSON.stringify(payload));
|
|
return new Msg(true, '');
|
|
});
|
|
const queryClient = makeTestQueryClient();
|
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
);
|
|
const { result } = renderHook(() => useXraySetting(), { wrapper });
|
|
|
|
await waitFor(() => expect(result.current.fetched).toBe(true));
|
|
act(() => result.current.setXraySetting('{"outbounds":[]}'));
|
|
payload = xrayPayload({ subscriptionOutbounds: [{ tag: 'after' }] });
|
|
await act(async () => result.current.fetchAll());
|
|
|
|
await waitFor(() => expect(result.current.subscriptionOutbounds).toEqual([{ tag: 'after' }]));
|
|
expect(result.current.xraySetting).toBe('{"outbounds":[]}');
|
|
});
|
|
|
|
// xray-core 26.10.10 runs a Lua dns.script that addresses servers by id; stripped
|
|
// on load, the next template save would silently delete both.
|
|
it('keeps the dns script and server ids through the load', async () => {
|
|
const payload = xrayPayload({
|
|
xraySetting: {
|
|
dns: { script: 'dns.lua', servers: [{ address: '1.1.1.1', port: 53, id: 'cf' }] },
|
|
},
|
|
});
|
|
vi.spyOn(HttpUtil, 'post').mockImplementation(async (url) => {
|
|
if (url === '/panel/api/xray/') return new Msg(true, '', JSON.stringify(payload));
|
|
return new Msg(true, '');
|
|
});
|
|
const queryClient = makeTestQueryClient();
|
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
);
|
|
const { result } = renderHook(() => useXraySetting(), { wrapper });
|
|
|
|
await waitFor(() => expect(result.current.fetched).toBe(true));
|
|
const loaded = JSON.parse(result.current.xraySetting) as {
|
|
dns: { script?: string; servers: Array<Record<string, unknown>> };
|
|
};
|
|
expect(loaded.dns.script).toBe('dns.lua');
|
|
expect(loaded.dns.servers[0].id).toBe('cf');
|
|
});
|
|
|
|
it('keeps the outbound test URL input empty when it is cleared', async () => {
|
|
const payload = xrayPayload({ outboundTestUrl: 'https://www.google.com/generate_204' });
|
|
vi.spyOn(HttpUtil, 'post').mockImplementation(async (url) => {
|
|
if (url === '/panel/api/xray/') return new Msg(true, '', JSON.stringify(payload));
|
|
return new Msg(true, '');
|
|
});
|
|
const queryClient = makeTestQueryClient();
|
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
);
|
|
const { result } = renderHook(() => useXraySetting(), { wrapper });
|
|
|
|
await waitFor(() => expect(result.current.fetched).toBe(true));
|
|
act(() => result.current.setOutboundTestUrl(''));
|
|
|
|
expect(result.current.outboundTestUrl).toBe('');
|
|
expect(result.current.saveDisabled).toBe(true);
|
|
});
|
|
|
|
// The core lowercases a protocol id and a transport name before resolving
|
|
// either, so a differently spelled UDP outbound must still skip the TCP dial.
|
|
it.each<[string, Record<string, unknown>, string]>([
|
|
['probes a canonical UDP outbound over HTTP', { protocol: 'wireguard', tag: 'wg' }, 'http'],
|
|
[
|
|
'probes a "WireGuard"-spelled outbound over HTTP',
|
|
{ protocol: 'WireGuard', tag: 'wg' },
|
|
'http',
|
|
],
|
|
['probes a "HyStErIa"-spelled outbound over HTTP', { protocol: 'HyStErIa', tag: 'hy' }, 'http'],
|
|
[
|
|
'probes a "KCP" transport over HTTP',
|
|
{ protocol: 'vless', tag: 'kcp', streamSettings: { network: 'KCP' } },
|
|
'http',
|
|
],
|
|
[
|
|
'probes an "mkcp" transport over HTTP',
|
|
{ protocol: 'vless', tag: 'mkcp', streamSettings: { network: 'mkcp' } },
|
|
'http',
|
|
],
|
|
['probes a plain vless outbound over TCP', { protocol: 'vless', tag: 'plain' }, 'tcp'],
|
|
])('%s', async (_name, outbound, want) => {
|
|
const bodies: Array<Record<string, unknown>> = [];
|
|
vi.spyOn(HttpUtil, 'post').mockImplementation(async (url, data) => {
|
|
if (url === '/panel/api/xray/') {
|
|
return new Msg(true, '', JSON.stringify(xrayPayload()));
|
|
}
|
|
bodies.push(data as Record<string, unknown>);
|
|
return new Msg(true, '', [{ success: true, mode: 'http' }]);
|
|
});
|
|
const queryClient = makeTestQueryClient();
|
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
);
|
|
const { result } = renderHook(() => useXraySetting(), { wrapper });
|
|
|
|
await waitFor(() => expect(result.current.fetched).toBe(true));
|
|
await act(async () => {
|
|
await result.current.testOutbound(0, outbound, 'tcp');
|
|
});
|
|
|
|
expect(bodies).toHaveLength(1);
|
|
expect(bodies[0].mode).toBe(want);
|
|
});
|
|
});
|