保存证书校验后台任务及独立结果的修复前基线
校验结果事务持久化、三库迁移及前端详情接线已实现,完整回归仍在执行。审查发现前端校验幂等键包含路径分隔符,下一批补回归并修复;本提交不是正式发布或生产验收结论。
This commit is contained in:
1 parent
fce5a84dd4
commit
24a9683c43
27 files changed
+803
-23
No files matched your search
@@ -588,7 +588,7 @@ export function useDashboard() {
|
||||
notice.value = "";
|
||||
try {
|
||||
const options = { method: "POST" };
|
||||
if (action === "issue" || action === "deploy") {
|
||||
if (action === "issue" || action === "deploy" || action === "certificate/validate") {
|
||||
const suffix = crypto.randomUUID ? crypto.randomUUID() : createRandomSuffix();
|
||||
options.headers = { "Idempotency-Key": `${action}-${item.id}-${suffix}` };
|
||||
}
|
||||
@@ -597,7 +597,8 @@ export function useDashboard() {
|
||||
if (response.status === 202 && !result.task?.id) {
|
||||
throw new Error("服务未返回任务编号,请在运行概览确认是否已接收,勿重复提交");
|
||||
}
|
||||
if (response.ok && result.task?.id && (response.status === 202 || result.accepted || result.replayed)) {
|
||||
if ((response.ok || response.status === 409 && result.replayed) && result.task?.id &&
|
||||
(response.status === 202 || result.accepted || result.replayed)) {
|
||||
notice.value = `任务已提交:${result.task.id},可在运行概览查看执行结果`;
|
||||
if (action === "deploy") {
|
||||
deploymentResult.value = {
|
||||
@@ -606,6 +607,7 @@ export function useDashboard() {
|
||||
taskMessage: result.task.message || "", report: null, error: "", queryError: "",
|
||||
};
|
||||
}
|
||||
if (action === "certificate/validate") await taskMonitor.openTaskDetails(result.task);
|
||||
return;
|
||||
}
|
||||
if (action === "deploy") {
|
||||
|
||||
@@ -141,6 +141,7 @@ test("完整页面逐个渲染六个板块,每次只有一个内容标题", as
|
||||
app.component("DNSAccounts", { render: () => Vue.h("h2", headings["dns-accounts"]) });
|
||||
app.component("DeploymentResult", { render: () => null });
|
||||
app.component("TaskDeploymentResults", { render: () => null });
|
||||
app.component("TaskValidationResult", { render: () => null });
|
||||
const warnings = [];
|
||||
app.config.warnHandler = (message) => warnings.push(message);
|
||||
const html = await renderToString(app);
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useDashboardNavigation } from "./DashboardNavigation.js";
|
||||
import { useDashboard } from "./Dashboard.js";
|
||||
import DeploymentResult from "./DeploymentResult.vue";
|
||||
import TaskDeploymentResults from "./TaskDeploymentResults.vue";
|
||||
import TaskValidationResult from "./TaskValidationResult.vue";
|
||||
|
||||
const dashboard = useDashboard();
|
||||
const {
|
||||
@@ -40,6 +41,7 @@ const {
|
||||
notice,
|
||||
taskQueryError,
|
||||
taskDeploymentReport,
|
||||
taskValidationResult,
|
||||
formError,
|
||||
showForm,
|
||||
editingId,
|
||||
@@ -521,6 +523,10 @@ const { activeSection, activeLabel, sections, selectSection } = useDashboardNavi
|
||||
<p>{{ taskDetails.message || "无附加信息" }}</p>
|
||||
</div>
|
||||
<TaskDeploymentResults v-if="taskDeploymentReport" :report="taskDeploymentReport" />
|
||||
<TaskValidationResult v-if="taskValidationResult" :result="taskValidationResult" />
|
||||
<p v-else-if="taskDetails.task_type === 'certificate_validate' && taskDetails.status === 'success'" class="muted">
|
||||
该任务没有留存校验详情,不据此推断当前证书仍然有效。
|
||||
</p>
|
||||
<h3 class="modal-section-title">执行尝试</h3>
|
||||
<div v-if="taskAttempts.length === 0" class="empty-state compact-empty">暂无执行尝试记录</div>
|
||||
<div v-else class="attempt-list">
|
||||
|
||||
@@ -6,6 +6,16 @@ export function taskIsPending(task) {
|
||||
return !terminalStatuses.has(task?.status);
|
||||
}
|
||||
|
||||
export function latestValidationResult(task, attempts, results) {
|
||||
if (task.task_type !== "certificate_validate" || task.status !== "success") return null;
|
||||
const latest = attempts.reduce((value, item) =>
|
||||
!value || item.attempt_number > value.attempt_number ? item : value, null);
|
||||
if (!latest || latest.status !== "success") return null;
|
||||
const stored = results.find((item) => item.task_id === task.id &&
|
||||
item.attempt_id === latest.id && item.attempt_number === latest.attempt_number);
|
||||
return Array.isArray(stored?.validation?.domains) ? stored.validation : null;
|
||||
}
|
||||
|
||||
export function latestDeploymentReport(task, attempts, results, reports = []) {
|
||||
const latest = Math.max(0, ...attempts.map((item) => item.attempt_number || 0));
|
||||
if (taskIsPending(task) || latest === 0) return null;
|
||||
@@ -31,6 +41,7 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
taskDetails, taskAttempts, taskDetailsLoading, taskDetailsError, refreshResources }) {
|
||||
const taskQueryError = ref("");
|
||||
const taskDeploymentReport = ref(null);
|
||||
const taskValidationResult = ref(null);
|
||||
let selectedID = "";
|
||||
let stopped = false;
|
||||
let timer;
|
||||
@@ -53,11 +64,13 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
const path = `/api/v1/tasks/${encodeURIComponent(id)}`;
|
||||
const task = await readJSON(path, signal);
|
||||
if (task.id !== id || !task.status) throw new Error("任务状态响应不完整,将自动重试");
|
||||
const [attempts, results] = await Promise.all([
|
||||
const [attempts, results, validations] = await Promise.all([
|
||||
readJSON(`${path}/attempts`, signal),
|
||||
readJSON(`${path}/deployment-results`, signal),
|
||||
task.task_type === "certificate_validate"
|
||||
? readJSON(`${path}/validation-results`, signal) : Promise.resolve({ items: [] }),
|
||||
]);
|
||||
if (!Array.isArray(attempts.items) || !Array.isArray(results.items)) {
|
||||
if (!Array.isArray(attempts.items) || !Array.isArray(results.items) || !Array.isArray(validations.items)) {
|
||||
throw new Error("任务执行记录响应不完整,将自动重试");
|
||||
}
|
||||
const latestAttempt = attempts.items.reduce((latest, item) =>
|
||||
@@ -72,6 +85,7 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
task,
|
||||
attempts: attempts.items,
|
||||
report: latestDeploymentReport(task, attempts.items, results.items, results.reports),
|
||||
validation: latestValidationResult(task, attempts.items, validations.items),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -100,6 +114,7 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
taskDetails.value = snapshot.task;
|
||||
taskAttempts.value = snapshot.attempts;
|
||||
taskDeploymentReport.value = snapshot.report;
|
||||
taskValidationResult.value = snapshot.validation;
|
||||
taskDetailsError.value = "";
|
||||
}
|
||||
if (deploymentResult.value?.taskID === id) {
|
||||
@@ -125,6 +140,7 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
taskDetails.value = null;
|
||||
taskAttempts.value = [];
|
||||
taskDeploymentReport.value = null;
|
||||
taskValidationResult.value = null;
|
||||
}
|
||||
}
|
||||
if (deploymentResult.value?.taskID === id) {
|
||||
@@ -149,6 +165,7 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
taskDetails.value = null;
|
||||
taskAttempts.value = [];
|
||||
taskDeploymentReport.value = null;
|
||||
taskValidationResult.value = null;
|
||||
if (deploymentResult.value) {
|
||||
deploymentResult.value.report = null;
|
||||
deploymentResult.value.certificateImported = false;
|
||||
@@ -179,6 +196,7 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
taskDetails.value = null;
|
||||
taskAttempts.value = [];
|
||||
taskDeploymentReport.value = null;
|
||||
taskValidationResult.value = null;
|
||||
taskDetailsError.value = "";
|
||||
taskDetailsLoading.value = true;
|
||||
await refreshTaskStatus();
|
||||
@@ -192,6 +210,7 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
taskDetails.value = null;
|
||||
taskAttempts.value = [];
|
||||
taskDeploymentReport.value = null;
|
||||
taskValidationResult.value = null;
|
||||
taskDetailsError.value = "";
|
||||
taskDetailsLoading.value = false;
|
||||
}
|
||||
@@ -203,5 +222,6 @@ export function useTaskMonitor({ fetchAdmin, tasks, deploymentResult, showTaskDe
|
||||
controller?.abort();
|
||||
});
|
||||
|
||||
return { taskQueryError, taskDeploymentReport, refreshTaskStatus, openTaskDetails, closeTaskDetails };
|
||||
return { taskQueryError, taskDeploymentReport, taskValidationResult,
|
||||
refreshTaskStatus, openTaskDetails, closeTaskDetails };
|
||||
}
|
||||
@@ -1,13 +1,119 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { useDashboard } from "./Dashboard.js";
|
||||
import { latestDeploymentReport } from "./TaskMonitor.js";
|
||||
import { latestDeploymentReport, latestValidationResult } from "./TaskMonitor.js";
|
||||
import { validationDate } from "./TaskValidationResult.js";
|
||||
import { deploymentSummary } from "./DeploymentFeedback.js";
|
||||
import { deferred, mountComposable } from "../../test-support/mount.js";
|
||||
|
||||
const initialTask = { id: "async-task", domain_id: "domain-1", task_type: "certificate_deploy", status: "running" };
|
||||
const target = { server_id: "server-1", server: "部署目标", status: "success", attempt_number: 1 };
|
||||
|
||||
test("校验只展示当前任务最近一次成功尝试,不挪用旧结果", () => {
|
||||
const task = { ...initialTask, task_type: "certificate_validate", status: "success" };
|
||||
const attempts = [{ id: "latest", attempt_number: 2, status: "success" }];
|
||||
const validation = { domains: ["example.test"], fingerprint_sha256: "verified" };
|
||||
const stored = { task_id: task.id, attempt_id: "latest", attempt_number: 2, validation };
|
||||
assert.deepEqual(latestValidationResult(task, attempts, [stored]), validation);
|
||||
for (const record of [
|
||||
{ ...stored, task_id: "another" },
|
||||
{ ...stored, attempt_id: "old" },
|
||||
{ ...stored, attempt_number: 1 },
|
||||
{ ...stored, validation: {} },
|
||||
]) assert.equal(latestValidationResult(task, attempts, [record]), null);
|
||||
for (const status of ["running", "failed", "cancelled"]) {
|
||||
assert.equal(latestValidationResult({ ...task, status }, attempts, [stored]), null);
|
||||
}
|
||||
assert.equal(latestValidationResult(initialTask, attempts, [stored]), null);
|
||||
assert.equal(latestValidationResult(task, [], [stored]), null);
|
||||
assert.equal(validationDate("invalid"), "未记录");
|
||||
assert.equal(validationDate(null), "未记录");
|
||||
});
|
||||
|
||||
test("校验任务提交后读取独立详情,页面重开可恢复,撤权后清除", async (t) => {
|
||||
let task = { ...initialTask, task_type: "certificate_validate", status: "queued" };
|
||||
let denied = false;
|
||||
let submitted = 0;
|
||||
const validation = {
|
||||
domains: ["example.test"], serial_number: "42", fingerprint_sha256: "verified",
|
||||
not_before: "2026-01-01T00:00:00Z", not_after: "2026-12-31T00:00:00Z", chain_length: 2,
|
||||
};
|
||||
const { state } = await mountComposable(t, useDashboard, async (path, options = {}) => {
|
||||
if (path.endsWith("/certificate/validate")) {
|
||||
submitted++;
|
||||
assert.ok(options.headers["Idempotency-Key"]);
|
||||
return Response.json({ task, accepted: true }, { status: 202 });
|
||||
}
|
||||
if (path === `/api/v1/tasks/${task.id}`) return Response.json(task);
|
||||
if (path.endsWith("/attempts")) return Response.json({
|
||||
items: [{ id: "validation-attempt", attempt_number: 1, status: task.status }],
|
||||
});
|
||||
if (path.endsWith("/validation-results")) {
|
||||
if (denied) return Response.json({ error: "禁止访问" }, { status: 403 });
|
||||
return Response.json({ items: task.status === "success" ? [{
|
||||
task_id: task.id, attempt_id: "validation-attempt", attempt_number: 1, validation,
|
||||
}] : [] });
|
||||
}
|
||||
if (path.startsWith("/api/v1/tasks?")) return Response.json({ items: [task] });
|
||||
return Response.json({ items: [] });
|
||||
});
|
||||
await state.validateDomain({ id: "domain-1", name: "example.test" });
|
||||
assert.equal(submitted, 1);
|
||||
assert.equal(state.showTaskDetails.value, true);
|
||||
assert.match(state.notice.value, /任务已提交/);
|
||||
assert.equal(state.taskValidationResult.value, null);
|
||||
task = { ...task, status: "success" };
|
||||
await state.refreshTaskStatus();
|
||||
assert.deepEqual(state.taskValidationResult.value, validation);
|
||||
assert.equal(state.taskDeploymentReport.value, null);
|
||||
state.closeTaskDetails();
|
||||
assert.equal(state.taskValidationResult.value, null);
|
||||
await state.openTaskDetails(task);
|
||||
assert.deepEqual(state.taskValidationResult.value, validation);
|
||||
denied = true;
|
||||
await state.refreshTaskStatus();
|
||||
assert.equal(state.taskValidationResult.value, null);
|
||||
assert.equal(state.taskDetails.value, null);
|
||||
assert.match(state.taskDetailsError.value, /无权/);
|
||||
assert.equal(submitted, 1);
|
||||
});
|
||||
|
||||
test("校验详情拆分展示元数据和本地校验边界,不展示私钥路径", async () => {
|
||||
const { readFile } = await import("node:fs/promises");
|
||||
const source = await readFile(new URL("./TaskValidationResult.vue", import.meta.url), "utf8");
|
||||
for (const label of ["覆盖域名", "序列号", "生效时间", "到期时间", "证书链长度", "SHA-256 指纹", "不代表远端部署"]) {
|
||||
assert.ok(source.includes(label));
|
||||
}
|
||||
assert.match(source, /src="\.\/TaskValidationResult.css"/);
|
||||
assert.doesNotMatch(source, /private_key_path|certificate_path|&#x/);
|
||||
const { parse, compileTemplate } = await import("@vue/compiler-sfc");
|
||||
const { renderToString } = await import("@vue/server-renderer");
|
||||
const Vue = await import("vue");
|
||||
const { descriptor, errors } = parse(source);
|
||||
assert.deepEqual(errors, []);
|
||||
const compiled = compileTemplate({
|
||||
source: descriptor.template.content, filename: "TaskValidationResult.vue",
|
||||
id: "validation-result", compilerOptions: { mode: "function" },
|
||||
});
|
||||
assert.deepEqual(compiled.errors, []);
|
||||
const render = new Function("Vue", compiled.code)(Vue);
|
||||
const app = Vue.createSSRApp({
|
||||
render,
|
||||
setup: () => ({ validationDate, result: {
|
||||
domains: ["example.test", "*.example.test"], serial_number: "98765",
|
||||
fingerprint_sha256: "AB:CD:EF", chain_length: 2,
|
||||
not_before: "2026-01-01T00:00:00Z", not_after: "2026-12-31T00:00:00Z",
|
||||
} }),
|
||||
});
|
||||
const warnings = [];
|
||||
app.config.warnHandler = (message) => warnings.push(message);
|
||||
const html = await renderToString(app);
|
||||
assert.deepEqual(warnings, []);
|
||||
assert.match(html, /example.test、\*.example.test/);
|
||||
assert.match(html, /AB:CD:EF/);
|
||||
assert.match(html, /98765/);
|
||||
});
|
||||
|
||||
test("完整报告恢复站点验证与回滚事实,不被逐目标结果覆盖", () => {
|
||||
const task = { ...initialTask, status: "failed" };
|
||||
const attempts = [{ id: "attempt-2", attempt_number: 2, status: "failed" }];
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
.task-validation {
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.task-validation dl {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px 18px;
|
||||
}
|
||||
|
||||
.task-validation .wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.task-validation dt,
|
||||
.task-validation p {
|
||||
color: #64748b;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.task-validation dd {
|
||||
margin: 4px 0 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.task-validation dl {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export function validationDate(value) {
|
||||
if (!value) return "未记录";
|
||||
const date = new Date(value);
|
||||
return Number.isNaN(date.getTime()) ? "未记录" : date.toLocaleString("zh-CN", { hour12: false });
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<script setup>
|
||||
import { validationDate } from "./TaskValidationResult.js";
|
||||
|
||||
defineProps({ result: { type: Object, required: true } });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="task-validation" aria-label="本次证书校验结果">
|
||||
<h3>本次证书校验结果</h3>
|
||||
<dl>
|
||||
<div class="wide"><dt>覆盖域名</dt><dd>{{ result.domains.join("、") || "未记录" }}</dd></div>
|
||||
<div><dt>生效时间</dt><dd>{{ validationDate(result.not_before) }}</dd></div>
|
||||
<div><dt>到期时间</dt><dd>{{ validationDate(result.not_after) }}</dd></div>
|
||||
<div><dt>序列号</dt><dd>{{ result.serial_number || "未记录" }}</dd></div>
|
||||
<div><dt>证书链长度</dt><dd>{{ result.chain_length ?? "未记录" }}</dd></div>
|
||||
<div class="wide"><dt>SHA-256 指纹</dt><dd>{{ result.fingerprint_sha256 || "未记录" }}</dd></div>
|
||||
</dl>
|
||||
<p>此结果仅表示本次本地证书、私钥匹配及信任链校验通过,不代表远端部署或公网 HTTPS 验收通过。</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped src="./TaskValidationResult.css"></style>
|
||||
Reference in new issue
Block a user