fix(network): исправить keepalive GRE и каталог IPsec

This commit is contained in:
Denozordec committed 2026-10-13 21:15:49 +07:00
1 parent 3f3f06f147
commit 727e35f985
28 files changed
+1722 -37

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
import { test, expect } from "@playwright/test"
for (const kind of ["gre", "recursive"] as const) {
test(`Filters: каталог ${kind} с masked IPsec сохраняется при сбое и блокирует маршрут/копирование`, async ({ page }) => {
let phase = 0, writes = 0, catalogReads = 0
const tunnel = (id: string) => ({ id: "t" + id, serverId: id, name: "GRE-" + id, localAddress: "192.0.2." + id, remoteAddress: "198.51.100.1", localInnerIp: "10.0.0.1/30", remoteInnerIp: "10.0.0.2/30", poolId: "", ipsec: { secret: "" }, mtu: 1476, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: true, comment: "", enabled: true, status: "up" })
const rec = { id: "rec1", dstAddress: "10.0.0.2/32", gateway: "198.51.100.1", distance: 1, routingTable: "main", comment: "Рекурсивный шлюз", disabled: false }
const rule = { id: "rule-1", community: "65001:101", gateway: "10.0.0.2", gatewayTunnelId: kind === "gre" ? "t1" : "rec:rec1", action: "route", description: "Маршрут" }
await page.route("**/health", route => route.fulfill({ json: { ok: true } }))
await page.route("**/api/**", route => {
const url = new URL(route.request().url()), path = url.pathname, id = url.searchParams.get("serverId") ?? "1"
if (path === "/api/filters/rules" && route.request().method() === "PUT") { writes++; return route.fulfill({ json: { ok: true, rules: route.request().postDataJSON().rules } }) }
const catalog = kind === "gre" ? "/api/filters/gre-tunnels" : "/api/recursive-routes"
if (path === catalog) catalogReads++
if (path === catalog && phase === 1) return route.fulfill({ status: 503, json: { error: "Каталог недоступен тест" } })
if (path === catalog && phase === 2) return route.fulfill({ json: kind === "gre" ? { tunnels: [{ ...tunnel(id), name: null }] } : { routes: [rec], stale: true } })
return route.fulfill({ json: path === "/api/filters/rules" ? { rulesets: [{ serverId: "1", rules: [rule] }, { serverId: "2", rules: [] }], live: true, greTunnels: [] }
: path === "/api/servers" ? [1, 2].map(i => ({ id: i, name: "Роутер " + i, host: "192.0.2." + i, type: "exit-node", enabled: true, country: "RU", site: "TEST", asn: "", status: "online", latency: 1 }))
: path === "/api/filters/gre-tunnels" ? { tunnels: kind === "gre" && phase !== 3 ? [tunnel(id)] : [] }
: path === "/api/recursive-routes" ? { routes: kind === "recursive" && phase !== 3 ? [rec] : [], stale: false }
: path === "/api/auth/config" ? { required: false } : {} })
})
await page.goto("/filters")
const row = page.locator("tr[data-row-id]").first()
await expect(row).toContainText(kind === "gre" ? "GRE-1" : rec.dstAddress)
phase = 1
await page.getByRole("button", { name: "Обновить", exact: true }).click()
await expect(page.getByRole("alert").filter({ hasText: "Каталог недоступен тест" })).toBeVisible()
await expect(row).toContainText(kind === "gre" ? "GRE-1" : rec.dstAddress)
await row.hover()
await row.getByRole("button", { name: "Редактировать правило", exact: true }).click()
const dialog = page.getByRole("dialog")
await dialog.getByRole("textbox", { name: "Описание правила" }).fill("Сохранить маршрут")
await dialog.getByRole("button", { name: "Сохранить", exact: true }).click()
await expect(dialog.getByRole("alert")).toContainText("Шлюзы устройства не подтверждены")
expect(writes).toBe(0)
await dialog.getByRole("button", { name: "Отмена", exact: true }).click()
await page.getByRole("button", { name: "Копировать", exact: true }).click()
await dialog.getByRole("button", { name: /Роутер 2/ }).click()
const copy = dialog.getByRole("button", { name: "Копировать 1 правил", exact: true })
await expect(copy).toBeDisabled()
phase = 2
let priorReads = catalogReads
await dialog.getByRole("button", { name: "Обновить шлюзы", exact: true }).click()
await expect.poll(() => catalogReads).toBeGreaterThanOrEqual(priorReads + 2)
await expect(copy).toBeDisabled()
await expect(dialog.getByRole("alert")).toContainText("сопоставление шлюзов не подтверждены")
phase = 3
priorReads = catalogReads
await dialog.getByRole("button", { name: "Обновить шлюзы", exact: true }).click()
await expect.poll(() => catalogReads).toBeGreaterThanOrEqual(priorReads + 2)
await page.evaluate(() => new Promise<void>(resolve => requestAnimationFrame(() => resolve())))
await expect(copy).toBeDisabled()
phase = 4
await dialog.getByRole("button", { name: "Обновить шлюзы", exact: true }).click()
await expect(copy).toBeEnabled()
await expect(dialog.getByRole("alert")).toHaveCount(0)
await copy.click()
await expect(dialog).toHaveCount(0)
expect(writes).toBe(1)
})
}
+8
View File
@@ -0,0 +1,8 @@
import {test,expect} from '@playwright/test'
for(const width of [1440,320])test(`GRE: неверный keepalive сохраняет форму без запроса ${width}`,async({page})=>{
let writes=0;const tunnel={id:'*1',serverId:'1',name:'own210-gre',localAddress:'192.0.2.1',remoteAddress:'192.0.2.2',localInnerIp:'',remoteInnerIp:'',poolId:'live',ipsec:null,mtu:1476,keepaliveInterval:60,keepaliveRetries:3,dscp:'inherit',clampTcpMss:true,allowFastPath:false,comment:'own210',enabled:false,status:'down'}
await page.route('**/health',r=>r.fulfill({json:{ok:true}}));await page.route('**/api/**',r=>{if(r.request().method()!=='GET')writes++;const p=new URL(r.request().url()).pathname;return r.fulfill({json:p==='/api/auth/config'?{required:false}:p==='/api/servers'?[{id:1,name:'Own210 router',host:'192.0.2.1',enabled:true,country:'RU'}]:p==='/api/gre/tunnels'?{tunnels:[tunnel]}:{}})})
await page.setViewportSize({width,height:1000});await page.goto('/gre?server=1');await page.getByRole('button',{name:'Действия: own210-gre',exact:true}).click();await page.getByRole('menuitem',{name:'Редактировать',exact:true}).click();const form=page.getByRole('dialog');await form.getByRole('button',{name:'Дополнительно',exact:true}).click();await expect(form.getByLabel('Keepalive, с')).toHaveValue('60');await expect(form).not.toContainText('0 = откл.');await form.getByLabel('Комментарий').fill('сохранённый ввод');
for(const field of ['Keepalive, с','Попытки']){await form.getByLabel(field).fill('0');await form.getByRole('button',{name:'Сохранить',exact:true}).click();await expect(form.getByRole('alert')).toContainText('целые значения от 1');await expect(form.getByLabel('Комментарий')).toHaveValue('сохранённый ввод');await form.getByLabel(field).fill(field==='Попытки'?'3':'60')}
expect(writes).toBe(0);expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1)).toBe(true)
})