fix(ui): защитить экспорт WireGuard от устаревших ответов

This commit is contained in:
Denozordec committed 2026-09-29 08:37:53 +07:00
1 parent d3ae2598fb
commit 4aa4726c6b
6 files changed
+105 -8

No files matched your search

+64
View File
@@ -351,3 +351,67 @@ test("WireGuard: переключение ждёт подтверждения и
await expect(page.getByRole("alert").filter({ hasText: "Сервер не подтвердил" })).toHaveCount(0)
expect(attempts).toBe(3)
})
for (const oldFails of [false, true]) {
test("WireGuard: поздний экспорт не меняет новую панель " + oldFails, async ({ page }) => {
await setup(page, "/wireguard")
let release: (() => void) | undefined
const gate = new Promise<void>(resolve => { release = resolve })
let requests = 0
await page.route("**/api/wireguard/export", async route => {
requests++
const body = route.request().postDataJSON()
expect(body.format).toBe("rsc")
if (body.serverId === "1") {
await gate
return oldFails ? route.fulfill({ status: 500, json: { error: "Старая ошибка экспорта" } }) : route.fulfill({ json: { format: "rsc", filename: "old.rsc", content: "OLD_EXPORT" } })
}
expect(body.serverId).toBe("2")
return route.fulfill({ json: { format: "rsc", filename: "new.rsc", content: "NEW_EXPORT" } })
})
const open = async (index: number) => {
await page.getByRole("button", { name: "Действия: wg-same" }).nth(index).click()
await page.getByRole("menuitem", { name: "Экспорт", exact: true }).click()
}
await expect(page.locator("tr[data-row-id]")).toHaveCount(4)
await open(0)
const dialog = page.getByRole("dialog", { name: "Экспорт WireGuard" })
await dialog.getByRole("button", { name: "Подтянуть конфиг с роутера с private-key", exact: true }).evaluate(button => { (button as HTMLButtonElement).click(); (button as HTMLButtonElement).click() })
await expect.poll(() => requests).toBe(1)
await expect(dialog.getByRole("button", { name: "Подтянуть конфиг с роутера с private-key", exact: true })).toBeDisabled()
await page.keyboard.press("Escape")
await expect(dialog).toHaveCount(0)
await open(2)
await expect(dialog).toContainText("Второй сервер")
await dialog.getByRole("button", { name: "Подтянуть конфиг с роутера с private-key", exact: true }).click()
await expect(dialog.locator("pre")).toContainText("NEW_EXPORT")
const oldResponse = page.waitForResponse(response => response.url().endsWith("/api/wireguard/export") && response.request().postDataJSON().serverId === "1")
release!()
await (await oldResponse).finished()
await page.waitForTimeout(150)
await expect(dialog.locator("pre")).toContainText("NEW_EXPORT")
await expect(page.getByText("Старая ошибка экспорта", { exact: true })).toHaveCount(0)
expect(requests).toBe(2)
})
}
test("WireGuard: экспорт отклоняет повреждённый ответ и другой формат", async ({ page }) => {
await setup(page, "/wireguard?server=1&interface=*%2F2")
let attempts = 0
await page.route("**/api/wireguard/export", route => {
attempts++
return route.fulfill({ json: attempts === 1 ? {} : attempts === 2 ? { format: "conf", filename: "wrong.conf", content: "WRONG_FORMAT" } : { format: "rsc", filename: "valid.rsc", content: "VALID_EXPORT" } })
})
await page.getByRole("button", { name: "Действия: wg-same" }).click()
await page.getByRole("menuitem", { name: "Экспорт", exact: true }).click()
const dialog = page.getByRole("dialog", { name: "Экспорт WireGuard" })
for (let i = 0; i < 2; i++) {
await dialog.getByRole("button", { name: "Подтянуть конфиг с роутера с private-key", exact: true }).click()
await expect.poll(() => attempts).toBe(i + 1)
await expect(page.getByText("Некорректный ответ экспорта WireGuard", { exact: true }).first()).toBeVisible()
await expect(dialog.getByRole("button", { name: "Подтянуть конфиг с роутера с private-key", exact: true })).toBeEnabled()
await expect(dialog.locator("pre")).not.toContainText("WRONG_FORMAT")
}
await dialog.getByRole("button", { name: "Подтянуть конфиг с роутера с private-key", exact: true }).click()
await expect(dialog.locator("pre")).toContainText("VALID_EXPORT")
})