Files
BetterDesk/web-nodejs/tests/clientConfigHost.test.js
T
Knienartowicz 95f8ea6964 fix(signal): advertise rendezvous servers, never relay, in ConfigUpdate
handleTestNat() built ConfigUpdate.rendezvous_servers from
GetRelayServers(), so every TestNatResponse told the client that its *ID
server* was the relay endpoint. On this instance RENDEZVOUS_SERVERS is unset,
so the list contained exactly `85.14.70.12:21117` and was sent 113 times
today.

Newer RustDesk clients honour ConfigUpdate. Reconfiguring the signal socket to
the relay port makes the host stop answering RequestRelay altogether: the panel
connected as initiator, hbbr logged `Connection ... for UUID` and then
`Pair timeout` 30 s later, and the browser saw "Relay connection closed
(WebSocket 1005)". Peer 275129227 (RustDesk 1.4.9) showed exactly that
signature: TestNatRequest, heartbeats, and no relay connection ever.

- config: add GetRendezvousServers() which parses RENDEZVOUS_SERVERS and
  appends SignalPort, with the same validation as GetRelayServers().
- signal: handleTestNat() now advertises only configured rendezvous servers and
  omits ConfigUpdate entirely when none are configured.
- web: relay endpoints are always emitted as host:port (resolveRustDeskEndpoints,
  keyService, customTxtBuilder, agentBundleService, generator config). A bare
  relay host made clients fall back to the API port, which hbbr cannot pair.

Refs #329

Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow); muopc (@muopc)
2026-11-17 09:54:48 +01:00

81 lines
3.6 KiB
JavaScript

'use strict';
const clientConfigHost = require('../services/clientConfigHost');
describe('clientConfigHost', () => {
const originalPanelHost = process.env.PANEL_PUBLIC_HOST;
const originalPublicServerId = process.env.PUBLIC_SERVER_ID;
const originalPublicRelay = process.env.PUBLIC_RELAY_SERVER;
const originalPublicApi = process.env.PUBLIC_API_URL;
afterEach(() => {
if (originalPanelHost === undefined) delete process.env.PANEL_PUBLIC_HOST;
else process.env.PANEL_PUBLIC_HOST = originalPanelHost;
if (originalPublicServerId === undefined) delete process.env.PUBLIC_SERVER_ID;
else process.env.PUBLIC_SERVER_ID = originalPublicServerId;
if (originalPublicRelay === undefined) delete process.env.PUBLIC_RELAY_SERVER;
else process.env.PUBLIC_RELAY_SERVER = originalPublicRelay;
if (originalPublicApi === undefined) delete process.env.PUBLIC_API_URL;
else process.env.PUBLIC_API_URL = originalPublicApi;
});
it('resolveClientFacingHost prefers query host override when PUBLIC_SERVER_ID unset', () => {
process.env.PANEL_PUBLIC_HOST = 'panel.internal';
const host = clientConfigHost.resolveClientFacingHost(
{ headers: { host: 'localhost:5000' } },
'203.0.113.10'
);
expect(host).toBe('203.0.113.10');
});
it('resolveClientFacingHost uses PANEL_PUBLIC_HOST before request host', () => {
process.env.PANEL_PUBLIC_HOST = 'desk.example.com';
const host = clientConfigHost.resolveClientFacingHost(
{ headers: { host: 'localhost:5000' } },
''
);
expect(host).toBe('desk.example.com');
});
it('resolveRustDeskEndpoints uses split PUBLIC_* env values', () => {
process.env.PUBLIC_SERVER_ID = 'remote.example.com';
process.env.PUBLIC_RELAY_SERVER = 'relay.example.com';
process.env.PUBLIC_API_URL = 'https://api.example.com';
const endpoints = clientConfigHost.resolveRustDeskEndpoints(
{ headers: { host: 'console.example.com' } },
''
);
expect(endpoints.host).toBe('remote.example.com');
// Relay gets an explicit port so RustDesk 1.4.8/1.4.9 does not fall back
// to the API port and request relay there (pairing would never complete).
expect(endpoints.relay).toBe('relay.example.com:21117');
expect(endpoints.api).toBe('https://api.example.com');
expect(endpoints.env_override_active).toBe(true);
expect(endpoints.sources.host).toBe('env');
});
it('resolveRustDeskEndpoints ignores query host when PUBLIC_SERVER_ID is set', () => {
process.env.PUBLIC_SERVER_ID = 'remote.example.com';
const endpoints = clientConfigHost.resolveRustDeskEndpoints(
{ headers: { host: 'console.example.com' } },
'203.0.113.10'
);
expect(endpoints.host).toBe('remote.example.com');
});
it('stripRequestHost removes port from IPv4 host header', () => {
expect(clientConfigHost.stripRequestHost('192.168.1.5:5000')).toBe('192.168.1.5');
});
it('isPhoneUnreachableHost flags loopback and .local (#368)', () => {
expect(clientConfigHost.isPhoneUnreachableHost('localhost')).toBe(true);
expect(clientConfigHost.isPhoneUnreachableHost('127.0.0.1')).toBe(true);
expect(clientConfigHost.isPhoneUnreachableHost('::1')).toBe(true);
expect(clientConfigHost.isPhoneUnreachableHost('desk.local')).toBe(true);
expect(clientConfigHost.isPhoneUnreachableHost('203.0.113.10')).toBe(false);
expect(clientConfigHost.isPhoneUnreachableHost('desk.example.com')).toBe(false);
});
});