Files
BetterDesk/web-nodejs/tests/serverConnectionConfig.docker.test.js
T
UNITRONIX 856002d389 fix(split-docker): unlock connection strategy settings
Allow the split console to read and write the P2P, relay, NAT, and initiator policy through the Go server's shared database API. Apply validated changes atomically at runtime, keep native systemd and compose paths unchanged, and cover the flow with regression tests and Docker image checks.

Refs #432

Thanks: INSOLVE (Honorary); Marco Jakobs (@jacotec); MyNameisStitch (@MyNameisStitch); Redspin (@playerumpknow)
2026-09-25 00:04:22 +02:00

96 lines
3.3 KiB
JavaScript

'use strict';
describe('serverConnectionConfigService Docker split mode', () => {
let service;
let apiClient;
beforeEach(() => {
jest.resetModules();
process.env.BETTERDESK_DOCKER_LAYOUT = 'split';
apiClient = {
get: jest.fn().mockResolvedValue({
data: {
mode: 'p2p_first',
p2p_fallback_ms: 2500,
same_nat_relay: true,
allow_shared_nat_initiator: false,
logged_in_only_initiator: true,
operator_only_outbound: false,
},
}),
put: jest.fn().mockResolvedValue({
data: {
config: {
mode: 'relay_only',
p2p_fallback_ms: 3500,
same_nat_relay: false,
allow_shared_nat_initiator: true,
logged_in_only_initiator: true,
operator_only_outbound: true,
},
},
}),
};
jest.doMock('../config/config', () => ({ isDocker: true }));
jest.doMock('../services/betterdeskApi', () => ({ apiClient }));
jest.doMock('../services/updateService', () => ({
COMPONENTS: { server: { service: 'betterdesk-server' } },
daemonReload: jest.fn(),
restartService: jest.fn(),
}));
jest.doMock('../lib/privilegedUpdateHelper', () => ({
canUsePrivilegedUpdate: jest.fn(() => false),
invokePrivilegedUpdate: jest.fn(),
}));
service = require('../services/serverConnectionConfigService');
});
afterEach(() => {
delete process.env.BETTERDESK_DOCKER_LAYOUT;
jest.resetModules();
});
test('reads and writes the Go server configuration as writable', async () => {
expect(service.isDockerSplitDeployment()).toBe(true);
const current = await service.getConnectionMode();
expect(current.source).toBe('go-api');
expect(current.writable).toBe(true);
expect(current.p2p_fallback_ms).toBe(2500);
const result = await service.setConnectionMode({
mode: 'relay_only',
p2p_fallback_ms: 3500,
same_nat_relay: false,
allow_shared_nat_initiator: true,
logged_in_only_initiator: true,
operator_only_outbound: true,
});
expect(apiClient.put).toHaveBeenCalledWith('/connection/config', {
mode: 'relay_only',
p2p_fallback_ms: 3500,
same_nat_relay: false,
allow_shared_nat_initiator: true,
logged_in_only_initiator: true,
operator_only_outbound: true,
});
expect(result.source).toBe('go-api');
expect(result.restart).toBeNull();
expect(result.restartRequired).toBeNull();
expect(result.settings.operator_only_outbound).toBe(true);
});
test('fails closed when the Go API is unavailable', async () => {
apiClient.get.mockRejectedValueOnce(new Error('server unavailable'));
const current = await service.getConnectionMode();
expect(current.source).toBe('go-api');
expect(current.writable).toBe(false);
});
});