接入托管域名HTTP验证与隔离挑战并补充回归用例

This commit is contained in:
xuans committed 2026-10-04 02:37:00 +08:00
1 parent e829d665ca
commit 5128b25e88
33 files changed
+1096 -76

No files matched your search

+11 -1
View File
@@ -9,6 +9,7 @@ function emptyForm() {
auto_renew: true,
acme_environment: "staging",
dns_provider: "",
challenge_type: "dns-01",
server_ids: [],
};
}
@@ -20,7 +21,8 @@ function domainPayload(form) {
sans: form.sans.split(/[\n,,]/).map((item) => item.trim()).filter(Boolean),
auto_renew: form.auto_renew,
acme_environment: form.acme_environment,
dns_provider: form.dns_provider,
dns_provider: form.challenge_type === "http-01" ? "" : form.dns_provider,
challenge_type: form.challenge_type || "dns-01",
};
}
@@ -71,6 +73,7 @@ export function useDomainForm({ fetchAdmin, domains, servers, domainServers, not
auto_renew: item.auto_renew !== false,
acme_environment: item.acme_environment || "staging",
dns_provider: item.dns_provider || "",
challenge_type: item.challenge_type || "dns-01",
};
formError.value = "";
savedPayload = "";
@@ -128,6 +131,13 @@ export function useDomainForm({ fetchAdmin, domains, servers, domainServers, not
return;
}
const payload = domainPayload(form.value);
if (payload.challenge_type === "http-01" && (
payload.certificate_type === "wildcard" ||
[payload.name, ...payload.sans].some((name) => name.trim().startsWith("*."))
)) {
formError.value = "HTTP-01 不支持泛域名,请选择 DNS-01";
return;
}
if (!payload.name.trim()) {
formError.value = "请输入主域名";
return;
@@ -32,6 +32,43 @@ function startCreate(state) {
state.form.value.server_ids = [firstServer.id, secondServer.id];
}
test("HTTP 验证保存方式且不携带 DNS 服务商", async (t) => {
const requests = [];
const { state } = await mountForm(t, async (path, options) => {
requests.push({ path, ...options });
if (path.endsWith("/servers")) return Response.json({ items: [] });
return Response.json({ ...firstDomain, ...JSON.parse(options.body) });
});
startCreate(state);
state.form.value.challenge_type = "http-01";
state.form.value.dns_provider = "aliyun";
await state.saveDomain();
assert.equal(JSON.parse(requests[0].body).challenge_type, "http-01");
assert.equal(JSON.parse(requests[0].body).dns_provider, "");
});
test("HTTP 验证拒绝主泛域名和附加泛域名,不提交请求", async (t) => {
let calls = 0;
const { state } = await mountForm(t, async () => { calls += 1; return Response.json({}); });
for (const type of ["wildcard", "san"]) {
startCreate(state);
state.form.value.challenge_type = "http-01";
state.form.value.certificate_type = type;
state.form.value.sans = "*.example.com";
await state.saveDomain();
assert.match(state.formError.value, /不支持泛域名/);
}
assert.equal(calls, 0);
});
test("编辑时保留已有 HTTP 验证方式", async (t) => {
const { state } = await mountForm(t, async () => Response.json({ items: [] }));
await state.openEdit({ ...firstDomain, challenge_type: "http-01" });
assert.equal(state.form.value.challenge_type, "http-01");
await state.openEdit(firstDomain);
assert.equal(state.form.value.challenge_type, "dns-01");
});
test("创建成功但关联冲突后只重试关联,不重复创建且不改变另一域名", async (t) => {
const requests = [];
let attempts = 0;
+13 -1
View File
@@ -96,7 +96,19 @@ const {
<option value="production">生产环境</option>
</select></label
>
<label class="field" for="dns-provider"
<label class="field" for="challenge-type">
<span>验证方式 <HelpTip>HTTP-01 要求全部域名的公网 80 端口挑战路径反代到 Scert,不支持泛域名;其余业务请求保持原站点配置。</HelpTip></span>
<select
id="challenge-type"
name="challenge_type"
v-model="form.challenge_type"
:disabled="saving || domainSaveUncertain"
>
<option value="dns-01">DNS-01(DNS 验证)</option>
<option value="http-01">HTTP-01(网站验证)</option>
</select>
</label>
<label v-if="form.challenge_type !== 'http-01'" class="field" for="dns-provider"
><span>DNS 验证服务商</span
><select
id="dns-provider"