Files
rust-discovery/deploy/browser/cloud_logs_read.cjs
T
2026-11-13 17:56:24 +01:00

47 lines
3.5 KiB
JavaScript

// Read only through actual UI clicks; inspect its normal HTTP response.
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert/strict');
const { chromium } = require('../../web/node_modules/playwright');
const root = path.resolve(__dirname, '../..');
function privateJson(file) {
const s = fs.lstatSync(file);
assert(s.isFile() && !s.isSymbolicLink() && s.uid === process.getuid() && (s.mode & 0o777) === 0o600 && s.size <= 1048576);
return JSON.parse(fs.readFileSync(file, 'utf8'));
}
(async () => {
const file = path.resolve(process.argv[2]); const expected = privateJson(file);
assert.equal(expected.profile, 'dev/test'); assert.equal(expected.case, 'query_logs');
const login = privateJson(path.join(root, 'credentials/server-browser-login.json'));
const browsers = path.join(root, 'web/node_modules/.cache/playwright-browsers');
const version = fs.readdirSync(browsers).find(x => /^chromium-/.test(x));
const executablePath = ['chrome-linux/chrome', 'chrome-linux64/chrome'].map(x => path.join(browsers, version, x)).find(x => fs.existsSync(x));
const browser = await chromium.launch({ headless: true, executablePath,
env: { ...process.env, HOME: path.join(root, 'web/node_modules/.cache/cloud-acceptance/home') } });
try {
const page = await browser.newPage({ ignoreHTTPSErrors: false });
await page.goto('https://localhost:18443/');
await page.getByLabel('Benutzername').fill(login.username);
await page.getByLabel('Passwort', { exact: true }).fill(login.password);
const sessionResponse = page.waitForResponse(r => new URL(r.url()).pathname === '/auth/session' && r.status() === 200);
await page.getByRole('button', { name: 'Anmelden', exact: true }).click();
const session = await (await sessionResponse).json();
assert(session.testsimulation === true && session.principal === 'simulated-testprincipal-a');
await page.getByRole('status').filter({ hasText: 'SIMULIERT' }).waitFor();
assert.equal(await page.getByLabel('Mandant', { exact: true }).inputValue(), expected.tenant_id);
await page.getByRole('button', { name: expected.operation_id, exact: true }).click();
const op = page.locator('section').filter({ has: page.getByRole('heading', { name: 'Antrag / Ausführung ' + expected.operation_id, exact: true }) });
const response = page.waitForResponse(r => new URL(r.url()).pathname === `/api/v1/tenants/${expected.tenant_id}/jobs/${expected.job_id}` && r.status() === 200);
await op.getByRole('button', { name: 'Job ' + expected.job_id + ' · succeeded', exact: true }).click();
const http = await (await response).json();
const detail = page.locator('article').filter({ has: page.getByRole('heading', { name: 'Job ' + expected.job_id, exact: true }) });
await detail.locator('pre').waitFor();
const rendered = JSON.parse(await detail.locator('pre').innerText());
assert.deepEqual(http, expected.result); assert.deepEqual(rendered, expected.result);
const observation = JSON.parse(Buffer.from(rendered.result.stdout).toString('utf8'));
assert.equal(observation.data.unit, 'rmm-mvp-test.service'); assert.equal(observation.data.json_lines.length, 4);
fs.writeFileSync(path.join(path.dirname(file), 'read-evidence.json'), JSON.stringify({ verified: true, http, rendered }), { mode: 0o600, flag: 'wx' });
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
} finally { await browser.close(); }
})().catch(error => { console.log('CLOUD_LOG_READ_INCOMPLETE:' + error.constructor.name); process.exitCode = 1; });