Plan device actions exclusively as approved scripts and provide reboot library revisions
This commit is contained in:
@@ -96,10 +96,14 @@ test('applies order filters from the first page and clears them on reset', async
|
||||
expect(requests.at(-1)?.searchParams.has('device')).toBe(false);
|
||||
});
|
||||
|
||||
test('uses the execution stop status and blocks restart planning until the device reports support', async ({ page }) => {
|
||||
test('shows the execution stop and prepares the Windows restart through a versioned administrator script', async ({ page }) => {
|
||||
const api = '/api/v1/tenants/' + tenantId;
|
||||
const permissions = [...auth.permissions, 'tenant:stop', 'system:execute'];
|
||||
let stopped = false, ready = false;
|
||||
let stopped = false, scopeDenied = false;
|
||||
const restart = {
|
||||
...script, name: 'Windows neu starten', revision_id: randomUUID(), version: 2,
|
||||
interpreter: 'powershell', execution_identity: 'system', script_utf8: "Write-Output 'Neustart-Test'\n"
|
||||
};
|
||||
const writes: unknown[] = [];
|
||||
await page.route(origin + '/auth/config', r => r.fulfill({ json: {
|
||||
dev_login_enabled: false, local_login_enabled: true, oidc_configured: false, oidc_login_url: null
|
||||
@@ -113,12 +117,16 @@ test('uses the execution stop status and blocks restart planning until the devic
|
||||
return r.fulfill({ json: { tenant_id: tenantId, changes_stopped: stopped } });
|
||||
}
|
||||
if (pathname === api + '/devices') return r.fulfill({ json: listing([windows]) });
|
||||
if (pathname === api + '/devices/' + windows.asset_id) return r.fulfill({ json: {
|
||||
...windows, tenant_id: tenantId,
|
||||
capabilities: ready ? ['reboot', 'rmm.sync.v1', 'windows.reboot/1', 'helper.system.v1', 'system:reboot'] : []
|
||||
} });
|
||||
if (req.method() !== 'GET') writes.push(req.postDataJSON());
|
||||
return r.fulfill({ status: 409, json: { code: 'UNSUPPORTED_CAPABILITY' } });
|
||||
if (pathname === api + '/script-revisions') return r.fulfill({ json: listing([
|
||||
{ ...restart, script_sha256: hash(restart.script_utf8) }
|
||||
]) });
|
||||
if (req.method() !== 'GET') {
|
||||
expect(req.headers()['x-csrf-token']).toBe(auth.csrf_token);
|
||||
writes.push({ pathname, body: req.postDataJSON() });
|
||||
}
|
||||
return scopeDenied
|
||||
? r.fulfill({ status: 403, json: { code: 'SCRIPT_HELPER_SCOPE_DENIED' } })
|
||||
: r.fulfill({ status: 409, json: { code: 'UNSUPPORTED_CAPABILITY' } });
|
||||
});
|
||||
|
||||
await page.goto(origin + '/#verwaltung/rechte');
|
||||
@@ -132,23 +140,96 @@ test('uses the execution stop status and blocks restart planning until the devic
|
||||
await expect(page.getByText('Mandantenausführung wieder zulassen', { exact: true })).toBeVisible();
|
||||
expect(writes).toHaveLength(0);
|
||||
|
||||
await page.goto(origin + '/#auftraege/neu');
|
||||
await page.goto(origin + '/#auftraege/wartung');
|
||||
await page.getByRole('checkbox', { name: /test-windows/ }).check();
|
||||
await page.getByRole('button', { name: 'Weiter zur Aktion' }).click();
|
||||
await page.getByRole('radio', { name: 'Gerät neu starten' }).check();
|
||||
await page.getByRole('button', { name: 'Weiter zum Skript' }).click();
|
||||
await page.getByRole('button', { name: 'Neustartskript auswählen' }).click();
|
||||
await expect(page.getByRole('combobox', { name: 'Bibliotheksskript', exact: true })).toHaveValue(restart.name);
|
||||
await expect(page.getByRole('combobox', { name: 'Version', exact: true })).toHaveValue(restart.revision_id);
|
||||
await expect(page.getByRole('combobox', { name: 'Ausführen als', exact: true })).toHaveValue('system');
|
||||
await page.getByText('Skriptinhalt anzeigen').click();
|
||||
await expect(page.locator('pre')).toHaveText(restart.script_utf8.trim());
|
||||
await page.getByLabel('Begründung', { exact: true }).fill('Neustart prüfen');
|
||||
const plan = page.getByRole('button', { name: 'Zusammenfassung ansehen' });
|
||||
await expect(page.getByRole('alert')).toContainText('keine Neustartfähigkeit');
|
||||
await expect(plan).toBeDisabled();
|
||||
expect(writes).toHaveLength(0);
|
||||
ready = true;
|
||||
await expect(plan).toBeEnabled({ timeout: 8000 });
|
||||
await plan.click();
|
||||
await expect(page.getByRole('alert')).toContainText('unterstützt die ausgewählte Ausführung noch nicht');
|
||||
expect(writes).toEqual([expect.objectContaining({
|
||||
action: 'reboot', targets: { asset_ids: [windows.asset_id] },
|
||||
parameters: expect.objectContaining({ execution_identity: 'system', reconnect_timeout_seconds: 180 })
|
||||
})]);
|
||||
await page.getByRole('button', { name: 'Zusammenfassung ansehen' }).click();
|
||||
await expect(page.getByRole('alert')).toContainText('Skript-Helper für SYSTEM noch nicht als betriebsbereit gemeldet');
|
||||
expect(writes).toEqual([{
|
||||
pathname: api + '/script-revisions/' + restart.revision_id + '/plan',
|
||||
body: expect.objectContaining({
|
||||
reason: 'Neustart prüfen', targets: { asset_ids: [windows.asset_id] }, max_runtime_seconds: 120, max_output_bytes: 65536
|
||||
})
|
||||
}]);
|
||||
scopeDenied = true;
|
||||
await page.getByRole('button', { name: 'Zusammenfassung ansehen' }).click();
|
||||
await expect(page.getByRole('alert')).toContainText('zentrale Richtlinie erlaubt dieses Administratorskript');
|
||||
expect(writes).toHaveLength(2);
|
||||
});
|
||||
|
||||
test('offers local admin opt-in on both installer commands and keeps the one-time code outside commands', async ({ page }) => {
|
||||
const token = 'f'.repeat(64), api = '/api/v1/tenants/' + tenantId;
|
||||
const requests: string[] = [];
|
||||
await page.route(origin + '/auth/config', r => r.fulfill({ json: { dev_login_enabled: true, oidc_configured: false, oidc_login_url: null } }));
|
||||
await page.route(origin + '/auth/session', r => r.fulfill({ json: { ...auth, permissions: [...auth.permissions, 'devices:enroll'] } }));
|
||||
await page.route(origin + '/api/v1/**', r => {
|
||||
const req = r.request(), url = new URL(req.url());
|
||||
if (req.method() !== 'GET') requests.push(url.pathname);
|
||||
if (url.pathname === '/api/v1/tenants') return r.fulfill({ json: listing(auth.tenants) });
|
||||
if (url.pathname === api + '/enrollment-tokens') return r.fulfill({ json: {
|
||||
token, expires_at: new Date(Date.now() + 900000).toISOString(), bootstrap_origin: 'https://bootstrap.example',
|
||||
release_platforms: ['x86_64-unknown-linux-gnu', 'x86_64-pc-windows-gnu']
|
||||
} });
|
||||
return r.fulfill({ json: { ...listing([]), pending_count: 0 } });
|
||||
});
|
||||
await page.goto(origin + '/#verwaltung/aufnahme');
|
||||
const enroll = page.getByRole('region', { name: 'Gerät aufnehmen' });
|
||||
const option = enroll.getByRole('checkbox', { name: /Administratorskripte/ });
|
||||
await expect(option).not.toBeChecked();
|
||||
await enroll.getByRole('button', { name: 'Einmalcode erstellen' }).click();
|
||||
const commands = enroll.locator('pre');
|
||||
await expect(commands).toHaveCount(2);
|
||||
expect((await commands.allTextContents()).join(' ')).not.toMatch(/enable-admin-scripts|EnableAdministratorScripts/);
|
||||
await option.check();
|
||||
await expect(commands.nth(0)).toContainText('--enable-admin-scripts');
|
||||
await expect(commands.nth(1)).toContainText('-EnableAdministratorScripts');
|
||||
await expect(enroll.getByText(/Für jeden Auftrag gelten zusätzlich/)).toBeVisible();
|
||||
expect((await commands.allTextContents()).join(' ')).not.toContain(token);
|
||||
expect(requests).toEqual([api + '/enrollment-tokens']);
|
||||
});
|
||||
|
||||
test('keeps an old pending device action readable and prevents approval', async ({ page }) => {
|
||||
const golden = JSON.parse(readFileSync(resolve(__dirname, '../script_console/codec-golden.json'), 'utf8'));
|
||||
const fixed = JSON.parse(Buffer.from(golden[0].plan_payload_bytes).toString('utf8'));
|
||||
fixed.plan_id = randomUUID();
|
||||
fixed.tenant_id = tenantId;
|
||||
const job = fixed.jobs[0];
|
||||
const end = new Date(Date.now() + 600000).toISOString();
|
||||
job.payload = { ...job.payload, tenant_id: tenantId, asset_id: linux.asset_id, agent_id: linux.agent_id,
|
||||
action: { action: 'refresh_inventory', scope: 'linux.base' }, execution_identity: 'agent_service', start_before: end };
|
||||
delete job.script_sha256;
|
||||
job.job_payload_hash = hash(JSON.stringify(job.payload));
|
||||
const bytes = JSON.stringify(fixed);
|
||||
const plan = { plan_id: fixed.plan_id, plan_hash: hash(bytes), plan_payload_bytes: [...Buffer.from(bytes)],
|
||||
plan_payload: fixed, jobs: fixed.jobs, targets: [linux], resolved_targets: [{ asset_id: linux.asset_id, agent_id: linux.agent_id }],
|
||||
excluded_targets: [], expires_at: end, approval_state: 'pending_approval' };
|
||||
const writes: string[] = [];
|
||||
await page.route(origin + '/auth/config', r => r.fulfill({ json: {
|
||||
dev_login_enabled: true, oidc_configured: false, oidc_login_url: null
|
||||
} }));
|
||||
await page.route(origin + '/auth/session', r => r.fulfill({ json: { ...auth, permissions: [...auth.permissions, 'plans:approve'] } }));
|
||||
await page.route(origin + '/api/v1/**', r => {
|
||||
const url = new URL(r.request().url());
|
||||
if (r.request().method() !== 'GET') writes.push(url.pathname);
|
||||
if (url.pathname.endsWith('/operation-plans/' + fixed.plan_id)) return r.fulfill({ json: plan });
|
||||
if (url.pathname === '/api/v1/tenants') return r.fulfill({ json: listing(auth.tenants) });
|
||||
return r.fulfill({ json: { ...listing([]), pending_count: 0 } });
|
||||
});
|
||||
await page.goto(origin + '/#genehmigungen/pruefen/' + tenantId + '/' + fixed.plan_id);
|
||||
await expect(page.locator('.review-targets').getByText('test-linux', { exact: true })).toBeVisible();
|
||||
await expect(page.getByRole('alert')).toHaveText(/frühere Aktionsart/);
|
||||
await page.getByRole('checkbox', { name: /Ich habe die Geräte/ }).check();
|
||||
await expect(page.getByRole('button', { name: 'SIMULIERT: Genehmigen' })).toBeDisabled();
|
||||
await expect(page.getByRole('button', { name: 'SIMULIERT: Ablehnen' })).toBeEnabled();
|
||||
expect(writes).toEqual([]);
|
||||
});
|
||||
|
||||
test('shows the bound script text alongside single and per-device results', async ({ page }) => {
|
||||
@@ -266,11 +347,17 @@ test('shows the bound script text alongside single and per-device results', asyn
|
||||
await expect(source.getByLabel('Gespeicherter Skripttext')).toHaveCount(0);
|
||||
});
|
||||
|
||||
for (const library of [true, false]) {
|
||||
test(
|
||||
library
|
||||
? 'pins a revision, blocks an incompatible target and finds the submitted order after a lost response'
|
||||
: 'submits a one-time script without publishing a library revision',
|
||||
for (const scenario of ['library', 'once', 'restart'] as const) {
|
||||
const library = scenario !== 'once';
|
||||
const restart = scenario === 'restart';
|
||||
const revision = restart ? { ...script, name: 'Linux neu starten', execution_identity: 'root', script_utf8: "printf 'Neustart-Test\n'\n" } : script;
|
||||
const session = restart ? { ...auth, permissions: [...auth.permissions, 'root:execute'] } : auth;
|
||||
const title = {
|
||||
library: 'pins a revision, blocks an incompatible target and finds the submitted order after a lost response',
|
||||
once: 'submits a one-time script without publishing a library revision',
|
||||
restart: 'submits the versioned Linux restart through the ordinary script plan with root identity'
|
||||
}[scenario];
|
||||
test(title,
|
||||
async ({ page }) => {
|
||||
let operationId: string | null = null;
|
||||
let plan: Record<string, unknown> | null = null;
|
||||
@@ -283,7 +370,7 @@ for (const library of [true, false]) {
|
||||
import React from '/node_modules/.vite/deps/react.js';
|
||||
import ReactDOM from '/node_modules/.vite/deps/react-dom_client.js';
|
||||
import {OrderComposer} from '/src/order-composer.tsx';
|
||||
ReactDOM.createRoot(document.querySelector('#root')).render(React.createElement(OrderComposer,{tenantId:'${tenantId}',auth:${JSON.stringify(auth)},initialAssetIds:['${linux.asset_id}'],onSubmitted:id=>document.body.setAttribute('data-operation',id)}));
|
||||
ReactDOM.createRoot(document.querySelector('#root')).render(React.createElement(OrderComposer,{tenantId:'${tenantId}',auth:${JSON.stringify(session)},initialAssetIds:['${linux.asset_id}'],onSubmitted:id=>document.body.setAttribute('data-operation',id)}));
|
||||
</script>`
|
||||
})
|
||||
);
|
||||
@@ -297,7 +384,7 @@ for (const library of [true, false]) {
|
||||
return r.fulfill({ json: suffix.endsWith(linux.asset_id) ? linux : windows });
|
||||
if (suffix === '/script-revisions')
|
||||
return r.fulfill({
|
||||
json: listing([{ ...script, script_sha256: hash(script.script_utf8), version: issuedVersion }])
|
||||
json: listing([{ ...revision, script_sha256: hash(revision.script_utf8), version: issuedVersion }])
|
||||
});
|
||||
if (suffix === '/operation-plans/' + plan?.plan_id)
|
||||
return r.fulfill({ json: { ...plan, operation_id: operationId } });
|
||||
@@ -305,16 +392,17 @@ for (const library of [true, false]) {
|
||||
posted.push(suffix);
|
||||
const body = req.postDataJSON();
|
||||
expect(req.headers()['x-csrf-token']).toBe(auth.csrf_token);
|
||||
if (suffix === (library ? '/script-revisions/' + script.revision_id + '/plan' : '/operation-plans')) {
|
||||
if (suffix === (library ? '/script-revisions/' + revision.revision_id + '/plan' : '/operation-plans')) {
|
||||
expect(body.targets.asset_ids).toEqual([linux.asset_id]);
|
||||
expect(body.reason).toBe('Abnahme');
|
||||
const content = library ? script.script_utf8 : body.parameters.variants[0].script_utf8;
|
||||
const content = library ? revision.script_utf8 : body.parameters.variants[0].script_utf8;
|
||||
const action = {
|
||||
action: 'run_script',
|
||||
interpreter: 'posix_sh',
|
||||
script_utf8: content,
|
||||
arguments: [],
|
||||
expected_stdout: null
|
||||
expected_stdout: null,
|
||||
...(restart ? { privileged_script_profile: 'full_maintenance_v1' } : {})
|
||||
};
|
||||
const payload = {
|
||||
schema_version: 1,
|
||||
@@ -326,7 +414,7 @@ for (const library of [true, false]) {
|
||||
job_id: randomUUID(),
|
||||
attempt_id: randomUUID(),
|
||||
action,
|
||||
execution_identity: 'agent_service',
|
||||
execution_identity: revision.execution_identity,
|
||||
not_before: body.schedule.not_before,
|
||||
start_before: body.schedule.start_before,
|
||||
max_runtime_seconds: library ? body.max_runtime_seconds : body.parameters.timeout_seconds,
|
||||
@@ -345,8 +433,8 @@ for (const library of [true, false]) {
|
||||
...(library
|
||||
? {
|
||||
script_revision: {
|
||||
revision_id: script.revision_id,
|
||||
name: script.name,
|
||||
revision_id: revision.revision_id,
|
||||
name: revision.name,
|
||||
version: 1,
|
||||
script_sha256: job.script_sha256
|
||||
}
|
||||
@@ -383,12 +471,16 @@ for (const library of [true, false]) {
|
||||
if (library) await page.getByRole('checkbox', { name: /test-windows/ }).check();
|
||||
await page.getByRole('button', { name: 'Weiter zum Skript' }).click();
|
||||
if (library) {
|
||||
await page.getByLabel('Bibliotheksskript').selectOption(script.name);
|
||||
await page.getByLabel('Bibliotheksskript').selectOption(revision.name);
|
||||
await expect(page.getByRole('alert')).toContainText('test-windows');
|
||||
await expect(page.getByRole('button', { name: 'Zusammenfassung ansehen' })).toBeDisabled();
|
||||
await page.getByRole('button', { name: 'Zurück zu Geräten' }).click();
|
||||
await page.getByRole('checkbox', { name: /test-windows/ }).uncheck();
|
||||
await page.getByRole('button', { name: 'Weiter zum Skript' }).click();
|
||||
if (restart) {
|
||||
await page.getByRole('button', { name: 'Neustartskript auswählen' }).click();
|
||||
await expect(page.getByRole('combobox', { name: 'Ausführen als', exact: true })).toHaveValue('root');
|
||||
}
|
||||
} else {
|
||||
await page.getByRole('radio', { name: 'Einmaliges Skript' }).check();
|
||||
await page.getByLabel('Skriptinhalt').fill('uname\n');
|
||||
@@ -409,7 +501,7 @@ for (const library of [true, false]) {
|
||||
await expect(page.locator('body')).toHaveAttribute('data-operation', /^[a-f0-9-]{36}$/);
|
||||
expect(await page.locator('body').getAttribute('data-operation')).toBe(operationId);
|
||||
expect(posted).toEqual([
|
||||
library ? '/script-revisions/' + script.revision_id + '/plan' : '/operation-plans',
|
||||
library ? '/script-revisions/' + revision.revision_id + '/plan' : '/operation-plans',
|
||||
'/operation-plans/' + plan!.plan_id + '/submit'
|
||||
]);
|
||||
expect(await page.evaluate(() => sessionStorage.length)).toBe(0);
|
||||
|
||||
Reference in New Issue
Block a user