feat: store rdp, vnc and telnet logins in a generic per-protocol table

This commit is contained in:
LukeGus committed 2026-09-29 12:33:09 -05:00
1 parent e0c30a4e6f
commit bba06f7ff6
107 files changed
+18750 -1224

No files matched your search

@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import { quickConnectGuacHost } from "../../src/frontend/quick-connect-guac-host";
// The shape core's Quick Connect builds for a plugin protocol: the switch and
// port in this plugin's host settings, the login on the protocol's fields.
// port in this plugin's host settings, the unsaved login in quickConnectLogin.
function quickHost(protocol: "rdp" | "vnc", extra: Record<string, unknown>) {
return {
id: "quick-connect-1",
@@ -24,9 +24,12 @@ describe("quickConnectGuacHost", () => {
expect(
quickConnectGuacHost(
quickHost("rdp", {
rdpUser: "admin",
rdpPassword: "pw",
domain: "CORP",
quickConnectLogin: {
protocol: "rdp",
username: "admin",
password: "pw",
fields: { domain: "CORP" },
},
}),
),
).toMatchObject({
@@ -41,7 +44,11 @@ describe("quickConnectGuacHost", () => {
it("takes a VNC quick connect's login from the VNC fields", () => {
expect(
quickConnectGuacHost(quickHost("vnc", { vncPassword: "vncpw" })),
quickConnectGuacHost(
quickHost("vnc", {
quickConnectLogin: { protocol: "vnc", password: "vncpw" },
}),
),
).toMatchObject({
connectionType: "vnc",
port: 5901,
@@ -0,0 +1,91 @@
import { describe, expect, it } from "vitest";
import type { HostEditorSectionProps } from "@termix/plugin-sdk/frontend";
import {
loginOf,
patchLogin,
remoteDesktopForm,
} from "../../src/frontend/remote-form";
function sectionProps(form: Record<string, unknown>) {
const state = { form: { ...form } };
const props = {
form: state.form,
setField: (key: string, value: unknown) => {
state.form = { ...state.form, [key]: value };
},
updateForm: (
patch: (current: Record<string, unknown>) => Record<string, unknown>,
) => {
state.form = { ...state.form, ...patch(state.form) };
},
} as unknown as HostEditorSectionProps;
return { props, state };
}
describe("remote desktop editor form", () => {
it("reads each protocol's login from the host form's protocolAuth", () => {
const { props } = sectionProps({
protocolAuth: {
rdp: {
authType: "credential",
credentialId: "4",
username: "",
password: "",
fields: { domain: "CORP" },
},
vnc: {
authType: "direct",
credentialId: "",
username: "",
password: "saved",
fields: {},
},
},
});
const { form } = remoteDesktopForm(props);
expect(form).toMatchObject({
rdpAuthType: "credential",
rdpCredentialId: "4",
domain: "CORP",
vncPassword: "saved",
telnetAuthType: "direct",
telnetUser: "",
});
});
it("writes the tabs' login fields into protocolAuth", () => {
const { props, state } = sectionProps({});
const { setField } = remoteDesktopForm(props);
setField("rdpUser", "admin");
setField("domain", "CORP");
setField("telnetAuthType", "credential");
expect(state.form.protocolAuth).toEqual({
rdp: {
authType: "direct",
credentialId: "",
username: "admin",
password: "",
fields: { domain: "CORP" },
},
telnet: {
authType: "credential",
credentialId: "",
username: "",
password: "",
fields: {},
},
});
});
it("keeps other protocols when one changes", () => {
const current = {
protocolAuth: { vnc: { ...loginOf(undefined, "vnc"), username: "v" } },
};
const next = patchLogin(current, "rdp", "password", "pw");
expect(next.protocolAuth).toMatchObject({
vnc: { username: "v" },
rdp: { password: "pw" },
});
});
});