// Actual UI only. No page.request, fetch injection, approval API or DB access. const fs = require('node:fs'); const path = require('node:path'); const crypto = require('node:crypto'); const { isDeepStrictEqual } = require('node:util'); const { chromium } = require('../../web/node_modules/playwright'); const root = path.resolve(__dirname, '../..'); const assert = (value) => { if (!value) throw new Error('UI contract mismatch'); }; function checkWindowsHello(job, planBytes) { const payload = job.payload; const action = { action: 'run_script', interpreter: 'powershell', script_utf8: "Write-Output 'Zeitprofil-Test'\r\n", arguments: [], expected_stdout: 'Zeitprofil-Test\r\n', windows_execution_profile: 'powershell_51_remote_signed', }; const stored = JSON.parse(Buffer.from(planBytes).toString('utf8')); assert(stored.jobs.length === 1 && isDeepStrictEqual(stored.jobs[0].payload, payload)); assert(payload.tenant_id === '11111111-1111-4111-8111-111111111111' && payload.agent_id === '63ea15b2-0643-403d-b5b4-cba1288dbea3' && payload.asset_id === 'a176520e-8a91-4e93-a78b-8e7620f430e0' && payload.execution_identity === 'agent_service' && isDeepStrictEqual(payload.action, action)); assert(stored.jobs[0].job_payload_hash === job.job_payload_hash && stored.jobs[0].script_sha256 === job.script_sha256 && crypto.createHash('sha256').update(action.script_utf8, 'utf8').digest('hex') === job.script_sha256); } (async () => { const file = path.resolve(process.argv[2]); const stat = fs.lstatSync(file); assert(stat.isFile() && !stat.isSymbolicLink() && stat.uid === process.getuid() && (stat.mode & 0o777) === 0o600); const expected = JSON.parse(fs.readFileSync(file, 'utf8')); assert(expected.profile === 'dev/test' && ['hello', 'refresh_inventory', 'cancel_queued', 'windows_hello'].includes(expected.case)); assert(expected.expected_principal === 'simulated-testprincipal-a'); const loginFile = path.join(root, 'credentials/server-browser-login.json'); const loginStat = fs.lstatSync(loginFile); assert(loginStat.isFile() && !loginStat.isSymbolicLink() && loginStat.uid === process.getuid() && (loginStat.mode & 0o777) === 0o600); const login = JSON.parse(fs.readFileSync(loginFile, 'utf8')); const cache = path.join(root, 'web/node_modules/.cache/cloud-acceptance'); const browserRoot = path.join(root, 'web/node_modules/.cache/playwright-browsers'); const version = fs.readdirSync(browserRoot).find(x => /^chromium-/.test(x)); const candidates = ['chrome-linux/chrome', 'chrome-linux64/chrome'].map(x => path.join(browserRoot, version, x)); const browser = await chromium.launch({ headless: true, executablePath: candidates.find(x => fs.existsSync(x)), env: { ...process.env, HOME: path.join(cache, '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.approval_origin === 'dev_test_browser_simulation' && session.principal === expected.expected_principal); await page.getByRole('status').filter({ hasText: 'SIMULIERT' }).waitFor(); 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 pending = JSON.parse(await op.locator('pre').first().innerText()); assert(pending.approval_state === 'pending_approval' && pending.job_count === 0 && pending.execution_state === null); await op.getByRole('button', { name: 'Unveränderlichen Plan zur Prüfung öffnen', exact: true }).click(); const detail = page.locator('section').filter({ has: page.getByRole('heading', { name: 'Unveränderlicher Plan / Genehmigungsdetail', exact: true }) }); const rendered = JSON.parse(await detail.getByLabel('Alle festen Zielpreviews, exakte Skriptinhalte/Hashes, Parameter, Rechte, Fristen, Rollout und Nachbedingungen', { exact: true }).innerText()); assert(rendered.plan_hash === expected.plan.plan_hash && crypto.createHash('sha256').update(Buffer.from(rendered.plan_payload_bytes)).digest('hex') === expected.plan.plan_hash); assert(JSON.stringify(rendered.plan_payload_bytes) === JSON.stringify(expected.plan.plan_payload_bytes)); assert(rendered.jobs.length === 1 && rendered.resolved_targets.length === 1); const job = rendered.jobs[0]; const payload = job.payload; assert(job.job_payload_hash === expected.job.job_payload_hash && JSON.stringify(payload) === JSON.stringify(expected.job.payload)); assert(payload.agent_id === expected.agent_id && payload.asset_id === expected.asset_id && payload.tenant_id === expected.tenant_id); assert(payload.execution_identity === 'agent_service' && payload.max_runtime_seconds === 60 && payload.max_output_bytes <= 65536); assert(Date.parse(payload.start_before) > Date.now()); if (expected.case === 'windows_hello') { checkWindowsHello(job, rendered.plan_payload_bytes); assert(expected.stage === 'pending_approval' && expected.preapproval.jobs === 0 && expected.preapproval.outbox === 0 && expected.preapproval.permits === 0); assert(pending.plan_id === rendered.plan_id && pending.operation_id === expected.operation_id); await detail.getByLabel('Feste PowerShell-Prozessprofile', { exact: true }) .getByText('Asset: ' + payload.asset_id + ' · Windows PowerShell5.1 · agent_service · RemoteSigned · nur Jobprozess', { exact: true }).waitFor(); } else if (expected.case === 'hello' || expected.case === 'cancel_queued') assert(payload.action.action === 'run_script' && payload.action.interpreter === 'posix_sh' && payload.action.script_utf8 === "printf '%s\\n' 'Hello World'\n" && payload.action.expected_stdout === 'Hello World\n'); else assert(payload.action.action === 'refresh_inventory' && payload.action.scope === 'linux.base'); const approve = detail.getByRole('button', { name: 'SIMULIERT: Diesen festen Plan ausdrücklich genehmigen', exact: true }); assert(await approve.isDisabled()); await detail.getByRole('checkbox', { name: 'Ich habe sämtliche festen Ziele', exact: false }).check(); await approve.click(); await op.locator('p.warning').filter({ hasText: 'Antrag: approved' }).waitFor(); await page.getByRole('button', { name: 'Abmelden', exact: true }).click(); } finally { await browser.close(); } })().catch(error => { console.log('CLOUD_UI_INCOMPLETE:' + error.constructor.name); process.exitCode = 1; });