Fix Proxmox credential guest imports (#1300)

This commit is contained in:
ZacharyZcR
2026-08-23 22:45:24 +08:00
committed by GitHub
parent b5d13c3664
commit a4b61cc27f
2 changed files with 43 additions and 7 deletions
@@ -1,5 +1,8 @@
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", () => {
it("parses a basic Host block", () => {
@@ -102,3 +105,24 @@ Host server
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",
);
});
});