fix(hosts): advertise Hosts in every WireGuard, AmneziaWG and TUIC config

Invariant: an inbound's enabled Hosts are the endpoints every client config
for it advertises, whichever surface renders that config.

WireGuard and AmneziaWG broke it. Their raw generators ignored the
externalProxy entries Hosts are injected as and always emitted
resolveInboundAddress, so the raw subscription, the sub page .conf, the
clients links API and "export all links" gave out the panel address while
the JSON and Clash formats of the same inbound used the Host.
advertisedEndpoints now states the fan-out once for mtproto, wireguard and
amneziawg.

The browser-built configs had the same gap. The Clients page WireGuard and
AmneziaWG config blocks and QR panels, and its TUIC Clash config, used the
panel hostname next to server links that already used Hosts; the Inbounds
page peer configs, QR and export ignored them too. withMtprotoHostEndpoints
becomes withHostEndpoints over a shared hostEndpointsFor mirror of the
backend, the tunnel fan-outs render one config per Host, and the clients
page waits for the hosts list the way the inbounds page does, so an empty
list means "no hosts" rather than "not loaded yet".
This commit is contained in:
MHSanaei
2026-09-30 15:03:16 +02:00
parent 8c023d13dc
commit aee45ca3fe
20 changed files with 876 additions and 362 deletions
@@ -4,6 +4,7 @@ import { MemoryRouter } from 'react-router';
import ClientInfoModal from '@/pages/clients/ClientInfoModal';
import ClientQrModal from '@/pages/clients/ClientQrModal';
import type { ClientRecord, InboundOption } from '@/hooks/useClients';
import type { HostRecord } from '@/schemas/api/host';
import { renderWithProviders } from './test-utils';
const deAwgInbound: InboundOption = {
@@ -182,4 +183,85 @@ describe('Multi-tunnel Client Modals', () => {
expect(screen.getByText('DE · Kelsterbach')).toBeTruthy();
expect(screen.getByText('FI · Helsinki')).toBeTruthy();
});
// The subscription beside these configs advertises the inbound's Hosts, so
// the panel-built configs must too — one per Host address.
const edgeHosts: HostRecord[] = [
{
groupId: 'cdn',
inboundIds: [201],
hosts: ['edge.example.com:443', 'edge2.example.com'],
remark: 'CDN',
},
];
const edgeClient = { ...multiWgClient, inboundIds: [201] } as ClientRecord;
const edgeLabels = [
'US · New York - edge.example.com:443',
'US · New York - edge2.example.com:51820',
];
it('renders one ConfigBlock per Host in ClientInfoModal', () => {
renderWithProviders(
<ClientInfoModal
open
client={edgeClient}
inboundsById={{ 201: usWgInbound }}
isOnline={false}
hosts={edgeHosts}
onOpenChange={() => {}}
/>,
);
for (const label of edgeLabels) expect(screen.getByText(label)).toBeTruthy();
});
it('renders one collapse panel per Host in ClientQrModal', () => {
renderWithProviders(
<MemoryRouter initialEntries={['/clients']}>
<ClientQrModal
open
client={edgeClient}
inboundsById={{ 201: usWgInbound }}
hosts={edgeHosts}
onOpenChange={() => {}}
/>
</MemoryRouter>,
);
for (const label of edgeLabels) expect(screen.getByText(label)).toBeTruthy();
});
it('builds the TUIC Clash config only from Hosts the Clash subscription serves', () => {
const tuicInbound = { id: 301, remark: 'tuic', protocol: 'tuic', port: 8443 } as InboundOption;
const tuicClient = {
id: 'c4',
email: 'TUIC-CLIENT',
uuid: 'e79b9107-1607-4e6c-a496-d8f99e4f0dc5',
password: 'secret',
inboundIds: [301],
} as unknown as ClientRecord;
const hosts: HostRecord[] = [
{ groupId: 'clash', inboundIds: [301], hosts: ['clash.example.com:443'] },
{
groupId: 'raw-only',
inboundIds: [301],
hosts: ['raw.example.com:443'],
excludeFromSubTypes: ['clash'],
},
];
renderWithProviders(
<MemoryRouter initialEntries={['/clients']}>
<ClientQrModal
open
client={tuicClient}
inboundsById={{ 301: tuicInbound }}
hosts={hosts}
onOpenChange={() => {}}
/>
</MemoryRouter>,
);
expect(screen.getAllByText('TUIC config (Clash)')).toHaveLength(1);
expect(screen.queryByText('raw.example.com:443')).toBeNull();
});
});