补齐SSH引导私钥名称联动

补充内嵌SSH引导默认私钥名称的联动逻辑,并保留用户手工指定名称不被覆盖的行为。测试顺序将在后续检查点中对齐真实页面流程。
This commit is contained in:
xuans 2026-09-26 13:42:23 +08:00
parent 661e074926
commit 121be43b1b
2 changed files with 14 additions and 0 deletions

View File

@ -316,6 +316,13 @@ export function useDashboard() {
() => String(serverForm.value.address || "").trim() || "服务器地址",
);
watch(sshKeyFileName, (fileName, previousFileName) => {
if (!showEmbeddedSSHKeyGuide.value) return;
const currentName = String(sshKeyForm.value.name || "").trim();
if (!currentName || currentName === previousFileName) {
sshKeyForm.value.name = fileName;
}
});
async function fetchAdmin(path, options = {}) {
const response = await fetch(path, {
...options,

View File

@ -154,14 +154,21 @@ test("编辑服务器正确保留已有密码状态,新建和未配置密码
test("SSH引导目标直接跟随服务器配置中的地址和用户", async (t) => {
const { state } = await setup(t, () => verifiedResponse());
state.openServerCreate();
state.openSSHKeyCreate({ embedded: true });
state.serverForm.value.username = "root";
state.serverForm.value.address = "45.136.13.241";
await nextTick();
assert.equal(state.sshKeyCommandUsername.value, "root");
assert.equal(state.sshKeyCommandHost.value, "45.136.13.241");
assert.equal(state.sshKeyForm.value.name, state.sshKeyFileName.value);
assert.match(state.sshPublicKeyCommands.value.windows, /ssh root@45\.136\.13\.241/);
assert.match(state.sshPublicKeyCommands.value.linux, /root@45\.136\.13\.241/);
state.sshKeyForm.value.name = "manual-key-name";
state.serverForm.value.username = "deploy";
await nextTick();
assert.equal(state.sshKeyForm.value.name, "manual-key-name");
});
async function fill(state) {