Files
openobserve/tests/ui-testing/playwright-tests/utils/reauth-alpha1.js
T
Shrinath Rao a384dd5ddd test(e2e/alpha1): robustness — auth self-heal + service-graph wide window (#13622)
## Alpha1 e2e robustness — self-healing auth + service-graph window

Builds on **#13621** (re-auth self-heal). Both branches share the slug
`test/alpha1-e2e-robustness` is stacked on `test/alpha1-reauth-on-401`;
review/merge #13621 first (or merge this, which contains it).

Root-caused against alpha1 runs 30892800970 / 30900015839 / 30902942856
(each investigated live via Playwright MCP).

### 1. Auth self-heal (from #13621, included here)
Shared cloud session + per-org passcode are minted once and reused all
run; on long runs / org-contention they expire mid-run → `User not
authenticated` (UI) and `HTTP 401 Unauthorized` (API). Now:
`authedRequest` refreshes the passcode and retries on 401;
`navigateToBase` re-authenticates and resumes instead of throwing.
**Verified working** in run 30902942856 — the auth storm cleared
(Metrics/SDR/Streams recovered, zero `User not authenticated`), and
`[auth] Refreshed cloud passcode after 401` fired and recovered mid-run.

### 2. Service graph queries a wide window
All 9 `service-graph.spec.js` chart tests failed with
`service-graph-chart` "element(s) not found" **despite** `beforeAll`
confirming topology via API (25 nodes). **Reproduced live**: the
service-graph tab defaults to **Past 15 Minutes** and shows *"No service
graph data / 0 entities"* (no chart element) when the daemon-processed
topology sits outside that window. The tab **honours the `period` URL
param** (verified: label → "Past 6 Hours").
→ `navigateToServiceGraphUrl` now navigates with `period=6h`; added
`navigateToServiceGraphAndWaitForChart()` (poll + refresh, tolerates
daemon lag). Non-masking.

### Honest scope
- **Not included (can't validate locally / not test-code):**
- **Pipelines ×5** (`Explore`/`update-pipeline` 45s timeout) —
persistent across *every* run; pipeline/stream data unavailable.
Env/data, needs CI-side repro.
- **OTLP metrics ingestion 401** (a PromQL-prereq `beforeAll`) — a
node-`fetch` ingest path with no page context to re-fetch the passcode;
narrow, needs a small refactor to self-heal.
- Singles: `logoManagement` (@enterprise `_meta`), `shareLink` (known
race), `alerts-ui-operations:131` (#9484) — pre-existing flaky/env.
- Service-graph is **enterprise/feature-gated** (403 in my org), so its
fix is evidence-reasoned + validated at the URL-param level, but final
proof is the seeded CI run.
2026-08-04 13:14:04 +00:00

59 lines
2.6 KiB
JavaScript

const path = require('path');
const testLogger = require('./test-logger.js');
const { isCloudEnvironment, resetCloudConfigCache } = require('./cloud-auth.js');
// Reuse the proven Dex login / org-switch / passcode-fetch helpers from global setup.
const { performDexLogin, switchOrgViaDropdown, fetchCloudConfig } = require('./global-setup-alpha1.js');
const AUTH_FILE = path.join(__dirname, 'auth', 'user.json');
/**
* Mid-run recovery for Alpha1 (cloud) when the shared session/passcode has expired or been
* invalidated by another shard sharing the same org. Performs a fresh Dex login in the CURRENT
* browser context, re-selects ORGNAME, re-fetches the passcode, and persists the refreshed
* storageState + cloud-config so the rest of this worker's tests (and getAuthHeaders API calls)
* use the new credentials.
*
* NOTE: this navigates the page (a full login flow), so callers must treat it as a hard reset —
* it's meant to run at a test boundary (navigateToBase) or as a last-resort escalation after a
* cheaper passcode refresh has already failed.
*
* @param {import('@playwright/test').Page} page
* @returns {Promise<boolean>} true if re-authentication succeeded
*/
async function reauthenticateAlpha1(page) {
if (!isCloudEnvironment()) return false;
const baseUrl = (process.env.ZO_BASE_URL || '').replace(/\/$/, '');
const idx = (process.env.ALPHA1_USER_INDEX || '1').trim();
const email = (process.env[`ALPHA1_USER_EMAIL_${idx}`] || process.env.ALPHA1_USER_EMAIL || '').trim();
const password = (process.env.ALPHA1_USER_PASSWORD || '').trim();
if (!baseUrl || !email || !password) {
testLogger.warn('[reauth] Missing ZO_BASE_URL / ALPHA1 creds — cannot re-authenticate');
return false;
}
try {
testLogger.info(`[reauth] Session lost — re-authenticating Dex user ${idx} (${email})`);
await performDexLogin(page, baseUrl, email, password);
const targetOrg = process.env.ORGNAME;
if (targetOrg && targetOrg !== 'default') {
await switchOrgViaDropdown(page, targetOrg);
}
// Persist the refreshed session so later tests in this worker reuse it,
// and refresh the passcode used by getAuthHeaders() for API calls.
await page.context().storageState({ path: AUTH_FILE });
await fetchCloudConfig(page);
resetCloudConfigCache();
testLogger.info('[reauth] Re-authentication succeeded');
return true;
} catch (e) {
testLogger.error(`[reauth] Re-authentication failed: ${e.message}`);
return false;
}
}
module.exports = { reauthenticateAlpha1 };