44 lines
3.1 KiB
TypeScript
44 lines
3.1 KiB
TypeScript
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)
|
|
})
|
|
}
|