feat: snapshot Linux-first RMM MVP and pause handover
Rust development slice / linux (push) Failing after 1m10s
Rust development slice / linux (push) Failing after 1m10s
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { actions, PlanInput, Session, request, session } from './api';
|
||||
import { adminIntent, allowed, availableActions, parseStrictJson, recipeInput, rootWarning, sha256, validateAptManifest, validateSensitiveInput, verifyAptManifest, verifyPlanIntegrity } from './safety';
|
||||
import { AdminControl } from './management';
|
||||
|
||||
const auth: Session = { principal: { id: 'test', display_name: 'SIMULIERT', simulated: true }, csrf_token: 'csrf', tenants: [], permissions: ['root:execute', 'devices:revoke'] };
|
||||
async function manifest(acceptance = true) {
|
||||
const transaction = { schema_version: 1, recipe_id: 'rmm-apt-fixture-install-1.0', recipe_version: '1', platform: 'ubuntu-24.04-amd64', resolver_config_version: 'rmm-apt-local-v1', no_reboot: true, status_fingerprint: 'a'.repeat(64), baseline_sha256: 'b'.repeat(64), packages: [{ name: 'rmm-mvp-test', architecture: 'all', old_version: null, new_version: '1.0', origin: 'rmm-test', sha256: '74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867', size: 20672, archive_path: '/var/lib/rmm-apt-transaction/archives/74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867.deb' }] };
|
||||
const raw = new TextEncoder().encode(JSON.stringify(transaction));
|
||||
return { type: 'rmm.apt.helper-action', schema_version: 2, action: acceptance ? 'apt-native-acceptance' : 'apt-execute', execution_profile: 'dev-test', transaction_sha256: await sha256(raw), transaction_bytes: Array.from(raw), resolved_apt_transaction: transaction, provider_sha256: 'c'.repeat(64), hook_sha256: 'd'.repeat(64), apt_config_sha256: 'e'.repeat(64), runtime_sha256: 'f'.repeat(64), test_result_id: 'unit-test-only-not-native-evidence' };
|
||||
}
|
||||
function input(apt_manifest: unknown): PlanInput { return { tenant_id: 't', action: 'apt_native_acceptance', targets: { asset_ids: ['asset'] }, parameters: { execution_identity: 'root', recipe_id: 'rmm-apt-fixture-install-1.0', recipe_version: '1', apt_manifest }, schedule: { not_before: '', start_before: '', offline_policy: 'wait_until_deadline' }, rollout: { max_parallel: 1, halt_after_failures: 1 }, reason: 'unit only' }; }
|
||||
describe('immutable catalog and strict import contracts', () => {
|
||||
it('only accepts full immutable exact APT package metadata, never URLs or unknown fields', () => {
|
||||
const r = { schema_version: 1, provider: 'apt', package: 'rmm-test', version: '1.0+test1', architecture: 'amd64', recipe_version: '1', installation_context: 'system', reboot_policy: 'never' };
|
||||
expect(recipeInput(r)).toEqual(r);
|
||||
expect(() => recipeInput({ ...r, url: 'https://example.invalid' })).toThrow();
|
||||
expect(() => recipeInput({ ...r, package: 'https://example.invalid/a.deb' })).toThrow();
|
||||
expect(() => recipeInput({ ...r, version: '' })).toThrow();
|
||||
expect(() => parseStrictJson('{"version":"1","version":"2"}')).toThrow('Doppeltes');
|
||||
expect(() => parseStrictJson('{"a":{"\u0078":1,"x":2}}')).toThrow('Doppeltes');
|
||||
});
|
||||
});
|
||||
describe('root and dedicated dev-test APT actions', () => {
|
||||
it('shows native acceptance only with explicit server simulation evidence, never upgrades identity', async () => {
|
||||
expect(availableActions(auth, actions)).toContain('apt_native_acceptance');
|
||||
expect(availableActions({ ...auth, principal: { ...auth.principal, simulated: false } }, actions)).not.toContain('apt_native_acceptance');
|
||||
const value = input(await manifest());
|
||||
await validateSensitiveInput(value, auth); expect(value.parameters.execution_identity).toBe('root');
|
||||
await expect(validateSensitiveInput({ ...value, parameters: { ...value.parameters, execution_identity: 'agent_service' } }, auth)).rejects.toThrow('root');
|
||||
await expect(validateSensitiveInput(value, { ...auth, permissions: [] })).rejects.toThrow('root:execute');
|
||||
await expect(validateSensitiveInput(value, { ...auth, principal: { ...auth.principal, simulated: false } })).rejects.toThrow('simuliert');
|
||||
expect(rootWarning).toContain('HOHES RISIKO'); expect(rootWarning).toContain('Keine automatische Rechteerhöhung');
|
||||
});
|
||||
it('checks schema2, full closure, exact bytes, pinned versions/hashes/origins and placeholders', async () => {
|
||||
const m = await manifest(); await verifyAptManifest(m, true);
|
||||
expect(() => validateAptManifest({ ...m, schema_version: 1 }, true)).toThrow();
|
||||
expect(() => validateAptManifest({ ...m, provider_sha256: '<placeholder>' }, true)).toThrow();
|
||||
expect(() => validateAptManifest({ ...m, transaction_bytes: [] }, true)).toThrow();
|
||||
expect(() => validateAptManifest({ ...m, resolved_apt_transaction: { ...m.resolved_apt_transaction, packages: [] } }, true)).toThrow();
|
||||
expect(() => validateAptManifest({ ...m, unknown: true }, true)).toThrow();
|
||||
await expect(verifyAptManifest({ ...m, transaction_sha256: 'a'.repeat(64) }, true)).rejects.toThrow('Transaktionshash');
|
||||
await expect(validateSensitiveInput({ ...input(m), parameters: { ...input(m).parameters, recipe_id: 'other' } }, auth)).rejects.toThrow('Rezept');
|
||||
});
|
||||
it('preserves ordinary package manifest closure unchanged, validates outer package identity', async () => {
|
||||
const m = await manifest(false), value = input(m); value.action = 'ensure_package'; value.parameters = { ...value.parameters, provider: 'apt', package: 'rmm-mvp-test', version: '1.0', architecture: 'all', installation_context: 'system' };
|
||||
const before = JSON.stringify(value); await validateSensitiveInput(value, auth); expect(JSON.stringify(value)).toBe(before);
|
||||
await expect(validateSensitiveInput({ ...value, parameters: { ...value.parameters, version: '2' } }, auth)).rejects.toThrow('Paketidentität');
|
||||
});
|
||||
it('checks exact plan byte hash and manifest consistency without demanding execution IDs', async () => {
|
||||
const p = { targets: ['asset'], jobs: [{ payload: { asset_id: 'asset', action: { action: 'apt_native_acceptance', apt_manifest: await manifest() } } }] }, raw = new TextEncoder().encode(JSON.stringify(p));
|
||||
const plan = { plan_payload: p, plan_payload_bytes: Array.from(raw), plan_hash: await sha256(raw), jobs: p.jobs };
|
||||
await verifyPlanIntegrity(plan);
|
||||
await expect(verifyPlanIntegrity({ ...plan, plan_hash: 'a'.repeat(64) })).rejects.toThrow('Planhash');
|
||||
await expect(verifyPlanIntegrity({ ...plan, plan_payload: { ...p, targets: ['foreign'] } })).rejects.toThrow('widerspricht');
|
||||
});
|
||||
});
|
||||
describe('interactive administrative boundary', () => {
|
||||
it('retains explicit membership permissions and never treats roles as implicit rights', () => {
|
||||
const s = session({ principal: 'test', tenant_id: 't', csrf_token: 'csrf', testsimulation: true, permissions: ['devices:revoke'], roles: ['dev_test_member'] });
|
||||
expect(allowed(s, 'devices:revoke')).toBe(true); expect(allowed({ ...s, permissions: undefined }, 'devices:revoke')).toBe(false);
|
||||
});
|
||||
it('requires explicit click confirmation, reason and current nonce; rendering causes no request', () => {
|
||||
const fetch = vi.fn(); vi.stubGlobal('fetch', fetch);
|
||||
const html = renderToStaticMarkup(<AdminControl auth={auth} path="/api/v1/tenants/t/devices/a/revocation" title="Widerrufen" permission="devices:revoke" warning="Unterbricht Verwaltung"/>);
|
||||
expect(html).toContain('Unterbricht Verwaltung'); expect(html).toContain('Bestätigungskennung'); expect(fetch).not.toHaveBeenCalled();
|
||||
expect(() => adminIntent(false, 'reason', 'nonce', 'nonce')).toThrow(); expect(() => adminIntent(true, '', 'nonce', 'nonce')).toThrow(); expect(() => adminIntent(true, 'reason', 'old', 'nonce')).toThrow();
|
||||
expect(adminIntent(true, 'reason', 'nonce', 'nonce')).toEqual({ reason: 'reason' }); vi.unstubAllGlobals();
|
||||
});
|
||||
it('sends exact admin JSON with cookie credentials and CSRF, never a secret-bearing nonce API field', async () => {
|
||||
const fetch = vi.fn().mockResolvedValue(new Response('{}')); vi.stubGlobal('fetch', fetch);
|
||||
await request('/api/v1/tenants/t/execution-stop', { csrf: 'csrf', body: { ...adminIntent(true, 'test only', 'nonce', 'nonce'), stopped: true } });
|
||||
expect(fetch).toHaveBeenCalledWith('/api/v1/tenants/t/execution-stop', expect.objectContaining({ credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': 'csrf' }, body: '{"reason":"test only","stopped":true}' })); vi.unstubAllGlobals();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user