59 lines
4.0 KiB
TypeScript
59 lines
4.0 KiB
TypeScript
import { test, expect, type Page } from "@playwright/test"
|
|
import { keyedNetflowSettings } from "./fixtures/netflow-settings"
|
|
|
|
const installed = {
|
|
configured: true, reachable: true, interfaceUp: true, configMatches: false,
|
|
publicKey: "public-fixture", listenPort: 51821, addresses: ["10.255.254.1/24"],
|
|
peers: [{ publicKey: "router-fixture", allowedIps: ["10.255.254.2/32"], lastHandshakeAt: null, receivedBytes: 0, sentBytes: 0 }], error: null,
|
|
}
|
|
async function setup(page: Page) {
|
|
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
|
|
await page.route("**/api/**", route => {
|
|
const path = new URL(route.request().url()).pathname
|
|
if (path === "/api/auth/config") return route.fulfill({ json: { required: false } })
|
|
if (path === "/api/traffic/flow/settings") return route.fulfill({ json: keyedNetflowSettings })
|
|
if (path === "/api/traffic/flow/host-status") return route.fulfill({ json: installed })
|
|
return route.fulfill({ status: 503, json: { error: "outside agent fixture" } })
|
|
})
|
|
}
|
|
|
|
test("NetFlow agent: apply, handshake waiting and frozen installation fields", async ({ page }, testInfo) => {
|
|
await setup(page)
|
|
let applied = false, posts = 0
|
|
await page.route("**/api/traffic/flow/host-status", route => route.fulfill({ json: { ...installed, configMatches: applied } }))
|
|
await page.route("**/api/traffic/flow/host-reconcile", route => { applied = true; posts++; return route.fulfill({ json: { ok: true, hostStatus: { ...installed, configMatches: true } } }) })
|
|
await page.goto("/data-collection")
|
|
await expect(page.getByRole("textbox", { name: "UDP IPFIX", exact: true })).toBeDisabled()
|
|
await expect(page.getByRole("textbox", { name: "Collector IP", exact: true })).toBeDisabled()
|
|
await expect(page.getByText("Ожидание handshake", { exact: false })).toBeVisible()
|
|
await page.getByRole("button", { name: "Применить настройки хоста", exact: true }).click()
|
|
await expect(page.getByText("Настройки применены", { exact: true })).toBeVisible()
|
|
expect(posts).toBe(1)
|
|
const panel = page.getByRole("region", { name: "Настройки NetFlow", exact: true })
|
|
await expect(panel.getByText(/Последний пакет:.*Не получен/)).toBeVisible()
|
|
await panel.screenshot({ path: testInfo.outputPath("netflow-agent.png") })
|
|
})
|
|
|
|
test("NetFlow agent: apply conflict stays visible after status refresh", async ({ page }) => {
|
|
await setup(page)
|
|
let posts = 0
|
|
await page.route("**/api/traffic/flow/host-reconcile", route => { posts++; return route.fulfill({ status: 502, json: { error: "AllowedIPs пересекаются с другим пиром" } }) })
|
|
await page.goto("/data-collection")
|
|
await page.getByRole("button", { name: "Применить настройки хоста", exact: true }).click()
|
|
await expect(page.getByText("AllowedIPs пересекаются с другим пиром", { exact: true })).toBeVisible()
|
|
await page.getByRole("button", { name: "Обновить состояние хоста", exact: true }).click()
|
|
await expect(page.getByText("AllowedIPs пересекаются с другим пиром", { exact: true })).toBeVisible()
|
|
expect(posts).toBe(1)
|
|
})
|
|
|
|
test("NetFlow agent: unavailable status does not invent success or enable apply", async ({ page }) => {
|
|
await page.setViewportSize({ width: 375, height: 900 })
|
|
await setup(page)
|
|
await page.route("**/api/traffic/flow/host-status", route => route.fulfill({ json: { ...installed, reachable: false, interfaceUp: false, configMatches: null, peers: [], error: "Агент недоступен" } }))
|
|
await page.goto("/data-collection")
|
|
await expect(page.getByRole("button", { name: "Применить настройки хоста", exact: true })).toBeDisabled()
|
|
await expect(page.getByText("Настройки применены", { exact: true })).toHaveCount(0)
|
|
await expect(page.getByRole("textbox", { name: "UDP IPFIX", exact: true })).toHaveValue("4739")
|
|
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true)
|
|
})
|