mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-08-29 18:31:33 +00:00
Fix Proxmox credential guest imports (#1300)
This commit is contained in:
@@ -105,6 +105,16 @@ export function parseSSHConfig(content: string): SSHConfigHost[] {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function importedHostUsername(
|
||||||
|
connectionType: string,
|
||||||
|
authType: unknown,
|
||||||
|
username: unknown,
|
||||||
|
): string | null {
|
||||||
|
if (isNonEmptyString(username)) return username;
|
||||||
|
if (connectionType !== "ssh" || authType === "credential") return "";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function registerHostBulkRoutes(
|
export function registerHostBulkRoutes(
|
||||||
router: Router,
|
router: Router,
|
||||||
authenticateJWT: RequestHandler,
|
authenticateJWT: RequestHandler,
|
||||||
@@ -558,10 +568,12 @@ export function registerHostBulkRoutes(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
const username = importedHostUsername(
|
||||||
effectiveConnectionType === "ssh" &&
|
effectiveConnectionType,
|
||||||
!isNonEmptyString(hostData.username)
|
hostData.authType,
|
||||||
) {
|
hostData.username,
|
||||||
|
);
|
||||||
|
if (username === null) {
|
||||||
results.failed++;
|
results.failed++;
|
||||||
results.errors.push(
|
results.errors.push(
|
||||||
`Host ${i + 1}: Username required for SSH connections`,
|
`Host ${i + 1}: Username required for SSH connections`,
|
||||||
@@ -660,12 +672,12 @@ export function registerHostBulkRoutes(
|
|||||||
const sshDataObj: Record<string, unknown> = {
|
const sshDataObj: Record<string, unknown> = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
connectionType: effectiveConnectionType,
|
connectionType: effectiveConnectionType,
|
||||||
name: hostData.name || `${hostData.username || ""}@${hostData.ip}`,
|
name: hostData.name || `${username}@${hostData.ip}`,
|
||||||
folder: hostData.folder || "Default",
|
folder: hostData.folder || "Default",
|
||||||
tags: Array.isArray(hostData.tags) ? hostData.tags.join(",") : "",
|
tags: Array.isArray(hostData.tags) ? hostData.tags.join(",") : "",
|
||||||
ip: hostData.ip,
|
ip: hostData.ip,
|
||||||
port: hostData.port,
|
port: hostData.port,
|
||||||
username: hostData.username || null,
|
username,
|
||||||
pin: hostData.pin || false,
|
pin: hostData.pin || false,
|
||||||
enableTerminal: hostData.enableTerminal !== false,
|
enableTerminal: hostData.enableTerminal !== false,
|
||||||
enableTunnel: hostData.enableTunnel !== false,
|
enableTunnel: hostData.enableTunnel !== false,
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { parseSSHConfig } from "../../../database/routes/host-bulk-routes.js";
|
import {
|
||||||
|
importedHostUsername,
|
||||||
|
parseSSHConfig,
|
||||||
|
} from "../../../database/routes/host-bulk-routes.js";
|
||||||
|
|
||||||
describe("parseSSHConfig", () => {
|
describe("parseSSHConfig", () => {
|
||||||
it("parses a basic Host block", () => {
|
it("parses a basic Host block", () => {
|
||||||
@@ -102,3 +105,24 @@ Host server
|
|||||||
expect(parseSSHConfig(" \n\n ")).toHaveLength(0);
|
expect(parseSSHConfig(" \n\n ")).toHaveLength(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("importedHostUsername", () => {
|
||||||
|
it("lets credential-backed SSH hosts inherit the credential username", () => {
|
||||||
|
expect(importedHostUsername("ssh", "credential", "")).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps requiring usernames for other SSH authentication modes", () => {
|
||||||
|
expect(importedHostUsername("ssh", "password", "")).toBeNull();
|
||||||
|
expect(importedHostUsername("ssh", "key", undefined)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("always returns a non-null database value for non-SSH hosts", () => {
|
||||||
|
expect(importedHostUsername("rdp", "password", undefined)).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves an explicitly configured host username", () => {
|
||||||
|
expect(importedHostUsername("ssh", "credential", "guest-admin")).toBe(
|
||||||
|
"guest-admin",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user