fix(ui): проверять подтверждение импорта WireGuard
This commit is contained in:
1 parent
f980619046
commit
efc6da1249
6 files changed
+60
-5
No files matched your search
@@ -175,3 +175,35 @@ for (const kind of ["iface", "peer"] as const) {
|
||||
expect(attempts).toBe(3)
|
||||
})
|
||||
}
|
||||
|
||||
test("WireGuard: импорт сохраняет форму без подтверждения применения", async ({ page }) => {
|
||||
await setup(page, "/wireguard?server=1")
|
||||
let attempts = 0
|
||||
const preview = { format: "rsc", interface: { name: "wg-import-test" }, peers: [] }
|
||||
const content = "/interface wireguard add name=wg-import-test listen-port=13231"
|
||||
await page.route("**/api/wireguard/import", async route => {
|
||||
expect(route.request().postDataJSON()).toEqual({ serverId: "1", content, format: "auto", dryRun: false })
|
||||
attempts++
|
||||
if (attempts === 1) return route.fulfill({ status: 403, json: { error: "Нет доступа к импорту" } })
|
||||
if (attempts === 2) return route.fulfill({ json: { dryRun: true, preview } })
|
||||
if (attempts === 3) return route.fulfill({ json: { dryRun: false, preview } })
|
||||
if (attempts === 4) return route.fulfill({ json: {} })
|
||||
return route.fulfill({ json: { dryRun: false, preview, applied: { interfaceName: "wg-import-test", peersCreated: 0 } } })
|
||||
})
|
||||
await page.getByRole("button", { name: "Импорт", exact: true }).click()
|
||||
const dialog = page.getByRole("dialog", { name: "Импорт конфига WireGuard" })
|
||||
await dialog.locator("textarea").fill(content)
|
||||
for (const message of ["Нет доступа к импорту", "Сервер не подтвердил применение конфигурации", "Сервер не подтвердил применение конфигурации", "Некорректный ответ импорта WireGuard"]) {
|
||||
const before = attempts
|
||||
await dialog.getByRole("button", { name: "Применить на роутер" }).click()
|
||||
await expect.poll(() => attempts).toBe(before + 1)
|
||||
await expect(page.getByText(message, { exact: true }).first()).toBeVisible()
|
||||
await expect(dialog.locator("textarea")).toHaveValue(content)
|
||||
await expect(dialog.locator("select").first()).toHaveValue("1")
|
||||
await expect(dialog.getByRole("button", { name: "Применить на роутер" })).toBeEnabled()
|
||||
}
|
||||
await dialog.getByRole("button", { name: "Применить на роутер" }).click()
|
||||
await expect(dialog).toHaveCount(0)
|
||||
await expect(page.getByText("Импортировано: wg-import-test (+0 пиров)", { exact: true })).toBeVisible()
|
||||
expect(attempts).toBe(5)
|
||||
})
|
||||
Reference in new issue
Block a user