fix(ui): подтверждать переключение интерфейсов WireGuard

This commit is contained in:
Denozordec committed 2026-09-29 08:33:10 +07:00
1 parent 8fff3d7fff
commit d3ae2598fb
6 files changed
+74 -8

No files matched your search

+37
View File
@@ -314,3 +314,40 @@ for (const kind of ["interface", "interface-dto", "peer"] as const) {
await expect(dialog).toHaveCount(0)
})
}
test("WireGuard: переключение ждёт подтверждения и защищено от повтора", async ({ page }) => {
await setup(page, "/wireguard?server=1&interface=*%2F2")
let attempts = 0
let release: (() => void) | undefined
const gate = new Promise<void>(resolve => { release = resolve })
await page.route("**/api/wireguard/interfaces/**", async route => {
expect(route.request().method()).toBe("PATCH")
expect(decodeURIComponent(new URL(route.request().url()).pathname)).toBe("/api/wireguard/interfaces/1/*/2")
expect(route.request().postDataJSON()).toEqual({ disabled: true })
attempts++
if (attempts === 1) {
await gate
return route.fulfill({ status: 403, json: { error: "Нет доступа к переключению" } })
}
return route.fulfill({ json: { ok: attempts > 2 } })
})
const menu = page.getByRole("button", { name: "Действия: wg-same" })
await menu.click()
await page.getByRole("menuitem", { name: "Отключить", exact: true }).click()
await expect.poll(() => attempts).toBe(1)
await expect(page.getByRole("status").filter({ hasText: "Изменение интерфейса wg-same · Источник" })).toBeVisible()
await menu.click()
await expect(page.getByRole("menuitem", { name: "Отключить", exact: true })).toBeDisabled()
await page.keyboard.press("Escape")
expect(attempts).toBe(1)
release!()
await expect(page.getByRole("alert").filter({ hasText: "wg-same · Источник: Нет доступа к переключению" })).toBeVisible()
await menu.click()
await page.getByRole("menuitem", { name: "Отключить", exact: true }).click()
await expect(page.getByRole("alert").filter({ hasText: "Сервер не подтвердил изменение интерфейса" })).toBeVisible()
await menu.click()
await page.getByRole("menuitem", { name: "Отключить", exact: true }).click()
await expect(page.getByText("Отключено", { exact: true })).toBeVisible()
await expect(page.getByRole("alert").filter({ hasText: "Сервер не подтвердил" })).toHaveCount(0)
expect(attempts).toBe(3)
})