Files
Termix/plugins/remote-desktop/tests/backend/host-settings.test.ts
T

119 lines
2.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
hostPayloadLegacy,
normalizeImportedHost,
userDefaultParams,
} from "../../src/backend/host-settings.js";
describe("normalizeImportedHost", () => {
it("reads a Termix export's pluginSettings", () => {
expect(
normalizeImportedHost({
pluginSettings: {
"remote-desktop": {
enableVnc: true,
vncPort: 5901,
guacamoleConfig: { cursor: "local" },
},
},
}),
).toEqual({
enableVnc: true,
vncPort: 5901,
guacamoleConfig: { cursor: "local" },
});
});
it("reads the flat fields hosts had before 2.9.0", () => {
expect(
normalizeImportedHost({
enableRdp: true,
rdpPort: "3390",
security: "nla",
ignoreCert: 1,
guacamoleConfig: JSON.stringify({ dpi: 120 }),
enableTerminalToolbar: false,
}),
).toEqual({
enableRdp: true,
rdpPort: 3390,
rdpSecurity: "nla",
rdpIgnoreCert: true,
guacamoleConfig: { dpi: 120 },
enableToolbar: false,
});
});
it("turns a connectionType-only host into its switch and port", () => {
expect(
normalizeImportedHost({ connectionType: "telnet", port: 2323 }),
).toEqual({ enableTelnet: true, telnetPort: 2323 });
});
it("writes nothing for a plain SSH row", () => {
expect(
normalizeImportedHost({ connectionType: "ssh", port: 22 }),
).toBeNull();
});
it("drops a port out of range", () => {
expect(normalizeImportedHost({ enableRdp: true, rdpPort: 70000 })).toEqual({
enableRdp: true,
});
});
});
describe("userDefaultParams", () => {
it("maps the user settings onto guacd parameters, skipping inherit", () => {
expect(
userDefaultParams({
colorDepth: "24",
resizeMethod: "reconnect",
disableCopy: "on",
enableWallpaper: "off",
enableDrive: "inherit",
}),
).toEqual({
"color-depth": 24,
"resize-method": "reconnect",
"disable-copy": true,
"enable-wallpaper": false,
});
});
});
describe("hostPayloadLegacy", () => {
it("puts each login back in its 2.8 flat shape for older clients", () => {
expect(
hostPayloadLegacy(
{},
{
protocolAuth: {
rdp: {
authType: "direct",
credentialId: null,
username: "admin",
fields: { domain: "CORP" },
hasPassword: true,
},
vnc: { authType: "credential", credentialId: 4 },
},
},
),
).toEqual({
rdpAuthType: "direct",
rdpCredentialId: null,
rdpUser: "admin",
hasRdpPassword: true,
rdpDomain: "CORP",
domain: "CORP",
vncAuthType: "credential",
vncCredentialId: 4,
});
});
it("adds nothing for a host without logins", () => {
expect(hostPayloadLegacy({}, {})).toBeNull();
});
});