From 79d825937172d04bd758cfc7bd83cc8da3940e6e Mon Sep 17 00:00:00 2001 From: xuans Date: Fri, 2 Oct 2026 02:19:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=89=8D=E7=AB=AF=E7=A7=81?= =?UTF-8?q?=E9=92=A5=E5=AE=89=E5=85=A8=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除管理页面私钥板块、命令生成与私钥接口请求,服务器配置统一使用密码认证,并补充安全边界测试。 --- frontend/src/views/Dashboard/Dashboard.js | 246 +----------------- .../src/views/Dashboard/Dashboard.test.js | 121 ++------- frontend/src/views/Dashboard/Dashboard.vue | 105 -------- .../src/views/Dashboard/DeploymentFeedback.js | 8 +- .../views/Dashboard/DeploymentResult.test.js | 12 +- 5 files changed, 34 insertions(+), 458 deletions(-) diff --git a/frontend/src/views/Dashboard/Dashboard.js b/frontend/src/views/Dashboard/Dashboard.js index b54094f..c27a09b 100644 --- a/frontend/src/views/Dashboard/Dashboard.js +++ b/frontend/src/views/Dashboard/Dashboard.js @@ -19,7 +19,6 @@ export function useDashboard() { const canRunRenewal = computed(() => currentUser.value?.role === "super_admin"); const domains = ref([]); const servers = ref([]); - const sshKeys = ref([]); const certificates = ref([]); const tasks = ref([]); const auditLogs = ref([]); @@ -47,13 +46,6 @@ export function useDashboard() { const serverEditingId = ref(""); const serverSaving = ref(false); const serverFormError = ref(""); - const showSSHKeyForm = ref(false); - const showEmbeddedSSHKeyGuide = ref(false); - const sshKeySaving = ref(false); - const sshKeyFormError = ref(""); - const sshKeyPlatform = ref("windows"); - const sshKeyPassphraseVisible = ref(false); - const sshKeyRandomSuffix = ref(createSSHKeyRandomSuffix()); const showSettings = ref(false); const settingsSaving = ref(false); const settingsError = ref(""); @@ -87,7 +79,6 @@ export function useDashboard() { () => showForm.value || showServerForm.value || - showSSHKeyForm.value || showSettings.value || showCertificateImport.value || deploymentResult.value !== null || @@ -128,30 +119,6 @@ export function useDashboard() { document.body.style.overflow = previousBodyOverflow; }); - const sshKeyFileName = computed( - () => - `${sanitizeSSHKeySegment(sshKeyCommandUsername.value, "用户名")}+scert-${sshKeyRandomSuffix.value}`, - ); - const sshKeyPath = computed(() => `/ssl/ssh/${sshKeyFileName.value}`); - const sshKeyPrivatePath = computed(() => `${sshKeyPath.value}.key`); - const sshKeyPublicPath = computed(() => sshKeyPath.value); - const sshKeyRemoteTarget = computed( - () => - `${sanitizeSSHKeySegment(sshKeyCommandUsername.value, "用户名")}@${sanitizeSSHHost(sshKeyCommandHost.value)}`, - ); - const sshKeyCommands = computed(() => ({ - windows: - `New-Item -ItemType Directory -Force -Path "/ssl/ssh" | Out-Null; ssh-keygen -t ed25519 -C "scert-deploy" -f "${sshKeyPrivatePath.value}"; Move-Item -Force "${sshKeyPrivatePath.value}.pub" "${sshKeyPublicPath.value}"`, - linux: - `sudo install -d -m 700 -o "$(id -un)" -g "$(id -gn)" /ssl/ssh && ssh-keygen -t ed25519 -C "scert-deploy" -f "${sshKeyPrivatePath.value}" && mv -f "${sshKeyPrivatePath.value}.pub" "${sshKeyPublicPath.value}" && chmod 644 "${sshKeyPublicPath.value}"`, - })); - const sshPublicKeyCommands = computed(() => ({ - windows: - `Get-Content "${sshKeyPublicPath.value}" | ssh ${sshKeyRemoteTarget.value} "umask 077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"`, - linux: - `ssh-copy-id -i "${sshKeyPublicPath.value}" ${sshKeyRemoteTarget.value}`, - })); - const certificateTypeLabels = { single: "单域名", wildcard: "泛域名", @@ -318,22 +285,6 @@ export function useDashboard() { const defaultPrivateKeyPath = "/ssl/{域名}/{证书类型}/key.pem"; const serverForm = ref(createEmptyServerForm()); - const sshKeyForm = ref(createEmptySSHKeyForm()); - - const sshKeyCommandUsername = computed( - () => String(serverForm.value.username || "").trim() || "用户名", - ); - const sshKeyCommandHost = computed( - () => 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, @@ -381,7 +332,6 @@ export function useDashboard() { port: 22, username: "", auth_method: "password", - private_key_ref: "", password: "", passwordConfigured: false, host_key_fingerprint: "", @@ -395,11 +345,7 @@ export function useDashboard() { }; } - function createEmptySSHKeyForm() { - return { name: "", private_key: "", passphrase: "" }; - } - - function createSSHKeyRandomSuffix() { + function createRandomSuffix() { const bytes = new Uint8Array(6); crypto.getRandomValues(bytes); return Array.from(bytes, (value) => value.toString(16).padStart(2, "0")).join( @@ -407,21 +353,6 @@ export function useDashboard() { ); } - function sanitizeSSHKeySegment(value, fallback) { - const normalized = String(value || "") - .trim() - .replace(/[^\p{L}\p{N}._-]+/gu, "-") - .replace(/^-+|-+$/g, ""); - return normalized || fallback; - } - - function sanitizeSSHHost(value) { - const normalized = String(value || "") - .trim() - .replace(/[^a-zA-Z0-9.:[\]-]+/g, ""); - return normalized || "服务器地址"; - } - function createEmptySettingsForm() { return { server: { host: "", port: 5200, https_mode: "direct", proxy_https_port: 0 }, @@ -515,49 +446,6 @@ export function useDashboard() { return labels[value] || (value ? "未知" : "—"); } - function serverSSHKey(server) { - if (!server?.private_key_ref) return null; - return sshKeys.value.find((item) => item.reference === server.private_key_ref) || null; - } - - function serverSSHKeyStatusLabel(server) { - const labels = { - not_configured: "未配置", - pending: "部署中", - deployed: "已部署并验证", - manual: "已配置,待验证", - failed: "部署失败,保留密码回退", - }; - return labels[server?.ssh_key_status] || "未配置"; - } - - function serverSSHKeyStatusClass(server) { - if (server?.ssh_key_status === "deployed") return "success"; - if (server?.ssh_key_status === "failed") return "danger"; - if (server?.ssh_key_status === "pending") return "warning"; - return "neutral"; - } - - function serverSSHCommand(server) { - if (!server?.address || !server?.username) return "—"; - const port = Number(server.port || 22); - const portOption = port === 22 ? "" : ` -p ${port}`; - return `ssh${portOption} ${server.username}@${server.address}`; - } - - function serverSSHKeyHint(server) { - if (server?.ssh_key_status === "deployed") { - return "Scert 已自动部署公钥并验证密钥登录,后续部署默认使用托管私钥。"; - } - if (server?.ssh_key_status === "failed") { - return server.ssh_key_error || "公钥部署或密钥登录验证失败,当前仍使用密码回退。"; - } - if (server?.auth_method === "private_key") { - return "当前使用已配置的私钥连接,尚未完成自动部署验证。"; - } - return "保存服务器后,Scert 会先用密码部署公钥,再自动验证密钥登录。"; - } - function formatDate(value) { if (!value) return "尚未签发"; return new Intl.DateTimeFormat("zh-CN", { @@ -599,6 +487,7 @@ export function useDashboard() { serverEditingId.value = item.id; serverForm.value = { ...item, + auth_method: "password", passwordConfigured: item.password_configured === true, password: "", validation_command: (item.validation_command || []).join("\n"), @@ -611,101 +500,10 @@ export function useDashboard() { function closeServerForm() { if (!serverSaving.value) { - showEmbeddedSSHKeyGuide.value = false; showServerForm.value = false; } } - function openSSHKeyCreate(options = {}) { - sshKeyForm.value = createEmptySSHKeyForm(); - sshKeyFormError.value = ""; - sshKeyPlatform.value = "windows"; - sshKeyPassphraseVisible.value = false; - sshKeyRandomSuffix.value = createSSHKeyRandomSuffix(); - sshKeyForm.value.name = sshKeyFileName.value; - showEmbeddedSSHKeyGuide.value = options.embedded === true; - showSSHKeyForm.value = options.embedded !== true; - } - - function closeSSHKeyForm() { - if (sshKeySaving.value) return; - sshKeyForm.value = createEmptySSHKeyForm(); - sshKeyFormError.value = ""; - sshKeyPassphraseVisible.value = false; - showEmbeddedSSHKeyGuide.value = false; - showSSHKeyForm.value = false; - } - - async function importSSHKeyFile(event) { - const file = event.target.files?.[0]; - event.target.value = ""; - if (!file) return; - try { - const content = await file.text(); - if (!content.trim()) throw new Error("选择的私钥文件为空"); - sshKeyForm.value.private_key = content; - sshKeyFormError.value = ""; - notice.value = `已读取私钥文件:${file.name}`; - } catch (err) { - sshKeyFormError.value = err.message || "读取私钥文件失败"; - } - } - - async function copySSHKeyCommand(value, message) { - try { - await navigator.clipboard.writeText(value); - notice.value = message; - } catch { - sshKeyFormError.value = "浏览器未允许访问剪贴板,请手动复制命令"; - } - } - - async function saveSSHKey() { - sshKeyFormError.value = ""; - sshKeySaving.value = true; - try { - const response = await fetchAdmin("/api/v1/ssh-keys", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(sshKeyForm.value), - }); - const result = await response.json().catch(() => ({})); - if (!response.ok) throw new Error(result.error || "保存 SSH 私钥失败"); - if (showEmbeddedSSHKeyGuide.value && result.reference) { - serverForm.value.private_key_ref = result.reference; - } - sshKeyForm.value = createEmptySSHKeyForm(); - showEmbeddedSSHKeyGuide.value = false; - showSSHKeyForm.value = false; - notice.value = "SSH 私钥已加密保存"; - await loadData(); - } catch (err) { - sshKeyFormError.value = err.message || "保存 SSH 私钥失败"; - } finally { - sshKeySaving.value = false; - } - } - - async function deleteSSHKey(item) { - if ( - !window.confirm( - `确定删除 SSH 私钥“${item.name}”吗?正在被服务器使用的私钥无法删除。`, - ) - ) - return; - try { - const response = await fetchAdmin(`/api/v1/ssh-keys/${item.id}`, { - method: "DELETE", - }); - const result = await response.json().catch(() => ({})); - if (!response.ok) throw new Error(result.error || "删除 SSH 私钥失败"); - notice.value = "SSH 私钥已删除"; - await loadData(); - } catch (err) { - error.value = err.message || "删除 SSH 私钥失败"; - } - } - function parseCommand(value) { return value .split(/\n/) @@ -722,8 +520,7 @@ export function useDashboard() { address: serverForm.value.address, port: Number(serverForm.value.port), username: serverForm.value.username, - auth_method: serverForm.value.auth_method, - private_key_ref: serverForm.value.private_key_ref, + auth_method: "password", host_key_fingerprint: serverForm.value.host_key_fingerprint, certificate_path: serverForm.value.certificate_path, private_key_path: serverForm.value.private_key_path, @@ -732,9 +529,7 @@ export function useDashboard() { validation_command: parseCommand(serverForm.value.validation_command), reload_command: parseCommand(serverForm.value.reload_command), }; - if (serverForm.value.auth_method === "password") { - payload.password = serverForm.value.password; - } + payload.password = serverForm.value.password; const path = serverEditingId.value ? `/api/v1/servers/${serverEditingId.value}` : "/api/v1/servers"; @@ -768,7 +563,7 @@ export function useDashboard() { try { const options = { method: "POST" }; if (action === "issue") { - const suffix = crypto.randomUUID ? crypto.randomUUID() : createSSHKeyRandomSuffix(); + const suffix = crypto.randomUUID ? crypto.randomUUID() : createRandomSuffix(); options.headers = { "Idempotency-Key": `issue-${item.id}-${suffix}` }; } const response = await fetchAdmin(`/api/v1/domains/${item.id}/${action}`, options); @@ -1152,7 +947,6 @@ export function useDashboard() { authResponse, domainResponse, serverResponse, - sshKeyResponse, certificateResponse, taskResponse, auditResponse, @@ -1163,7 +957,6 @@ export function useDashboard() { fetchAdmin("/api/v1/auth/session"), fetchAdmin("/api/v1/domains"), fetchAdmin("/api/v1/servers"), - fetchAdmin("/api/v1/ssh-keys"), fetchAdmin("/api/v1/certificates"), fetchAdmin("/api/v1/tasks?limit=20"), fetchAdmin("/api/v1/audit-logs?limit=20"), @@ -1174,7 +967,6 @@ export function useDashboard() { statusResponse, domainResponse, serverResponse, - sshKeyResponse, certificateResponse, taskResponse, auditResponse, @@ -1188,7 +980,6 @@ export function useDashboard() { currentUser.value = await authResponse.json(); domains.value = (await domainResponse.json()).items || []; servers.value = (await serverResponse.json()).items || []; - sshKeys.value = (await sshKeyResponse.json()).items || []; certificates.value = (await certificateResponse.json()).items || []; tasks.value = (await taskResponse.json()).items || []; auditLogs.value = (await auditResponse.json()).items || []; @@ -1240,7 +1031,6 @@ export function useDashboard() { canRunRenewal, domains, servers, - sshKeys, certificates, tasks, auditLogs, @@ -1279,10 +1069,6 @@ export function useDashboard() { serverEditingId, serverSaving, serverFormError, - showSSHKeyForm, - showEmbeddedSSHKeyGuide, - sshKeySaving, - sshKeyFormError, certificateTypeLabels, domainStatusLabels, taskStatusLabels, @@ -1295,24 +1081,10 @@ export function useDashboard() { environmentLabels, webServerLabels, serverAuthLabel, - serverSSHKey, - serverSSHKeyStatusLabel, - serverSSHKeyStatusClass, - serverSSHCommand, - serverSSHKeyHint, isEditing, formTitle, form, serverForm, - sshKeyForm, - sshKeyPlatform, - sshKeyPassphraseVisible, - sshKeyCommandUsername, - sshKeyCommandHost, - sshKeyFileName, - sshKeyPath, - sshKeyPrivatePath, - sshKeyPublicPath, showSettings, settingsSaving, settingsError, @@ -1321,8 +1093,6 @@ export function useDashboard() { importSaving, importError, importResult, - sshKeyCommands, - sshPublicKeyCommands, defaultCertificatePath, defaultCertificateChainPath, defaultPrivateKeyPath, @@ -1332,12 +1102,6 @@ export function useDashboard() { openServerCreate, openServerEdit, closeServerForm, - openSSHKeyCreate, - closeSSHKeyForm, - importSSHKeyFile, - copySSHKeyCommand, - saveSSHKey, - deleteSSHKey, openCertificateImport, closeCertificateImport, selectCertificateImportFile, diff --git a/frontend/src/views/Dashboard/Dashboard.test.js b/frontend/src/views/Dashboard/Dashboard.test.js index 4769d9a..fda2861 100644 --- a/frontend/src/views/Dashboard/Dashboard.test.js +++ b/frontend/src/views/Dashboard/Dashboard.test.js @@ -60,7 +60,7 @@ test("用户管理导航按权限显示,权限变化后回到基本信息", () assert.equal(navigation.sections.value.length, 7); user.value = null; assert.equal(navigation.activeSection.value, "overview"); - assert.equal(navigation.sections.value.length, 6); + assert.equal(navigation.sections.value.length, 5); }); test("单板块布局使用互斥条件,切换重置滚动且保留弹窗入口", async () => { @@ -308,24 +308,29 @@ test("编辑服务器正确保留已有密码状态,新建和未配置密码 assert.equal(state.serverEditingId.value, ""); }); -test("SSH引导目标直接跟随服务器配置中的地址和用户", async (t) => { - const { state } = await setup(t, () => verifiedResponse()); +test("部署服务器仅使用密码认证且不暴露私钥管理入口", async (t) => { + const requests = []; + const { state } = await mountComposable(t, useDashboard, async (path, options = {}) => { + if (options.method) { + requests.push({ path, ...options }); + return Response.json({}); + } + return verifiedResponse(); + }); state.openServerCreate(); - state.serverForm.value.username = "root"; - state.serverForm.value.address = "45.136.13.241"; - state.openSSHKeyCreate({ embedded: true }); - 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"; + assert.equal(state.serverForm.value.auth_method, "password"); + assert.equal("openSSHKeyCreate" in state, false); + assert.equal("sshKeys" in state, false); + state.serverForm.value.name = "生产服务器"; + state.serverForm.value.address = "example.test"; state.serverForm.value.username = "deploy"; - await nextTick(); - assert.equal(state.sshKeyForm.value.name, "manual-key-name"); + state.serverForm.value.password = "test-password"; + state.serverForm.value.host_key_fingerprint = "SHA256:test"; + await state.saveServer(); + const payload = JSON.parse(requests.at(-1).body); + assert.equal(payload.auth_method, "password"); + assert.equal(payload.password, "test-password"); + assert.equal("private_key_ref" in payload, false); }); async function fill(state) { @@ -712,7 +717,6 @@ test("serverModal.compilesAndPreservesDeploymentFields", async () => { address: "example.test", port: 22, username: "deploy", - private_key_ref: "key-ref", host_key_fingerprint: "SHA256:test-fingerprint", certificate_path: "/test/cert.pem", certificate_chain_path: "/test/fullchain.pem", @@ -720,25 +724,6 @@ test("serverModal.compilesAndPreservesDeploymentFields", async () => { validation_command: "nginx\n-t", reload_command: "nginx\n-s\nreload", }, - sshKeys: [], - openSSHKeyCreate: () => {}, - showEmbeddedSSHKeyGuide: false, - closeSSHKeyForm: () => {}, - sshKeySaving: false, - sshKeyFormError: "", - sshKeyPlatform: "windows", - sshKeyFileName: "test-key", - sshKeyPrivatePath: "/test/private", - sshKeyPublicPath: "/test/public", - sshKeyCommandUsername: "deploy", - sshKeyCommandHost: "example.test", - sshKeyCommands: { windows: "generate-windows", linux: "generate-linux" }, - sshPublicKeyCommands: { windows: "install-windows", linux: "install-linux" }, - sshKeyForm: { name: "", private_key: "", passphrase: "" }, - importSSHKeyFile: () => {}, - sshKeyPassphraseVisible: false, - copySSHKeyCommand: () => {}, - saveSSHKey: () => {}, defaultCertificatePath: "", defaultCertificateChainPath: "", defaultPrivateKeyPath: "", @@ -789,67 +774,7 @@ test("changePassword.loadsScopedBaseStylesAndCompiles", async () => { assert.match(base, /\.field\s*\{/); }); -test("sshKeyModal.compilesAndPreservesCredentialFields", async () => { - const { readFile } = await import("node:fs/promises"); - const { parse, compileScript, compileTemplate } = await import("@vue/compiler-sfc"); - const { renderToString } = await import("@vue/server-renderer"); - const Vue = await import("vue"); - const source = await readFile(new URL("./SSHKeyModal.vue", import.meta.url), "utf8"); - const { descriptor, errors } = parse(source); - assert.deepEqual(errors, []); - assert.ok(compileScript(descriptor, { id: "ssh-key-modal" })); - const compiled = compileTemplate({ - source: descriptor.template.content, - filename: "SSHKeyModal.vue", - id: "ssh-key-modal", - compilerOptions: { mode: "function" }, - }); - assert.deepEqual(compiled.errors, []); - assert.ok(descriptor.styles.some(style => style.scoped && style.src === "./Dashboard.css")); - assert.ok(descriptor.styles.some(style => style.scoped && style.src === "./SSHKeyModal.css")); - assert.doesNotMatch(source, / ({ - showSSHKeyForm: true, - closeSSHKeyForm: () => {}, - saveSSHKey: () => {}, - sshKeyPlatform: platform, - sshKeyFileName: "test-key", - sshKeyPrivatePath: "/test/private", - sshKeyPublicPath: "/test/public", - sshKeyCommandUsername: "deploy", - sshKeyCommandHost: "example.test", - copySSHKeyCommand: () => {}, - sshKeyCommands: { windows: "generate-windows", linux: "generate-linux" }, - sshPublicKeyCommands: { windows: "install-windows", linux: "install-linux" }, - sshKeyForm: { name: "", private_key: "", passphrase: "" }, - importSSHKeyFile: () => {}, - sshKeyPassphraseVisible: false, - sshKeyFormError: "test-validation-error", - sshKeySaving: false, - }), - }); - app.component("HelpTip", { - setup: (_, { slots }) => () => Vue.h("span", { class: "test-help-tip" }, slots.default?.()), - }); - const html = await renderToString(app); - assert.match(html, /class="modal-card ssh-key-modal"/); - assert.match(html, /type="submit"/); - assert.match(html, /type="file"/); - assert.match(html, /type="password"/); - assert.match(html, /rows="5"/); - assert.match(html, /test-validation-error/); - assert.equal((html.match(/ required/g) || []).length, 2); - assert.ok(html.includes(`generate-${platform}`)); - assert.ok(html.includes(`install-${platform}`)); - assert.ok(html.includes("deploy@example.test")); - } - const css = await readFile(new URL("./SSHKeyModal.css", import.meta.url), "utf8"); - assert.match(css, /\.ssh-key-modal\s*\{[^}]*overflow:\s*auto;/); -});test("domainAction.refreshesPersistedFailureWithoutLosingError", async (t) => { +test("domainAction.refreshesPersistedFailureWithoutLosingError", async (t) => { let issued = false; const { state } = await mountComposable(t, useDashboard, async (path) => { if (path.endsWith("/issue")) { diff --git a/frontend/src/views/Dashboard/Dashboard.vue b/frontend/src/views/Dashboard/Dashboard.vue index bc339fe..a8cd266 100644 --- a/frontend/src/views/Dashboard/Dashboard.vue +++ b/frontend/src/views/Dashboard/Dashboard.vue @@ -385,107 +385,6 @@ const { activeSection, activeLabel, sections, selectSection } = useDashboardNavi -
-
-
-

安全凭据

-

服务器 SSH 密钥

-
- -
-
- 还没有部署服务器 - 添加服务器后,Scert 会自动生成密钥、部署公钥并验证密钥登录。 - -
-
-
-
-
- {{ item.name }} - {{ displayLabel(webServerLabels, item.web_server) }} - - {{ serverSSHKeyStatusLabel(item) }} - -
-
- - -
-
-
- {{ item.username }}@{{ item.address }}:{{ item.port }} - 主机指纹:{{ item.host_key_fingerprint || "未填写" }} - 认证:{{ serverAuthLabel(item) }} -
-
- 托管域名 -
- - {{ domain.name }} - -
- 未关联托管域名 -
-
-
- 托管私钥 - {{ serverSSHKey(item)?.name || "尚未生成" }} - {{ serverSSHKey(item)?.fingerprint || item.ssh_key_fingerprint || "—" }} -
-
- 公钥部署 - {{ serverSSHKeyStatusLabel(item) }} - {{ serverSSHKeyHint(item) }} -
-
- 最近部署 / 测试 - {{ formatDate(item.ssh_key_deployed_at) }} / {{ formatDate(item.ssh_key_tested_at) }} - {{ item.ssh_key_error }} -
-
-
-
- 服务器 SSH 命令 - {{ serverSSHCommand(item) }} -
- -
-
-
-
-
-
- 兼容入口 - 未关联服务器的私钥 -
- -
-
- - {{ item.name }} · {{ item.fingerprint }} - - -
-
-
-
@@ -507,14 +406,10 @@ const { activeSection, activeLabel, sections, selectSection } = useDashboardNavi
{{ item.name }}{{ displayLabel(webServerLabels, item.web_server) }} - > - {{ serverSSHKeyStatusLabel(item) }} -
{{ item.username }}@{{ item.address }}:{{ item.port }}{{ serverAuthLabel(item) }}托管私钥:{{ serverSSHKey(item)?.name || "尚未生成" }}指纹:{{ item.host_key_fingerprint }}
diff --git a/frontend/src/views/Dashboard/DeploymentFeedback.js b/frontend/src/views/Dashboard/DeploymentFeedback.js index b4d96f6..ad71759 100644 --- a/frontend/src/views/Dashboard/DeploymentFeedback.js +++ b/frontend/src/views/Dashboard/DeploymentFeedback.js @@ -1,11 +1,5 @@ export function serverAuthLabel(server) { - if (server.auth_method === "password") { - return server.password_configured ? "SSH 密码已配置" : "SSH 密码未配置"; - } - if (server.auth_method === "private_key") { - return server.private_key_ref ? "SSH 私钥已配置" : "SSH 私钥未配置"; - } - return "认证方式未确认"; + return server.password_configured ? "SSH 密码已配置" : "SSH 密码未配置"; } export function deploymentSummary(report) { diff --git a/frontend/src/views/Dashboard/DeploymentResult.test.js b/frontend/src/views/Dashboard/DeploymentResult.test.js index 726bfc4..a196987 100644 --- a/frontend/src/views/Dashboard/DeploymentResult.test.js +++ b/frontend/src/views/Dashboard/DeploymentResult.test.js @@ -14,12 +14,11 @@ const report = { results: [{ server_id: "server-1", server: "验收服务器", status: "success", message: "部署完成" }], }; -test("服务器认证提示区分密码、私钥及缺失配置", () => { +test("服务器认证提示只显示密码配置状态", () => { assert.equal(serverAuthLabel({ auth_method: "password", password_configured: true }), "SSH 密码已配置"); - assert.equal(serverAuthLabel({ auth_method: "password", private_key_ref: "secret://test" }), "SSH 密码未配置"); - assert.equal(serverAuthLabel({ auth_method: "private_key", private_key_ref: "secret://test" }), "SSH 私钥已配置"); - assert.equal(serverAuthLabel({ auth_method: "private_key" }), "SSH 私钥未配置"); - assert.equal(serverAuthLabel({}), "认证方式未确认"); + assert.equal(serverAuthLabel({ auth_method: "password", password_configured: false }), "SSH 密码未配置"); + assert.equal(serverAuthLabel({ auth_method: "private_key", password_configured: false }), "SSH 密码未配置"); + assert.equal(serverAuthLabel({}), "SSH 密码未配置"); }); test("部署汇总不把空目标、缺失结果或部分失败称为成功", () => { @@ -145,6 +144,5 @@ test("部署结果组件可编译且认证提示绑定真实配置", async () => assert.match(source, /role="dialog"/); const dashboard = await readFile(new URL("./Dashboard.vue", import.meta.url), "utf8"); assert.match(dashboard, /serverAuthLabel\(item\)/); - assert.match(dashboard, /serverSSHKeyStatusLabel\(item\)/); - assert.match(dashboard, /serverSSHCommand\(item\)/); + assert.doesNotMatch(dashboard, /serverSSHKeyStatusLabel|serverSSHCommand|SSHKeyModal/); });