Files
duplicati/playwright-tests/ngaxAuthRefresh.spec.ts
adnit 721c1c96fe fix(ngax): stop auth refresh infinite loop on terminal refresh failures
Treat auth refresh responses 400, 401, and 415 as terminal authentication failures
Clear stale auth state and refresh nonce, then immediately redirect to /login.html
Stop reconnect countdown/retry when terminal refresh failure is detected
Preserve normal retry behavior for transient failures such as 503
Add Playwright regression tests covering:
415 refresh failure redirects to login without runaway retries
503 refresh failure keeps retry behavior and does not force login redirect
2026-04-10 00:25:42 +02:00

48 lines
1.5 KiB
TypeScript

import { expect, test } from "@playwright/test";
const NGAX_URL = process.env.NGAX_URL || "http://localhost:8200/ngax/index.html";
test("ngax redirects to login on terminal refresh failures", async ({ page }) => {
let refreshCalls = 0;
await page.route("**/api/v1/auth/refresh", async (route) => {
refreshCalls++;
await route.fulfill({
status: 415,
contentType: "application/json",
body: JSON.stringify({ Error: "Unsupported Media Type" }),
});
});
await page.goto(NGAX_URL, { waitUntil: "domcontentloaded" });
// The app should immediately abandon refresh retries and go to login.
await page.waitForURL(/\/login\.html(\?.*)?$/, { timeout: 15000 });
// Give it a short window and ensure no runaway retry loop occurs.
await page.waitForTimeout(1500);
expect(refreshCalls).toBeLessThanOrEqual(3);
});
test("ngax keeps retry behavior for transient refresh failures", async ({ page }) => {
let refreshCalls = 0;
await page.route("**/api/v1/auth/refresh", async (route) => {
refreshCalls++;
await route.fulfill({
status: 503,
contentType: "application/json",
body: JSON.stringify({ Error: "Service Unavailable" }),
});
});
await page.goto(NGAX_URL, { waitUntil: "domcontentloaded" });
// For transient failures, the app should not force a login redirect.
await page.waitForTimeout(2500);
await expect(page).not.toHaveURL(/\/login\.html(\?.*)?$/);
// The reconnect flow should attempt refresh again rather than terminating.
expect(refreshCalls).toBeGreaterThanOrEqual(2);
});