feat: snapshot Linux-first RMM MVP and pause handover
Rust development slice / linux (push) Failing after 1m10s

This commit is contained in:
BuTzZ
2026-11-12 22:06:25 +01:00
commit 6c3203d725
194 changed files with 49234 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
import { test, expect } from '../../web/node_modules/@playwright/test/index.js';
import { readFileSync, statSync } from 'node:fs';
test('dev/test browser simulation: login → fixed plan → pending → explicit click → result', async ({ page }) => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'execute', 'Explicit dev/test execution opt-in required; never run against production');
const file = process.env.RMM_E2E_LOGIN_FILE;
if (!file) throw new Error('Protected login JSON file required');
const stat = statSync(file);
if (!stat.isFile() || (stat.mode & 0o777) !== 0o600 || stat.uid !== process.getuid?.()) throw new Error('Login file must be owned by current user, mode 0600');
const value: unknown = JSON.parse(readFileSync(file, 'utf8'));
if (!value || typeof value !== 'object' || !('username' in value) || !('password' in value) || typeof value.username !== 'string' || typeof value.password !== 'string') throw new Error('Invalid login file');
const asset = process.env.RMM_E2E_ASSET_ID;
if (!asset) throw new Error('Explicit approved test asset required');
// No APIRequestContext, direct approval request, storageState, screenshots or traces.
await page.goto('/');
await page.getByLabel('Benutzername').fill(value.username);
await page.getByLabel('Passwort', { exact: true }).fill(value.password);
await page.getByRole('button', { name: 'Anmelden', exact: true }).click();
await expect(page.getByRole('status')).toContainText('SIMULIERT');
await expect(page.getByRole('status')).toContainText('kein menschlicher Produktions-Freigabenachweis');
await page.getByRole('checkbox', { name: `Ziel ${asset}`, exact: true }).check();
await page.getByLabel('Exakte UTF-8 Skriptbytes', { exact: false }).fill("printf '%s\\n' 'Hello World'\n");
await page.getByLabel('Erwartete stdout-Ausgabe', { exact: false }).fill('Hello World\n');
await page.getByLabel('Begründung', { exact: true }).fill('Dev/test browser simulation · Hello World');
await page.getByRole('button', { name: 'Plan erstellen · noch keine Ausführung' }).click();
const approve = page.getByRole('button', { name: 'SIMULIERT: Diesen festen Plan ausdrücklich genehmigen' });
await expect(approve).toBeDisabled();
await page.getByRole('button', { name: 'Antrag absenden · pending_approval' }).click();
await expect(page.getByText('Antrag: pending_approval', { exact: false })).toBeVisible();
await page.getByRole('checkbox', { name: 'Ich habe sämtliche festen Ziele', exact: false }).check();
await expect(approve).toBeEnabled();
await approve.click(); // The only approval path: visible, interactive UI action.
await expect(page.getByText('Antrag: approved', { exact: false })).toBeVisible();
await expect(page.getByText('Ausführung: succeeded', { exact: false })).toBeVisible({ timeout: 90000 });
await page.getByRole('button', { name: /^Job / }).first().click();
await expect(page.getByRole('heading', { name: /^Job / })).toBeVisible();
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
});
+7
View File
@@ -0,0 +1,7 @@
export const diagnosticSteps = ['management:login-banner', 'management:catalog-response', 'management:catalog-heading', 'management:membership-heading', 'management:unknown-stop', 'management:action-option', 'management:select-native', 'management:native-hint', 'management:identity-unchanged', 'management:inert-controls', 'management:logout'] as const;
export function diagnostic(label: string, error: { name?: string; message?: string } | undefined, line: number | undefined): string | null {
if (!error || !diagnosticSteps.some(step => step === label)) return null;
const name = ['Error', 'TimeoutError', 'TypeError', 'AssertionError', 'TestTimeoutError'].includes(error.name ?? '') ? error.name : 'Error';
const kind = /Timeout|timed out|timeout/i.test(error.message ?? '') ? 'timeout' : /expect\(|Assertion/i.test(error.message ?? '') ? 'assertion' : 'exception';
return `failure_step=${label} exception=${name} kind=${kind} source_line=${Number.isSafeInteger(line) && Number(line) > 0 ? line : 'unknown'}`;
}
+23
View File
@@ -0,0 +1,23 @@
import type { Page } from '../../web/node_modules/@playwright/test/index.js';
import { expect } from '../../web/node_modules/@playwright/test/index.js';
import { readFileSync, statSync } from 'node:fs';
export function loginData(): { username: string; password: string } {
if (process.env.RMM_E2E_PROFILE !== 'dev/test') throw new Error('Explicit dev/test profile required');
const file = process.env.RMM_E2E_LOGIN_FILE;
if (!file) throw new Error('Protected login JSON file required');
const stat = statSync(file);
if (!stat.isFile() || (stat.mode & 0o777) !== 0o600 || stat.uid !== process.getuid?.()) throw new Error('Login file must be owned by current user, mode 0600');
const value: unknown = JSON.parse(readFileSync(file, 'utf8'));
if (!value || typeof value !== 'object' || !('username' in value) || !('password' in value) || typeof value.username !== 'string' || typeof value.password !== 'string') throw new Error('Invalid login file');
return { username: value.username, password: value.password };
}
export async function login(page: Page) {
const value = loginData();
await page.goto('/');
await page.getByLabel('Benutzername').fill(value.username);
await page.getByLabel('Passwort', { exact: true }).fill(value.password);
await page.getByRole('button', { name: 'Anmelden', exact: true }).click();
await expect(page.getByRole('status')).toContainText('SIMULIERT');
await expect(page.getByRole('status')).toContainText('kein menschlicher Produktions-Freigabenachweis');
}
+22
View File
@@ -0,0 +1,22 @@
import { test, expect } from '../../web/node_modules/@playwright/test/index.js';
import { login } from './helpers';
test('real TLS login follows announced configuration and restores session without invented simulation identity', async ({ page }) => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'management-read');
const configResponse = page.waitForResponse(r => new URL(r.url()).pathname === '/auth/config');
await page.goto('/');
const response = await configResponse; expect(response.status()).toBe(200);
const config: unknown = await response.json();
if (!config || typeof config !== 'object' || !('oidc_configured' in config) || !('dev_login_enabled' in config) || !('oidc_login_url' in config)) throw new Error('Auth configuration schema missing');
expect(typeof config.oidc_configured).toBe('boolean'); expect(typeof config.dev_login_enabled).toBe('boolean');
if (config.oidc_configured) {
expect(config.oidc_login_url).toBe('/auth/oidc/login'); await expect(page.getByRole('link', { name: 'Mit SSO anmelden', exact: true })).toHaveAttribute('href', '/auth/oidc/login');
} else {
expect(config.oidc_login_url).toBeNull(); await expect(page.getByText('OIDC: not_configured', { exact: false })).toBeVisible(); await expect(page.getByRole('link', { name: 'Mit SSO anmelden', exact: true })).toHaveCount(0);
}
if (!config.dev_login_enabled) { await expect(page.locator('input[type="password"]')).toHaveCount(0); return; }
await expect(page.getByText('DEV/TEST · SIMULIERTER TESTPRINCIPAL', { exact: false })).toBeVisible();
await login(page); await page.reload(); await expect(page.getByRole('status')).toContainText('SIMULIERT');
await expect(page.getByRole('heading', { name: 'Mitgliedschaft und Ausführungsstopp' })).toBeVisible();
await page.getByRole('button', { name: 'Abmelden', exact: true }).click(); await expect(page.getByRole('button', { name: 'Anmelden', exact: true })).toBeVisible();
});
+20
View File
@@ -0,0 +1,20 @@
import { test, expect } from '../../web/node_modules/@playwright/test/index.js';
import { login } from './helpers';
test('real dev browser membership/catalog read and administrative controls stay inert', async ({ page }) => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'management-read');
let mutations = 0;
page.on('request', r => { if (r.method() === 'POST' && !['/auth/dev/login', '/auth/logout'].includes(new URL(r.url()).pathname)) mutations++; });
const catalog = page.waitForResponse(r => new URL(r.url()).pathname.endsWith('/package-recipes'));
await test.step('management:login-banner', async () => { await login(page); await expect(page.getByRole('status')).toContainText('SIMULIERT'); });
await test.step('management:catalog-response', async () => { expect((await catalog).status()).toBe(200); });
await test.step('management:catalog-heading', async () => { await expect(page.getByRole('heading', { name: 'Unveränderlicher Paketkatalog und Artefakte' })).toBeVisible(); });
await test.step('management:membership-heading', async () => { await expect(page.getByRole('heading', { name: 'Mitgliedschaft und Ausführungsstopp' })).toBeVisible(); });
await test.step('management:unknown-stop', async () => { await expect(page.getByText('unknown — kein lesender Stopstatus-Endpunkt angekündigt', { exact: false })).toBeVisible(); });
await test.step('management:action-option', async () => { await expect(page.getByLabel('Aktion', { exact: true }).locator('option[value="apt_native_acceptance"]')).toHaveCount(1); });
await test.step('management:select-native', async () => { await page.getByLabel('Aktion', { exact: true }).selectOption('apt_native_acceptance'); });
await test.step('management:native-hint', async () => { await expect(page.getByText('NUR SIMULIERTE DEV/TEST-NATIVABNAHME.', { exact: false })).toBeVisible(); });
await test.step('management:identity-unchanged', async () => { await expect(page.getByLabel('Ausführungsidentität', { exact: true })).toHaveValue('agent_service'); });
await test.step('management:inert-controls', async () => { expect(mutations).toBe(0); });
await test.step('management:logout', async () => { await page.getByRole('button', { name: 'Abmelden', exact: true }).click(); await expect(page.getByRole('button', { name: 'Anmelden', exact: true })).toBeVisible(); });
});
+182
View File
@@ -0,0 +1,182 @@
import { test, expect } from '../../web/node_modules/@playwright/test/index.js';
import { readFileSync, lstatSync, writeFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { createHash } from 'node:crypto';
import { login } from './helpers';
function object(value: unknown): Record<string, unknown> {
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Object required');
return value as Record<string, unknown>;
}
function bytes(value: unknown): Buffer {
if (!Array.isArray(value) || !value.every(n => Number.isInteger(n) && n >= 0 && n <= 255)) throw new Error('Exact byte array required');
return Buffer.from(value);
}
function text(value: unknown): string { if (typeof value !== 'string' || !value) throw new Error('Text required'); return value; }
test('simulated human prepares root request through UI only, without approving', async ({ page }) => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'mvp-prepare');
const file = process.env.RMM_E2E_CASE_FILE;
if (!file) throw new Error('Protected root preparation file required');
const metadata = lstatSync(file);
if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.uid !== process.getuid?.() || (metadata.mode & 0o777) !== 0o600 || metadata.size > 1048576) throw new Error('Unsafe root preparation file');
const expected = object(JSON.parse(readFileSync(file, 'utf8')));
expect(expected.phase).toBe('prepare'); expect(expected.profile).toBe('dev/test');
expect(expected.expected_principal).toBe('simulated-testprincipal-a');
const request = object(expected.request), params = object(request.parameters);
expect(params.execution_identity).toBe('root');
expect(object(request.targets).asset_ids).toEqual([expected.asset_id]);
expect(['run_script', 'set_service_state', 'apt_native_acceptance', 'ensure_package', 'apply_updates', 'reboot']).toContain(request.action);
let authorizationRequests = 0;
page.on('request', r => { if (new URL(r.url()).pathname.endsWith('/authorizations')) authorizationRequests++; });
const sessionResponse = page.waitForResponse(r => new URL(r.url()).pathname === '/auth/session' && r.status() === 200);
await login(page);
const session = object(await (await sessionResponse).json());
expect(session.testsimulation).toBe(true); expect(session.principal).toBe(expected.expected_principal);
expect(session.approval_origin).toBe('dev_test_browser_simulation');
await expect(page.getByLabel('Mandant', { exact: true })).toHaveValue(text(expected.tenant_id));
await page.getByRole('checkbox', { name: `Ziel ${text(expected.asset_id)}`, exact: true }).check();
await page.getByLabel('Aktion', { exact: true }).selectOption(text(request.action));
if (request.action === 'run_script') {
const variants = params.variants;
if (!Array.isArray(variants) || variants.length !== 1) throw new Error('One exact script variant required');
const variant = object(variants[0]);
await page.getByLabel('Interpreter', { exact: true }).selectOption(text(variant.interpreter));
await page.getByLabel('Exakte UTF-8 Skriptbytes', { exact: false }).fill(text(variant.script_utf8));
await page.getByLabel('Erwartete stdout-Ausgabe', { exact: false }).fill(text(params.expected_stdout));
} else {
await page.getByLabel('Aktionsparameter', { exact: true }).fill(JSON.stringify(params));
}
await page.getByLabel('Ausführungsidentität', { exact: true }).selectOption('root');
await page.getByLabel('Laufzeitlimit (s)', { exact: true }).fill(String(params.timeout_seconds));
await page.getByLabel('Ausgabelimit (Bytes)', { exact: true }).fill(String(params.max_output_bytes));
// Runner fixes browser/Node TZ to UTC. The actual UI's minute-precision form
// selects an explicit future minute; all resulting exact bytes are reviewed
// again in the separate approval test before any executable job can exist.
const start = new Date(Math.ceil(Date.now() / 60000) * 60000);
await page.getByLabel('Frühester Start (lokale Zeit)', { exact: true }).fill(start.toISOString().slice(0, 16));
await page.getByLabel('Startfrist / Ablauf (lokale Zeit)', { exact: true }).fill(new Date(start.getTime() + 15 * 60000).toISOString().slice(0, 16));
await page.getByLabel('Maximal parallel', { exact: true }).fill('1');
await page.getByLabel('Stopp nach Fehlern', { exact: true }).fill('1');
await page.getByLabel('Begründung', { exact: true }).fill(text(request.reason));
await page.getByRole('button', { name: 'Plan erstellen · noch keine Ausführung' }).click();
const detail = page.locator('section').filter({ has: page.getByRole('heading', { name: 'Unveränderlicher Plan / Genehmigungsdetail', exact: true }) });
await expect(detail.locator('pre')).toBeVisible();
const plan = object(JSON.parse(await detail.locator('pre').innerText()));
expect(createHash('sha256').update(bytes(plan.plan_payload_bytes)).digest('hex')).toBe(plan.plan_hash);
await detail.getByRole('button', { name: 'Antrag absenden · pending_approval' }).click();
const op = page.locator('section').filter({ has: page.getByRole('heading', { name: /^Antrag \/ Ausführung / }) });
await expect(op.locator('pre').first()).toContainText('"job_count": 0');
const operation = object(JSON.parse(await op.locator('pre').first().innerText()));
expect(operation.approval_state).toBe('pending_approval'); expect(operation.execution_state).toBeNull();
expect(authorizationRequests).toBe(0);
const output = resolve(text(expected.output_file));
if (dirname(output) !== dirname(resolve(file))) throw new Error('Private same-directory output required');
writeFileSync(output, JSON.stringify({ plan, operation }), { mode: 0o600, flag: 'wx' });
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
});
test('one opted-in immutable dev/test action: inspect all fixed bytes → UI click only', async ({ page }) => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'mvp-actions', 'Explicit dev/test simulation only');
const file = process.env.RMM_E2E_CASE_FILE;
if (!file) throw new Error('Protected expected case file required');
const metadata = lstatSync(file);
if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.uid !== process.getuid?.() || (metadata.mode & 0o777) !== 0o600 || metadata.size > 1048576) throw new Error('Unsafe expected case file');
const expected = object(JSON.parse(readFileSync(file, 'utf8')));
expect(expected.profile).toBe('dev/test');
expect(expected.expected_principal).toBe('simulated-testprincipal-a');
expect(['hello', 'refresh_inventory', 'query_logs', 'service_setup', 'service_start', 'service_stop',
'apt_native_install', 'apt_native_update', 'ensure_package', 'apply_updates', 'cancel_queued', 'expired_offline', 'reboot_last']).toContain(expected.case);
const sessionResponse = page.waitForResponse(r => new URL(r.url()).pathname === '/auth/session' && r.status() === 200);
await login(page);
const session = object(await (await sessionResponse).json());
expect(session.testsimulation).toBe(true);
expect(session.approval_origin).toBe('dev_test_browser_simulation');
expect(session.principal).toBe(expected.expected_principal);
await expect(page.getByLabel('Mandant', { exact: true })).toHaveValue(text(expected.tenant_id));
const operation = text(expected.operation_id);
await page.getByRole('button', { name: operation, exact: true }).click();
const op = page.locator('section').filter({ has: page.getByRole('heading', { name: `Antrag / Ausführung ${operation}`, exact: true }) });
await expect(op.locator('p.warning')).toContainText('Antrag: pending_approval');
await expect(op.locator('pre').first()).toContainText('"job_count": 0');
await expect(op.locator('pre').first()).toContainText('"execution_state": null');
await op.getByRole('button', { name: 'Unveränderlichen Plan zur Prüfung öffnen' }).click();
const detail = page.locator('section').filter({ has: page.getByRole('heading', { name: 'Unveränderlicher Plan / Genehmigungsdetail', exact: true }) });
await expect(detail.locator('pre')).toBeVisible();
const plan = object(JSON.parse(await detail.locator('pre').innerText()));
expect(plan.plan_hash).toBe(expected.plan_hash);
expect(bytes(plan.plan_payload_bytes)).toEqual(bytes(expected.plan_payload_bytes));
expect(createHash('sha256').update(bytes(plan.plan_payload_bytes)).digest('hex')).toBe(expected.plan_hash);
const targets = plan.resolved_targets;
const jobs = plan.jobs;
if (!Array.isArray(targets) || !Array.isArray(jobs) || targets.length !== 1 || jobs.length !== 1) throw new Error('Exactly one fixed VM target/job required');
expect(object(targets[0])).toEqual({ agent_id: expected.agent_id, asset_id: expected.asset_id });
const job = object(jobs[0]);
const payload = object(job.payload);
expect(payload).toEqual(expected.job_payload);
expect(job.job_payload_hash).toBe(expected.job_payload_hash);
expect(payload.tenant_id).toBe(expected.tenant_id);
expect(payload.agent_id).toBe(expected.agent_id);
expect(payload.asset_id).toBe(expected.asset_id);
expect(Number.isInteger(payload.enrollment_generation) && Number(payload.enrollment_generation) > 0).toBe(true);
expect(Number.isInteger(payload.assignment_version) && Number(payload.assignment_version) > 0).toBe(true);
expect(Date.parse(text(payload.start_before))).toBeGreaterThan(Date.now());
expect(Number(payload.max_output_bytes)).toBeLessThanOrEqual(65536);
const action = object(payload.action);
if (expected.case === 'hello' || expected.case === 'cancel_queued' || expected.case === 'expired_offline') {
expect(payload.execution_identity).toBe('agent_service');
expect(action).toEqual({ action: 'run_script', interpreter: 'posix_sh', script_utf8: "printf '%s\\n' 'Hello World'\n", arguments: [], expected_stdout: 'Hello World\n' });
} else if (expected.case === 'service_setup') {
expect(payload.execution_identity).toBe('root');
expect(action.action).toBe('run_script'); expect(action.interpreter).toBe('posix_sh');
expect(action.arguments).toEqual([]); expect(action.expected_stdout).toBe('RMM test unit prepared\n');
expect(createHash('sha256').update(text(action.script_utf8)).digest('hex')).toBe('159ff240504b8a350b46a56fdf9cd50e5768816de7e6683829f05144978449f0');
expect(payload.max_runtime_seconds).toBe(60);
} else if (expected.case === 'refresh_inventory') {
expect(payload.execution_identity).toBe('agent_service');
expect(action).toEqual({ action: 'refresh_inventory', scope: 'linux.base' });
} else if (expected.case === 'query_logs') {
expect(payload.execution_identity).toBe('agent_service');
expect(action.action).toBe('query_logs'); expect(action.unit).toBe('rmm-mvp-test.service');
expect(action.max_lines).toBe(50);
expect(Date.parse(text(action.until)) - Date.parse(text(action.since))).toBe(300000);
} else if (['apt_native_install', 'apt_native_update', 'ensure_package', 'apply_updates'].includes(text(expected.case))) {
expect(payload.execution_identity).toBe('root');
const native = expected.case === 'apt_native_install' || expected.case === 'apt_native_update';
const upgrade = expected.case === 'apt_native_update' || expected.case === 'apply_updates' || expected.case === 'ensure_package';
expect(action.action).toBe(native ? 'apt_native_acceptance' : expected.case);
const manifest = object(action.apt_manifest);
expect(manifest.type).toBe('rmm.apt.helper-action'); expect(manifest.schema_version).toBe(2);
expect(manifest.action).toBe(native ? 'apt-native-acceptance' : 'apt-execute');
expect(manifest.execution_profile).toBe('dev-test');
const transaction = object(manifest.resolved_apt_transaction);
expect(JSON.parse(bytes(manifest.transaction_bytes).toString('utf8'))).toEqual(transaction);
expect(createHash('sha256').update(bytes(manifest.transaction_bytes)).digest('hex')).toBe(manifest.transaction_sha256);
expect(transaction.recipe_id).toBe(upgrade ? 'rmm-apt-fixture-update-1.1' : 'rmm-apt-fixture-install-1.0');
expect(transaction.recipe_version).toBe('1'); expect(transaction.platform).toBe('ubuntu-24.04-amd64');
expect(transaction.no_reboot).toBe(true);
const pin = upgrade ? 'ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af6027d8a9c00491' : '74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867';
expect(transaction.packages).toEqual([{ name: 'rmm-mvp-test', architecture: 'all', old_version: upgrade ? '1.0' : null,
new_version: upgrade ? '1.1' : '1.0', origin: 'rmm-test', sha256: pin, size: 20672,
archive_path: `/var/lib/rmm-apt-transaction/archives/${pin}.deb` }]);
for (const key of ['provider_sha256', 'hook_sha256', 'apt_config_sha256', 'runtime_sha256']) expect(text(manifest[key])).toMatch(/^[a-f0-9]{64}$/);
if (expected.case === 'apply_updates') { expect(action.packages).toEqual(['rmm-mvp-test']); expect(action.reboot_policy).toBe('never'); }
if (expected.case === 'ensure_package') { expect(action.package).toBe('rmm-mvp-test'); expect(action.version).toBe('1.1'); }
} else if (expected.case === 'reboot_last') {
expect(payload.execution_identity).toBe('root');
expect(action).toEqual({ action: 'reboot', reason: 'Explicit final Linux VM dev/test acceptance', dependency_group: 'single-test-vm', reconnect_timeout_seconds: 180 });
expect(payload.max_runtime_seconds).toBe(240);
} else {
expect(payload.execution_identity).toBe('root');
expect(action).toEqual({ action: 'set_service_state', unit: 'rmm-mvp-test.service', state: expected.case === 'service_start' ? 'running' : 'stopped' });
expect(payload.max_runtime_seconds).toBe(180);
}
const approve = detail.getByRole('button', { name: 'SIMULIERT: Diesen festen Plan ausdrücklich genehmigen', exact: true });
await expect(approve).toBeDisabled();
await detail.getByRole('checkbox', { name: 'Ich habe sämtliche festen Ziele', exact: false }).check();
await expect(approve).toBeEnabled();
await approve.click(); // Deliberately no API client, injected fetch, route or direct approval request.
await expect(op.locator('p.warning')).toContainText('Antrag: approved');
await expect(op.locator('pre').first()).toContainText('"job_count": 1');
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
});
+84
View File
@@ -0,0 +1,84 @@
import { test, expect } from '../../web/node_modules/@playwright/test/index.js';
import { mkdirSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { mkdtempSync, rmSync } from 'node:fs';
import { chromium } from '../../web/node_modules/@playwright/test/index.js';
import { login } from './helpers';
test('real TLS UI: login, tenant, fixed preview, pending, reload, CSRF denial and logout', async ({ page, context }) => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'pending-only', 'Explicit pending-only dev/test run required');
const asset = process.env.RMM_E2E_ASSET_ID;
if (!asset) throw new Error('Authenticated local fixture asset required');
const statuses: { path: string; status: number }[] = [];
page.on('response', r => {
const path = new URL(r.url()).pathname;
if (path === '/auth/dev/login' || path.endsWith('/operation-plans') || path.endsWith('/submit')) statuses.push({ path: path === '/auth/dev/login' ? 'login' : path.endsWith('/submit') ? 'submit' : 'plan', status: r.status() });
});
let authorizationRequests = 0;
page.on('request', r => { if (new URL(r.url()).pathname.endsWith('/authorizations')) authorizationRequests++; });
await login(page);
await expect(page.getByLabel('Mandant', { exact: true })).not.toHaveValue('');
const cookies = await context.cookies();
const authCookie = cookies.find(c => c.name === '__Host-rmm_session');
expect(authCookie?.httpOnly).toBe(true); expect(authCookie?.secure).toBe(true); expect(authCookie?.sameSite).toBe('Strict');
await page.getByRole('checkbox', { name: `Ziel ${asset}`, exact: true }).check();
await page.getByLabel('Exakte UTF-8 Skriptbytes', { exact: false }).fill("printf '%s\\n' 'Hello World'\n");
await page.getByLabel('Erwartete stdout-Ausgabe', { exact: false }).fill('Hello World\n');
await page.getByLabel('Begründung', { exact: true }).fill('Authenticated synthetic local fixture · pending-only browser contract; do not execute');
await page.getByRole('button', { name: 'Plan erstellen · noch keine Ausführung' }).click();
const approve = page.getByRole('button', { name: 'SIMULIERT: Diesen festen Plan ausdrücklich genehmigen' });
await expect(approve).toBeDisabled();
await expect(page.getByText('Nicht genehmigungsfähig:', { exact: false })).toHaveCount(0);
await page.getByRole('button', { name: 'Antrag absenden · pending_approval' }).click();
const op = page.locator('section').filter({ has: page.getByRole('heading', { name: /^Antrag \/ Ausführung / }) });
await expect(op.locator('p.warning')).toContainText('Antrag: pending_approval');
await expect(op.locator('pre')).toContainText('"job_count": 0');
await expect(op.locator('pre')).toContainText('"execution_state": null');
const operationHeading = await op.getByRole('heading', { name: /^Antrag \/ Ausführung / }).innerText();
const operationId = operationHeading.replace('Antrag / Ausführung ', '').trim();
await page.reload();
await expect(page.getByRole('status')).toContainText('SIMULIERT');
await page.getByRole('button', { name: operationId, exact: true }).click();
await expect(op.locator('p.warning')).toContainText('Antrag: pending_approval');
await page.getByRole('button', { name: 'Unveränderlichen Plan zur Prüfung öffnen' }).click();
await page.getByRole('checkbox', { name: 'Ich habe sämtliche festen Ziele', exact: false }).check();
await expect(approve).toBeEnabled(); // We intentionally do NOT click approval in this run.
expect(authorizationRequests).toBe(0);
// Negative CSRF check uses a real UI logout click, never an authorization request.
await page.route('**/auth/logout', async route => {
const headers = { ...route.request().headers() }; delete headers['x-csrf-token'];
await route.continue({ headers });
});
const denied = page.waitForResponse(r => new URL(r.url()).pathname === '/auth/logout');
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
expect((await denied).status()).toBe(403);
await expect(page.getByRole('alert').first()).toBeVisible();
await expect(page.getByRole('status')).toContainText('SIMULIERT');
await page.unroute('**/auth/logout');
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
await expect(page.getByRole('button', { name: 'Anmelden', exact: true })).toBeVisible();
expect(statuses.some(s => s.path === 'login' && s.status === 200)).toBe(true);
expect(statuses.some(s => s.path === 'plan' && s.status === 200)).toBe(true);
expect(statuses.some(s => s.path === 'submit' && s.status === 200)).toBe(true);
const directory = resolve('node_modules/.cache/browser-evidence'); mkdirSync(directory, { recursive: true, mode: 0o700 });
writeFileSync(resolve(directory, 'pending.json'), JSON.stringify({ profile: 'dev/test', testsimulation: true, tls_verification_enabled: true, synthetic_authenticated_local_fixture: true, simulation_banner: true, secure_cookie: true, pending_job_count: 0, pending_execution_state: null, reload_pending_review: true, csrf_logout_denied_status: 403, authorization_requests: authorizationRequests, executed_jobs: false, vm_evidence: false, statuses, checked_at: new Date().toISOString() }, null, 2), { mode: 0o600 });
});
test('real browser TLS rejects a certificate for a different DNS name', async ({ page }) => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'pending-only');
let rejected = false;
try { await page.goto('https://rmm-dev-wrong-name.internal:18443/'); } catch (e) { rejected = e instanceof Error && /ERR_CERT_COMMON_NAME_INVALID/.test(e.message); }
expect(rejected).toBe(true);
});
test('real browser without the isolated development CA rejects the server chain', async () => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'pending-only');
const home = mkdtempSync(resolve('node_modules/.cache/browser-untrusted-'));
const browser = await chromium.launch({ env: { ...process.env, HOME: home }, args: ['--host-resolver-rules=MAP rmm-dev.internal 127.0.0.1', '--no-proxy-server'] });
try {
const page = await browser.newPage();
let rejected = false;
try { await page.goto('https://rmm-dev.internal:18443/'); } catch (e) { rejected = e instanceof Error && /ERR_CERT_AUTHORITY_INVALID/.test(e.message); }
expect(rejected).toBe(true);
} finally { await browser.close(); rmSync(home, { recursive: true, force: true }); }
});
+17
View File
@@ -0,0 +1,17 @@
import type { FullResult, Reporter, TestCase, TestResult, TestStep } from '../../web/node_modules/@playwright/test/reporter';
import { diagnostic } from './diagnostics';
/** Playwright action error call logs can contain locator.fill(password) arguments.
* Never print raw test errors/steps/stdout/stderr, even on a failed login. */
export default class SafeReporter implements Reporter {
private executed = 0;
onBegin() { console.log('Dev/test browser simulation suite. Secret-bearing step/error logs suppressed.'); }
onTestEnd(_test: TestCase, result: TestResult) { if (result.status !== 'skipped') this.executed++; console.log(`Browser simulation: ${result.status}.`); }
onStepEnd(_test: TestCase, _result: TestResult, step: TestStep) {
if (step.category !== 'test.step') return;
const safe = diagnostic(step.title, step.error, step.location?.line);
if (safe) console.error(safe);
}
onError() { console.error('Browser simulation infrastructure error; details suppressed to protect login secrets.'); }
onEnd(result: FullResult) { console.log(this.executed ? `Browser simulation suite: ${result.status}. No production approval evidence.` : 'No browser test executed (discovery or skipped). No acceptance evidence.'); }
}
+46
View File
@@ -0,0 +1,46 @@
import { test, expect } from '../../web/node_modules/@playwright/test/index.js';
import { createHash } from 'node:crypto';
import { login } from './helpers';
test('preserved real VM: pending fixed Hello World → UI click → confirmed result', async ({ page }) => {
test.skip(process.env.RMM_E2E_PROFILE !== 'dev/test' || process.env.RMM_E2E_MODE !== 'vm-hello', 'Explicit VM Hello-World simulation required');
const asset = process.env.RMM_E2E_ASSET_ID;
const operation = process.env.RMM_E2E_OPERATION_ID;
if (!asset || !operation) throw new Error('Fixed VM asset and existing pending operation required');
await login(page);
await page.getByRole('button', { name: operation, exact: true }).click();
const op = page.locator('section').filter({ has: page.getByRole('heading', { name: `Antrag / Ausführung ${operation}`, exact: true }) });
await expect(op.locator('p.warning')).toContainText('Antrag: pending_approval');
await expect(op.locator('pre').first()).toContainText('"job_count": 0');
await expect(op.locator('pre').first()).toContainText('"execution_state": null');
await op.getByRole('button', { name: 'Unveränderlichen Plan zur Prüfung öffnen' }).click();
const detail = page.locator('section').filter({ has: page.getByRole('heading', { name: 'Unveränderlicher Plan / Genehmigungsdetail', exact: true }) });
await expect(detail.locator('pre')).toBeVisible();
// Inspect the complete rendered immutable preview, not a separately fetched
// or caller-supplied payload. Refuse all root/package/reboot/extra-target jobs.
const plan = JSON.parse(await detail.locator('pre').innerText());
expect(plan.resolved_targets).toHaveLength(1);
expect(plan.resolved_targets[0].asset_id).toBe(asset);
expect(plan.jobs).toHaveLength(1);
const payload = plan.jobs[0].payload;
expect(payload.asset_id).toBe(asset);
expect(payload.execution_identity).toBe('agent_service');
expect(payload.action).toEqual({ action: 'run_script', interpreter: 'posix_sh', script_utf8: "printf '%s\\n' 'Hello World'\n", arguments: [], expected_stdout: 'Hello World\n' });
expect(payload.max_runtime_seconds).toBeLessThanOrEqual(60);
expect(payload.max_output_bytes).toBeLessThanOrEqual(65536);
expect(Date.parse(payload.start_before)).toBeGreaterThan(Date.now());
expect(createHash('sha256').update(Buffer.from(plan.plan_payload_bytes)).digest('hex')).toBe(plan.plan_hash);
await expect(detail).toContainText(plan.plan_hash);
const approve = detail.getByRole('button', { name: 'SIMULIERT: Diesen festen Plan ausdrücklich genehmigen', exact: true });
await expect(approve).toBeDisabled();
await detail.getByRole('checkbox', { name: 'Ich habe sämtliche festen Ziele', exact: false }).check();
await expect(approve).toBeEnabled();
await approve.click(); // Only actual UI interaction; no request/API approval.
await expect(op.locator('p.warning')).toContainText('Antrag: approved');
await expect(op.locator('pre').first()).toContainText('"job_count": 1');
await expect(op.locator('p.warning')).toContainText('Ausführung: succeeded', { timeout: 90000 });
await op.getByRole('button', { name: /^Job / }).click();
await expect(op.getByRole('heading', { name: /^Job / })).toBeVisible();
await expect(op.locator('article pre')).toContainText('"postconditions_passed": true');
await page.getByRole('button', { name: 'Abmelden', exact: true }).click();
});