85 lines
6.4 KiB
TypeScript
85 lines
6.4 KiB
TypeScript
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 }); }
|
|
});
|