Files
openobserve/tests/ui-testing/playwright-tests/utils/cloud-auth.js
T
befa1883a0 test: add alpha1 cloud compatibility for E2E logs tests (#10763)
## Summary
- Add cloud auth infrastructure (`cloud-env.js`, `cloud-auth.js`) for
cloud/self-hosted switching
- Centralize ingestion auth via `getAuthHeaders()` across all ingestion
utilities (data, trace, service-graph, metrics)
- Refactor `commonActions.js` from `exec(curl)` to `page.request.post()`
for cloud cookie compatibility
- Enhance `cloudLoginPage.js` + `page-manager.js` for conditional cloud
page objects
- Update `global-setup-alpha1.js` to fetch org identifier and passcode
from cloud session
- Fix `global-teardown.js` race condition with proper error handling
- Replace `console.log` with `testLogger` in `commonActions.js`,
`ingest-service-graph.spec.js`, `scripts/ingest-service-graph.js`
- Replace raw selectors with POM methods (`applyQueryButton`, VRL
editor, pagination, time range)
- Add missing test tags to `searchpartition`, `unflattened`,
`ingest-service-graph` specs
- Fix `networkidle` → `domcontentloaded` across multiple spec files

## Companion PR
- Enterprise: sets `IS_CLOUD=true` in alpha1 E2E workflow

## Test plan
- [ ] Self-hosted E2E tests pass (no behavioral changes — only routing
through POM + testLogger)
- [ ] Alpha1 cloud E2E tests pass with cloud auth enabled
- [ ] Verify no credential leaks in logs (passcode/password values never
logged)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Shrinath Rao <undefined@users.noreply.github.com>
2026-03-07 07:00:07 +05:30

75 lines
2.5 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const { isCloudEnvironment } = require('../../pages/cloudPages/cloud-env.js');
let _cloudConfig = null;
/**
* Reads and caches the cloud config written by global-setup-alpha1.js.
* Contains: orgIdentifier, orgName, userEmail, passcode
*/
function getCloudConfig() {
if (_cloudConfig) return _cloudConfig;
const configFile = path.join(__dirname, 'auth', 'cloud-config.json');
try {
if (fs.existsSync(configFile)) {
_cloudConfig = JSON.parse(fs.readFileSync(configFile, 'utf-8'));
}
} catch (e) {
// Config not available — will fall back to env vars
}
return _cloudConfig;
}
/**
* Returns auth headers appropriate for the current environment.
* - Cloud: Basic Auth with email:passcode (fetched during global setup)
* - Self-hosted: Basic Auth with email:password (from env vars)
*/
function getAuthHeaders() {
if (isCloudEnvironment()) {
const config = getCloudConfig();
if (config && config.passcode) {
const basicAuthCredentials = Buffer.from(
`${config.userEmail}:${config.passcode}`
).toString('base64');
return {
'Authorization': `Basic ${basicAuthCredentials}`,
'Content-Type': 'application/json',
};
}
// Fallback: no passcode available, try without auth (cookies may work for some endpoints)
const testLogger = require('./test-logger.js');
testLogger.warn('Cloud environment active but no passcode found in cloud-config.json — ingestion calls may fail with 401');
return {
'Content-Type': 'application/json',
};
}
const basicAuthCredentials = Buffer.from(
`${process.env['ZO_ROOT_USER_EMAIL']}:${process.env['ZO_ROOT_USER_PASSWORD']}`
).toString('base64');
return {
'Authorization': `Basic ${basicAuthCredentials}`,
'Content-Type': 'application/json',
};
}
/**
* Returns the correct org identifier for the current environment.
* - Cloud: from cloud-config.json (fetched during global setup)
* - Self-hosted: from ORGNAME env var
*/
function getOrgIdentifier() {
if (isCloudEnvironment()) {
const config = getCloudConfig();
if (config && config.orgIdentifier) {
return config.orgIdentifier;
}
}
return process.env['ORGNAME'];
}
module.exports = { getAuthHeaders, isCloudEnvironment, getCloudConfig, getOrgIdentifier };