fix(geoip): отклонять неполные ответы и проверять подтверждения операций
This commit is contained in:
1 parent
638c17caef
commit
1b51d2af01
8 files changed
+98
-26
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
import { geoip } from "./fixtures/geoip"
|
||||
for (const invalid of [true, false]) test("GeoIP: malformed reader не обрушает сбор данных/" + invalid, async ({ page }) => {
|
||||
const errors: string[] = []; page.on("pageerror", error => errors.push(error.message))
|
||||
await page.route("**/health", r => r.fulfill({ json: { ok: true } }))
|
||||
await page.route("**/api/**", r => {
|
||||
const path = new URL(r.request().url()).pathname
|
||||
if (path === "/api/auth/config") return r.fulfill({ json: { required: false } })
|
||||
if (path === "/api/geoip") return r.fulfill({ json: invalid ? {} : geoip })
|
||||
if (path === "/api/traffic/flow/settings") return r.fulfill({ status: 503, json: { error: "NetFlow outside fixture" } })
|
||||
if (path === "/api/scheduler/runs") return r.fulfill({ json: { runs: [] } })
|
||||
return r.fulfill({ json: { enabled: false, intervalSec: 300, retentionDays: 14, lastCollectedAt: null, lastDurationMs: null, lastError: null, scheduler: { jobs: [] } } })
|
||||
})
|
||||
await page.goto("/data-collection")
|
||||
await expect(page.getByText("Журнал прогонов", { exact: true })).toBeVisible()
|
||||
if (invalid) await expect(page.getByText("Данные GeoIP не подтверждены: получен некорректный ответ сервера", { exact: true }).first()).toBeVisible()
|
||||
else await expect(page.getByRole("button", { name: "Сохранить GeoIP", exact: true })).toBeVisible()
|
||||
expect(errors).toEqual([])
|
||||
})
|
||||
@@ -1,4 +1,5 @@
|
||||
import { test, expect } from "@playwright/test"
|
||||
import { geoip } from "./fixtures/geoip"
|
||||
const snapshot = { v: 1, job: "backups", sampledAt: "2026-10-01T00:00:00Z", due: true, created: 2, failures: 0, pruned: 1, errors: ["S3 upload unavailable"] }
|
||||
for (const representation of ["jsonb", "legacy", "invalid", "foreign"] as const) test("Сбор данных: snapshot/" + representation, async ({ page }) => {
|
||||
const pageErrors: string[] = []; page.on("pageerror", error => pageErrors.push(error.message))
|
||||
@@ -7,7 +8,7 @@ for (const representation of ["jsonb", "legacy", "invalid", "foreign"] as const)
|
||||
const path = new URL(r.request().url()).pathname
|
||||
if (path === "/api/traffic/flow/settings") return r.fulfill({ status: 503, json: { error: "NetFlow is outside this snapshot fixture" } })
|
||||
const settings = { enabled: false, intervalSec: 300, retentionDays: 14, lastCollectedAt: null, lastDurationMs: null, lastError: null, scheduler: { jobs: [] } }
|
||||
return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/geoip" ? { settings: { ...settings, updateIntervalSec: 604800 }, countryLoaded: false, asnLoaded: false, dir: "test" } : path === "/api/scheduler/runs" ? { runs: [{ id: "run-jsonb", jobKey: "backups", startedAt: snapshot.sampledAt, finishedAt: snapshot.sampledAt, status: "error", error: "Завершено с ограничениями", durationMs: 100, resultJson: representation === "legacy" ? JSON.stringify(snapshot) : representation === "invalid" ? { ...snapshot, created: undefined } : representation === "foreign" ? { v: 1, job: "traffic", sampledAt: snapshot.sampledAt, servers: [] } : snapshot }] } : settings })
|
||||
return r.fulfill({ json: path === "/api/auth/config" ? { required: false } : path === "/api/geoip" ? geoip : path === "/api/scheduler/runs" ? { runs: [{ id: "run-jsonb", jobKey: "backups", startedAt: snapshot.sampledAt, finishedAt: snapshot.sampledAt, status: "error", error: "Завершено с ограничениями", durationMs: 100, resultJson: representation === "legacy" ? JSON.stringify(snapshot) : representation === "invalid" ? { ...snapshot, created: undefined } : representation === "foreign" ? { v: 1, job: "traffic", sampledAt: snapshot.sampledAt, servers: [] } : snapshot }] } : settings })
|
||||
})
|
||||
await page.goto("/data-collection")
|
||||
await page.getByRole("button", { name: /Бэкапы.*100 мс/ }).click()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const geoip = { ready: false, countryLoaded: false, asnLoaded: false, countryFile: "country.mmdb", asnFile: "asn.mmdb", dir: "geoip", running: false, settings: { enabled: false, updateIntervalSec: 604800, lastCheckAt: null, lastSuccessAt: null, lastError: null, countryBuildAt: null, asnBuildAt: null, updatedAt: "2026-10-01T00:00:00Z" } }
|
||||
Reference in new issue
Block a user