feat(xray): add the XDRIVE transport

xray-core v26.10.10 tunnels a stream through files in shared cloud
storage ("network": "xdrive"): Google Drive, a local folder, or any HTTP
storage API described by a template. The panel could not select it, and
the stream schema rejected a pasted xdrive stream outright.

The inbound and outbound forms now offer XDRIVE with one shared editor:
service, folder, the three Google Drive secrets in the order the core
reads them, a template JSON editor with its {secretN} values, the
optional domain front (the stream-level address/port the storage client
dials), and the core's tuning knobs with their defaults as placeholders.
Switching an inbound to XDRIVE resets security to none, because the
core would otherwise read the inbound's TLS/REALITY as the storage API's
client TLS.

XDRIVE has no share-link format, and a link carrying the storage
secrets would print them into every QR code, so both link generators
emit none for it; the JSON subscription already passes the stream
through intact, and Clash drops the unknown transport.
This commit is contained in:
MHSanaei
2026-10-11 08:21:08 +02:00
parent 73a028f52d
commit ca5983595b
34 changed files with 848 additions and 19 deletions
@@ -35,6 +35,31 @@ exports[`NetworkSettingsSchema fixtures > parses ws-default byte-stably 1`] = `
}
`;
exports[`NetworkSettingsSchema fixtures > parses xdrive-google-drive byte-stably 1`] = `
{
"address": "142.250.0.1",
"network": "xdrive",
"port": 443,
"xdriveSettings": {
"concurrency": 8,
"eagerWindowMs": 2000,
"flushIntervalMs": 20,
"holeTimeoutMs": 30000,
"maxPollIntervalMs": 500,
"pollIntervalMs": 50,
"remoteFolder": "xray-tunnel",
"secrets": [
"000000000000-example.apps.googleusercontent.com",
"GOCSPX-example-client-secret",
"1//example-refresh-token",
],
"segmentBytes": 524288,
"service": "Google Drive",
"sessionTtlSeconds": 300,
},
}
`;
exports[`NetworkSettingsSchema fixtures > parses xhttp-basic byte-stably 1`] = `
{
"network": "xhttp",
@@ -0,0 +1,22 @@
{
"network": "xdrive",
"address": "142.250.0.1",
"port": 443,
"xdriveSettings": {
"service": "Google Drive",
"remoteFolder": "xray-tunnel",
"secrets": [
"000000000000-example.apps.googleusercontent.com",
"GOCSPX-example-client-secret",
"1//example-refresh-token"
],
"segmentBytes": 524288,
"flushIntervalMs": 20,
"pollIntervalMs": 50,
"maxPollIntervalMs": 500,
"sessionTtlSeconds": 300,
"concurrency": 8,
"eagerWindowMs": 2000,
"holeTimeoutMs": 30000
}
}
@@ -318,6 +318,50 @@ describe('InboundFormModal', () => {
});
});
// The core reads an XDRIVE inbound's TLS/REALITY as the storage API's client TLS, so
// switching a REALITY inbound to XDRIVE must store security none with its secrets.
it('switches a REALITY inbound to an XDRIVE stream with security none', async () => {
const post = vi.mocked(HttpUtil.post);
post.mockClear();
renderCloneLikeEdit(cloneLikeVlessInbound('example.com:443'));
fireEvent.click(screen.getByRole('tab', { name: 'Stream' }));
const transmission = Array.from(document.querySelectorAll('.ant-form-item')).find(
(el) =>
el.querySelector('.ant-form-item-label label')?.textContent?.trim() === 'Transmission',
);
const select = transmission?.querySelector('.ant-select') as HTMLElement;
fireEvent.mouseDown(select.querySelector('.ant-select-selector') ?? select);
const option = Array.from(document.querySelectorAll('.ant-select-item-option')).find(
(o) => (o.getAttribute('title') ?? o.textContent ?? '').trim() === 'XDRIVE',
) as HTMLElement;
fireEvent.click(option);
for (const [label, value] of [
['Remote folder', 'xray-tunnel'],
['Client ID', 'id.apps.googleusercontent.com'],
['Client secret', 'client-secret'],
['Refresh token', 'refresh-token'],
]) {
fireEvent.change(await screen.findByLabelText(label), { target: { value } });
}
fireEvent.click(primaryButton());
const isUpdate = ([url]: unknown[]) => url === '/panel/api/inbounds/update/42';
await waitFor(() => expect(post.mock.calls.some(isUpdate)).toBe(true));
const payload = post.mock.calls.find(isUpdate)![1] as { streamSettings: string };
const stream = JSON.parse(payload.streamSettings) as Record<string, unknown>;
expect(stream).toMatchObject({
network: 'xdrive',
security: 'none',
xdriveSettings: {
service: 'Google Drive',
remoteFolder: 'xray-tunnel',
secrets: ['id.apps.googleusercontent.com', 'client-secret', 'refresh-token'],
},
});
expect(stream.realitySettings).toBeUndefined();
});
// Clients and enable change through their own endpoints; the server keeps the
// stored ones, so the edit form must neither send nor validate its stale copy.
it('edit save neither sends nor validates the clients it loaded', async () => {
+22
View File
@@ -127,6 +127,28 @@ describe('genVlessLink', () => {
}
});
describe('XDRIVE share links', () => {
// No client reads an xdrive link, and one carrying the storage secrets would print
// them into every QR code; mirrors the Go generator, which emits none either.
it('emits no link for an XDRIVE stream', () => {
const [, raw] = fixturesForProtocol('vless').find(([name]) => name === 'vless-ws-tls')!;
const inbound = InboundSchema.parse({
...raw,
streamSettings: {
network: 'xdrive',
security: 'none',
xdriveSettings: { service: 'local', remoteFolder: '/srv/xdrive' },
},
});
const client = (raw as { settings: { clients: Array<{ id: string; email: string }> } }).settings
.clients[0];
const entries = genAllLinks({ inbound, client, fallbackHostname: 'panel.example.test' });
expect(entries.map((e) => e.link)).toEqual(['']);
});
});
describe('applyVlessRoute', () => {
const id = '11111111-2222-4333-8444-555555555555';
it('encodes a single value into the 3rd group and no-ops on invalid input', () => {
+88 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest';
import { act, fireEvent, render } from '@testing-library/react';
import { act, fireEvent, render, screen } from '@testing-library/react';
import { QueryClientProvider } from '@tanstack/react-query';
import { ThemeProvider } from '@/hooks/useTheme';
@@ -24,6 +24,23 @@ function renderModal(outbound: Record<string, unknown> | null = null) {
);
}
function formItemByLabel(label: string): Element | undefined {
return Array.from(document.querySelectorAll('.ant-form-item')).find(
(el) => (el.querySelector('.ant-form-item-label label')?.textContent ?? '').trim() === label,
);
}
function chooseOptionByLabel(label: string, optionText: string) {
const select = formItemByLabel(label)?.querySelector('.ant-select');
if (!select) throw new Error(`${label} select not found`);
fireEvent.mouseDown(select.querySelector('.ant-select-selector') ?? select);
const option = Array.from(document.querySelectorAll('.ant-select-item-option')).find(
(o) => (o.getAttribute('title') ?? o.textContent ?? '').trim() === optionText,
);
if (!option) throw new Error(`Option '${optionText}' not found for ${label}`);
fireEvent.click(option);
}
function toggleSwitch(label: string) {
const item = Array.from(document.querySelectorAll('.ant-form-item')).find(
(el) => (el.querySelector('.ant-form-item-label label')?.textContent ?? '').trim() === label,
@@ -290,4 +307,74 @@ describe('OutboundFormModal', () => {
useSystemCA: true,
});
});
// xray-core reads Google Drive's three secrets by position (ClientID, ClientSecret,
// RefreshToken); a misordered list fails OAuth only when the tunnel first dials.
it('saves an XDRIVE stream picked in the transmission selector', async () => {
const onConfirm = vi.fn();
const queryClient = makeTestQueryClient();
const outbound = {
protocol: 'vless',
tag: 'drive-out',
settings: {
vnext: [
{
address: 'example.com',
port: 443,
users: [{ id: 'c9f0c2d0-0000-4000-8000-000000000000', encryption: 'none' }],
},
],
},
streamSettings: { network: 'tcp', security: 'none' },
};
const tree = (open: boolean) => (
<QueryClientProvider client={queryClient}>
<ThemeProvider>
<OutboundFormModal
open={open}
outbound={outbound}
existingTags={[]}
onClose={() => {}}
onConfirm={onConfirm}
/>
</ThemeProvider>
</QueryClientProvider>
);
const { rerender } = render(tree(false));
rerender(tree(true));
await act(async () => {
await new Promise((r) => setTimeout(r, 0));
});
chooseOptionByLabel('Transmission', 'XDRIVE');
await act(async () => {
await new Promise((r) => setTimeout(r, 0));
});
for (const [label, value] of [
['Remote folder', 'xray-tunnel'],
['Client ID', 'id.apps.googleusercontent.com'],
['Client secret', 'client-secret'],
['Refresh token', 'refresh-token'],
]) {
fireEvent.change(screen.getByLabelText(label), { target: { value } });
}
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);
const payload = onConfirm.mock.calls[0][0] as { streamSettings: Record<string, unknown> };
expect(payload.streamSettings).toMatchObject({
network: 'xdrive',
xdriveSettings: {
service: 'Google Drive',
remoteFolder: 'xray-tunnel',
secrets: ['id.apps.googleusercontent.com', 'client-secret', 'refresh-token'],
},
});
});
});