mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-08-29 10:21:34 +00:00
fix: preserve omitted host protocol settings (#1350)
This commit is contained in:
@@ -14,6 +14,25 @@ export function isOptionalBoolean(
|
||||
return value === undefined || typeof value === "boolean";
|
||||
}
|
||||
|
||||
const PROTOCOL_ENABLE_FIELDS = [
|
||||
"enableSsh",
|
||||
"enableRdp",
|
||||
"enableVnc",
|
||||
"enableTelnet",
|
||||
] as const;
|
||||
|
||||
export function normalizeProtocolEnableFields(
|
||||
values: Record<string, unknown>,
|
||||
): Partial<Record<(typeof PROTOCOL_ENABLE_FIELDS)[number], 0 | 1>> {
|
||||
return Object.fromEntries(
|
||||
PROTOCOL_ENABLE_FIELDS.flatMap((field) =>
|
||||
typeof values[field] === "boolean"
|
||||
? [[field, values[field] ? 1 : 0]]
|
||||
: [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export const OWNER_PRIVATE_AUTH_FIELDS = {
|
||||
ssh: [
|
||||
"authType",
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
isNonEmptyString,
|
||||
isOptionalBoolean,
|
||||
isValidPort,
|
||||
normalizeProtocolEnableFields,
|
||||
OWNER_PRIVATE_AUTH_FIELDS,
|
||||
OWNER_PRIVATE_TERMINAL_CONFIG_FIELDS,
|
||||
sanitizeHostForRecipient,
|
||||
@@ -267,7 +268,8 @@ router.post(
|
||||
!isNonEmptyString(userId) ||
|
||||
!isNonEmptyString(ip) ||
|
||||
!isValidPort(port) ||
|
||||
!isOptionalBoolean(shareSshAuth)
|
||||
!isOptionalBoolean(shareSshAuth) ||
|
||||
![enableSsh, enableRdp, enableVnc, enableTelnet].every(isOptionalBoolean)
|
||||
) {
|
||||
sshLogger.warn("Invalid SSH data input validation failed", {
|
||||
operation: "host_create",
|
||||
@@ -398,10 +400,7 @@ router.post(
|
||||
portKnockSequence: portKnockSequence
|
||||
? JSON.stringify(portKnockSequence)
|
||||
: null,
|
||||
enableSsh: enableSsh ? 1 : 0,
|
||||
enableRdp: enableRdp ? 1 : 0,
|
||||
enableVnc: enableVnc ? 1 : 0,
|
||||
enableTelnet: enableTelnet ? 1 : 0,
|
||||
...normalizeProtocolEnableFields(hostData),
|
||||
sshPort: sshPort || port || 22,
|
||||
rdpPort: rdpPort || 3389,
|
||||
vncPort: vncPort || 5900,
|
||||
@@ -971,6 +970,9 @@ router.put(
|
||||
!isNonEmptyString(ip) ||
|
||||
!isValidPort(port) ||
|
||||
!isOptionalBoolean(shareSshAuth) ||
|
||||
![enableSsh, enableRdp, enableVnc, enableTelnet].every(
|
||||
isOptionalBoolean,
|
||||
) ||
|
||||
!hostId
|
||||
) {
|
||||
sshLogger.warn("Invalid SSH data input validation failed for update", {
|
||||
@@ -1102,10 +1104,7 @@ router.put(
|
||||
portKnockSequence: portKnockSequence
|
||||
? JSON.stringify(portKnockSequence)
|
||||
: null,
|
||||
enableSsh: enableSsh ? 1 : 0,
|
||||
enableRdp: enableRdp ? 1 : 0,
|
||||
enableVnc: enableVnc ? 1 : 0,
|
||||
enableTelnet: enableTelnet ? 1 : 0,
|
||||
...normalizeProtocolEnableFields(hostData),
|
||||
sshPort: sshPort || port || 22,
|
||||
rdpPort: rdpPort || 3389,
|
||||
vncPort: vncPort || 5900,
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
isOptionalBoolean,
|
||||
isValidPort,
|
||||
normalizeImportedHost,
|
||||
normalizeProtocolEnableFields,
|
||||
renameFolderPath,
|
||||
sanitizeHostForRecipient,
|
||||
stripSensitiveFields,
|
||||
@@ -80,6 +81,23 @@ describe("isOptionalBoolean", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeProtocolEnableFields", () => {
|
||||
it("omits unspecified protocol fields so database defaults are preserved", () => {
|
||||
expect(normalizeProtocolEnableFields({ name: "server" })).toEqual({});
|
||||
});
|
||||
|
||||
it("converts explicitly provided protocol booleans to database integers", () => {
|
||||
expect(
|
||||
normalizeProtocolEnableFields({
|
||||
enableSsh: true,
|
||||
enableRdp: false,
|
||||
enableVnc: undefined,
|
||||
enableTelnet: true,
|
||||
}),
|
||||
).toEqual({ enableSsh: 1, enableRdp: 0, enableTelnet: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("renameFolderPath", () => {
|
||||
it("renames an exact folder match", () => {
|
||||
expect(renameFolderPath("Production", "Production", "Prod")).toBe("Prod");
|
||||
|
||||
Reference in New Issue
Block a user