Files
rust-discovery/deploy/browser/cloud_lifecycle_revoke.cjs
2026-11-13 17:01:14 +01:00

52 lines
4.4 KiB
JavaScript

// Real interactive dev/test UI; never direct revocation/approval API calls.
const fs = require('node:fs');
const path = require('node:path');
const { chromium } = require('../../web/node_modules/playwright');
const root = path.resolve(__dirname, '../..');
const assert = value => { if (!value) { const e = new Error('Lifecycle UI mismatch'); Error.captureStackTrace(e, assert); throw e; } };
function readPrivate(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 expected = readPrivate(path.resolve(process.argv[2]));
assert(expected.profile === 'dev/test' && expected.expected_principal === 'simulated-testprincipal-a');
const login = readPrivate(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, timezoneId: 'UTC' }); page.setDefaultTimeout(15000);
let revocations = 0; let approvals = 0;
page.on('request', r => { const p = new URL(r.url()).pathname; if (p.endsWith('/authorizations')) approvals++; if (p.endsWith('/revocation') && r.method() === 'POST') revocations++; });
await page.goto('https://localhost:18443/');
await page.getByLabel('Benutzername').fill(login.username); await page.getByLabel('Passwort', { exact: true }).fill(login.password);
const response = 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 response).json();
assert(session.testsimulation === true && session.approval_origin === 'dev_test_browser_simulation' && session.principal === expected.expected_principal && session.permissions.includes('devices:revoke'));
await page.getByRole('status').filter({ hasText: 'SIMULIERT' }).waitFor();
assert(await page.getByLabel('Mandant', { exact: true }).inputValue() === expected.tenant_id);
await page.getByRole('button', { name: expected.asset_id, exact: true }).click();
const article = page.locator('article').filter({ has: page.getByRole('heading', { name: 'Inventardetail ' + expected.asset_id, exact: true }) });
await article.locator('pre').waitFor(); const device = JSON.parse(await article.locator('pre').innerText());
assert(device.agent_id === expected.agent_id && device.asset_id === expected.asset_id && device.presence === 'online');
assert(device.capabilities.length === 2 && device.capabilities.includes('linux.base/1') && device.capabilities.includes('heartbeat/1'));
const control = article.locator('details').filter({ has: page.locator('summary').filter({ hasText: /^Geräteidentität widerrufen$/ }) });
await control.locator('summary').click();
await control.getByLabel('Grund für Geräteidentität widerrufen', { exact: true }).fill('Native passive Linux MVP lifecycle acceptance; revoke only this separate nonexecuting test identity');
const nonce = await control.locator('code').innerText();
await control.getByLabel('Bestätigungskennung eingeben', { exact: true }).fill(nonce);
await control.getByRole('checkbox', { name: 'Ich bestätige diese konkrete administrative Wirkung ausdrücklich.' }).check();
await control.getByRole('button', { name: 'Geräteidentität widerrufen · ausdrücklich ausführen', exact: true }).click();
await control.locator('pre').filter({ hasText: '"revoked": true' }).waitFor();
assert(revocations === 1 && approvals === 0);
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
} finally { await browser.close(); }
})().catch(error => {
const line = error.stack?.match(/cloud_lifecycle_revoke\.cjs:(\d+):\d+/)?.[1] || 'unknown';
console.log('CLOUD_LIFECYCLE_UI_INCOMPLETE:' + error.constructor.name + ':source_line=' + line); process.exitCode = 1;
});