补充 DNS 验证等待测试
This commit is contained in:
1 parent
ddbf3b2d29
commit
519a538755
6 files changed
+149
-18
No files matched your search
@@ -5,15 +5,16 @@ import { useDashboard } from "./Dashboard.js";
|
||||
import { aliyunProvider, deferred, mountComposable, verifiedResponse } from "../../test-support/mount.js";
|
||||
|
||||
async function setup(t, request) {
|
||||
const { state } = await mountComposable(t, useDashboard, async (path) => {
|
||||
const mounted = await mountComposable(t, useDashboard, async (path) => {
|
||||
if (path === "/api/v1/dns/test") return request();
|
||||
if (path.endsWith("/dns/providers")) return Response.json({ items: [aliyunProvider] });
|
||||
if (path.endsWith("/settings")) return Response.json({ dns: { provider: "aliyun", credential_configured: true, verification_state: "verified" } });
|
||||
return Response.json({ items: [] });
|
||||
});
|
||||
const { state } = mounted;
|
||||
state.openSettings();
|
||||
await nextTick();
|
||||
return state;
|
||||
return mounted;
|
||||
}
|
||||
|
||||
async function fill(state) {
|
||||
@@ -23,7 +24,7 @@ async function fill(state) {
|
||||
}
|
||||
|
||||
test("已保存凭据不变可保存,输入新凭据必须重新验证", async (t) => {
|
||||
const state = await setup(t, () => verifiedResponse());
|
||||
const { state } = await setup(t, () => verifiedResponse());
|
||||
assert.equal(state.dnsReadyToSave.value, true);
|
||||
await fill(state);
|
||||
assert.equal(state.dnsReadyToSave.value, false);
|
||||
@@ -35,7 +36,7 @@ test("已保存凭据不变可保存,输入新凭据必须重新验证", async
|
||||
|
||||
test("管理设置不接受旧输入的在途 DNS 响应", async (t) => {
|
||||
const pending = deferred();
|
||||
const state = await setup(t, () => pending.promise);
|
||||
const { state } = await setup(t, () => pending.promise);
|
||||
await fill(state);
|
||||
const task = state.testDNS();
|
||||
state.settingsForm.value.dns.test_domain = "other.test";
|
||||
@@ -47,14 +48,14 @@ test("管理设置不接受旧输入的在途 DNS 响应", async (t) => {
|
||||
});
|
||||
|
||||
test("管理设置拒绝过期验证令牌", async (t) => {
|
||||
const state = await setup(t, () => Response.json({ credential_ref: "secret://test/only", verification_token: "expired", expires_at: "2000-01-01T00:00:00Z" }));
|
||||
const { state } = await setup(t, () => Response.json({ credential_ref: "secret://test/only", verification_token: "expired", expires_at: "2000-01-01T00:00:00Z" }));
|
||||
await fill(state);
|
||||
await state.testDNS();
|
||||
assert.equal(state.dnsReadyToSave.value, false);
|
||||
});
|
||||
|
||||
test("管理设置变更托管区不能复用验证令牌", async (t) => {
|
||||
const state = await setup(t, () => verifiedResponse());
|
||||
const { state } = await setup(t, () => verifiedResponse());
|
||||
await fill(state);
|
||||
state.settingsForm.value.dns.credentials.managed_zones = "example.test";
|
||||
state.settingsForm.value.dns.credentials.allowed_domains = "example.test";
|
||||
@@ -67,7 +68,7 @@ test("管理设置变更托管区不能复用验证令牌", async (t) => {
|
||||
|
||||
test("关闭设置后不显示旧 DNS 请求的成功提示", async (t) => {
|
||||
const pending = deferred();
|
||||
const state = await setup(t, () => pending.promise);
|
||||
const { state } = await setup(t, () => pending.promise);
|
||||
await fill(state);
|
||||
const task = state.testDNS();
|
||||
state.closeSettings();
|
||||
@@ -81,7 +82,7 @@ test("管理设置新请求成功后旧失败不能删除令牌", async (t) => {
|
||||
const first = deferred();
|
||||
const second = deferred();
|
||||
let count = 0;
|
||||
const state = await setup(t, () => (++count === 1 ? first.promise : second.promise));
|
||||
const { state } = await setup(t, () => (++count === 1 ? first.promise : second.promise));
|
||||
await fill(state);
|
||||
const oldTask = state.testDNS();
|
||||
const newTask = state.testDNS();
|
||||
@@ -93,3 +94,52 @@ test("管理设置新请求成功后旧失败不能删除令牌", async (t) => {
|
||||
assert.equal(state.dnsTestError.value, "");
|
||||
assert.equal(state.dnsReadyToSave.value, true);
|
||||
});
|
||||
|
||||
test("管理设置 DNS 验证显示等待进度,并在结束后停止计时", async (t) => {
|
||||
const pending = deferred();
|
||||
const { state, runIntervals, advanceTime } = await setup(t, () => pending.promise);
|
||||
await fill(state);
|
||||
const task = state.testDNS();
|
||||
|
||||
assert.equal(state.dnsTesting.value, true);
|
||||
assert.equal(state.dnsVerificationElapsedSeconds.value, 0);
|
||||
assert.equal(state.dnsVerificationTimeoutSeconds.value, 930);
|
||||
advanceTime(3200);
|
||||
runIntervals();
|
||||
assert.equal(state.dnsVerificationElapsedSeconds.value, 3);
|
||||
|
||||
pending.resolve(Response.json({
|
||||
verified: true,
|
||||
credential_ref: "secret://test/only",
|
||||
verification_token: "test-token",
|
||||
expires_at: new Date(Date.now() + 60000).toISOString(),
|
||||
verification_timeout_secs: 31,
|
||||
}));
|
||||
await task;
|
||||
assert.equal(state.dnsTesting.value, false);
|
||||
assert.equal(state.dnsVerificationElapsedSeconds.value, 0);
|
||||
assert.equal(state.dnsVerificationTimeoutSeconds.value, 31);
|
||||
advanceTime(1000);
|
||||
runIntervals();
|
||||
assert.equal(state.dnsVerificationElapsedSeconds.value, 0);
|
||||
});
|
||||
|
||||
test("关闭管理设置会停止 DNS 等待计时器", async (t) => {
|
||||
const pending = deferred();
|
||||
const { state, runIntervals, advanceTime } = await setup(t, () => pending.promise);
|
||||
await fill(state);
|
||||
const task = state.testDNS();
|
||||
advanceTime(1000);
|
||||
runIntervals();
|
||||
assert.equal(state.dnsVerificationElapsedSeconds.value, 1);
|
||||
|
||||
state.closeSettings();
|
||||
assert.equal(state.dnsTesting.value, false);
|
||||
assert.equal(state.dnsVerificationElapsedSeconds.value, 0);
|
||||
advanceTime(1000);
|
||||
runIntervals();
|
||||
assert.equal(state.dnsVerificationElapsedSeconds.value, 0);
|
||||
|
||||
pending.resolve(verifiedResponse());
|
||||
await task;
|
||||
});
|
||||
Reference in new issue
Block a user