35 lines
2.6 KiB
TypeScript
35 lines
2.6 KiB
TypeScript
import { test, expect } from "@playwright/test"
|
|
for (const disable of [false, true]) {
|
|
test(`GRE: PSK ${disable ? "очищается" : "изменяется"} через поддерживаемый API`, async ({ page }) => {
|
|
let writes = 0
|
|
const tunnel = { id: "*1", serverId: "1", name: "gre-psk", localAddress: "192.0.2.1", remoteAddress: "192.0.2.2", localInnerIp: "10.0.0.1/30", remoteInnerIp: "10.0.0.2/30", poolId: "live", ipsec: { secret: "original-secret" }, mtu: 1476, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: false, comment: "", enabled: true, status: "up" }
|
|
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
|
|
await page.route("**/api/**", r => {
|
|
const path = new URL(r.request().url()).pathname
|
|
if (r.request().method() === "PATCH") {
|
|
writes++
|
|
expect(r.request().postDataJSON()).toMatchObject({ serverId: "1", rosId: "*1", name: "gre-psk", ipsecSecret: disable ? "" : "updated-secret" })
|
|
for (const key of ["ipsecIkeVersion", "ipsecEncAlg", "ipsecAuthAlg", "ipsecDhGroup", "ipsecLifetime", "ipsecPfs"]) expect(r.request().postDataJSON()).not.toHaveProperty(key)
|
|
return r.fulfill({ json: { ok: true } })
|
|
}
|
|
return r.fulfill({ json: path === "/api/gre/tunnels" ? { tunnels: [tunnel] } : path === "/api/servers" ? [{ id: 1, name: "Роутер", host: "192.0.2.1", enabled: true, country: "RU" }] : path === "/api/auth/config" ? { required: false } : {} })
|
|
})
|
|
await page.goto("/gre")
|
|
await page.getByRole("button", { name: "Действия: gre-psk" }).click()
|
|
await page.getByRole("menuitem", { name: "Редактировать", exact: true }).click()
|
|
const dialog = page.getByRole("dialog")
|
|
await expect(dialog.getByLabel("Пароль (PSK)")).toHaveValue("original-secret")
|
|
await expect(dialog).toContainText("эта форма их не изменяет")
|
|
for (const label of ["IKE-версия", "Шифрование", "Хеш-алгоритм", "DH-группа", "Срок жизни SA"]) await expect(dialog.getByText(label, { exact: true })).toHaveCount(0)
|
|
if (disable) await dialog.getByRole("switch", { name: "Включить IPsec", exact: true }).click()
|
|
else {
|
|
await dialog.getByRole("button", { name: "Показать PSK" }).click()
|
|
await expect(dialog.getByLabel("Пароль (PSK)")).toHaveAttribute("type", "text")
|
|
await dialog.getByLabel("Пароль (PSK)").fill("updated-secret")
|
|
}
|
|
await dialog.getByRole("button", { name: "Сохранить", exact: true }).click()
|
|
await expect(dialog).toHaveCount(0)
|
|
expect(writes).toBe(1)
|
|
})
|
|
}
|