mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 06:35:24 +00:00
feat: store rdp, vnc and telnet logins in a generic per-protocol table
This commit is contained in:
1 parent
e0c30a4e6f
commit
bba06f7ff6
107 files changed
+18750
-1224
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
hostPayloadLegacy,
|
||||
normalizeImportedHost,
|
||||
userDefaultParams,
|
||||
} from "../../src/backend/host-settings.js";
|
||||
@@ -80,3 +81,38 @@ describe("userDefaultParams", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -37,7 +37,7 @@ function target(
|
||||
authType: "direct",
|
||||
username: "admin",
|
||||
password: "secret",
|
||||
domain: "CORP",
|
||||
fields: { domain: "CORP" },
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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" },
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user