fix(ui): блокировать операции Firewall после ошибки чтения
This commit is contained in:
1 parent
1e9889f892
commit
2e648dcf1c
6 files changed
+88
-19
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
|
||||
for (const failure of ["http", "invalid"] as const) {
|
||||
test(`Firewall: ${failure} блокирует кэш до завершения успешного повтора`, async ({ page }) => {
|
||||
const rule = { id: "r1", rosId: "*1", serverId: "1", serverName: "Роутер", family: "ip", table: "filter", chain: "forward", action: "accept", proto: "tcp", src: "", dst: "", port: "443", iface: "", comment: "Правило", enabled: true, hits: 1 }
|
||||
let failed = false, gated = false, writes = 0, started = false
|
||||
let release: (() => void) | undefined
|
||||
const gate = new Promise<void>(resolve => { release = resolve })
|
||||
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
|
||||
await page.route("**/api/**", async r => {
|
||||
const p = new URL(r.request().url()).pathname
|
||||
if (r.request().method() !== "GET") { writes++; return r.fulfill({ json: { ok: true } }) }
|
||||
if (p === "/api/firewall/all") {
|
||||
if (gated) { started = true; await gate }
|
||||
if (failed) return r.fulfill(failure === "http" ? { status: 503, json: { error: "Чтение недоступно stale" } } : { json: { rules: "invalid", addressLists: [] } })
|
||||
return r.fulfill({ json: { rules: [rule], addressLists: [] } })
|
||||
}
|
||||
return r.fulfill({ json: p === "/api/auth/config" ? { required: false } : p === "/api/servers" ? [{ id: 1, name: "Роутер", host: "192.0.2.1", type: "exit-node", enabled: true, country: "RU", status: "online" }] : {} })
|
||||
})
|
||||
await page.goto("/firewall?server=1")
|
||||
const rows = page.locator("tr[data-row-id]")
|
||||
const toggle = rows.getByRole("switch", { name: "Включено правило *1", exact: true })
|
||||
const history = page.getByRole("button", { name: "История", exact: true })
|
||||
await expect(toggle).toBeEnabled(); await expect(history).toBeEnabled()
|
||||
failed = true
|
||||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||||
const status = page.getByRole("status").filter({ hasText: "Изменения Firewall заблокированы" })
|
||||
await expect(status).toBeVisible(); await expect(rows).toHaveCount(1)
|
||||
await expect(toggle).toBeDisabled(); await expect(history).toBeDisabled()
|
||||
await expect(page.getByRole("button", { name: "Новое правило", exact: true })).toBeDisabled()
|
||||
await rows.getByRole("button", { name: "Действия: forward accept", exact: true }).click()
|
||||
for (const name of ["Редактировать", "Отключить", "Удалить правило"]) await expect(page.getByRole("menuitem", { name, exact: true })).toBeDisabled()
|
||||
await page.keyboard.press("Escape")
|
||||
failed = false; gated = true
|
||||
await page.getByRole("button", { name: "Обновить", exact: true }).click()
|
||||
await expect.poll(() => started).toBe(true)
|
||||
await expect(status).toBeVisible(); await expect(toggle).toBeDisabled(); await expect(history).toBeDisabled()
|
||||
expect(writes).toBe(0)
|
||||
release!()
|
||||
await expect(status).toHaveCount(0); await expect(toggle).toBeEnabled(); await expect(history).toBeEnabled()
|
||||
await expect(rows).toHaveCount(1); expect(writes).toBe(0)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user