Files
BetterDesk/web-nodejs/tests/keyService.test.js
T
UNITRONIX 8579e88be4 Fix split-domain RustDesk client config for dashboard and QR (Fixes #222).
Add PUBLIC_SERVER_ID, PUBLIC_RELAY_SERVER, and PUBLIC_API_URL with Settings UI,
unified endpoint resolution across Dashboard/Keys, and fallbacks via PANEL_PUBLIC_HOST.
2026-06-27 20:45:00 +02:00

46 lines
1.8 KiB
JavaScript

'use strict';
const keyService = require('../services/keyService');
describe('keyService RustDesk config encoding', () => {
const samplePayload = {
host: '203.0.113.10',
relay: '203.0.113.10',
api: 'http://203.0.113.10:21114',
key: 'AbCdEfGhIjKlMnOpQrStUvWxYz0123456789+/=',
};
it('encodeRustDeskConfigUri uses standard base64 JSON', () => {
const uri = keyService.encodeRustDeskConfigUri(samplePayload);
expect(uri.startsWith('rustdesk://config/')).toBe(true);
const b64 = uri.slice('rustdesk://config/'.length);
const decoded = JSON.parse(Buffer.from(b64, 'base64').toString('utf8'));
expect(decoded).toEqual(samplePayload);
});
it('encodeRustDeskCliConfigString reverses base64 without padding', () => {
const json = JSON.stringify(samplePayload);
let b64 = Buffer.from(json).toString('base64').replace(/=+$/, '');
const expected = b64.split('').reverse().join('');
expect(keyService.encodeRustDeskCliConfigString(samplePayload)).toBe(expected);
});
it('buildRustDeskConfigPayload normalizes host input', () => {
const payload = keyService.buildRustDeskConfigPayload('https://desk.example.com:8443/path');
expect(payload.host).toBe('desk.example.com');
expect(payload.relay).toBe('desk.example.com');
});
it('buildRustDeskConfigPayload accepts split endpoints object', () => {
const payload = keyService.buildRustDeskConfigPayload({
host: 'remote.example.com',
relay: 'relay.example.com',
api: 'https://api.example.com',
});
expect(payload.host).toBe('remote.example.com');
expect(payload.relay).toBe('relay.example.com');
expect(payload.api).toBe('https://api.example.com');
});
});