Assessor_2.0/tests/features/gpo-source-presentation.tes...

48 lines
3.3 KiB
TypeScript

import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it } from 'vitest';
import type { UnifiedResultProjection } from '../../src/domain/unified-result';
import type { FindingRecord } from '../../src/domain/finding';
import { formatPolicySources, policySourceReference } from '../../src/profiles/group-policy/source-presentation';
import { FindingReader } from '../../src/features/finding-reader/FindingReader';
function source(id: string, value = 0): UnifiedResultProjection {
return { sourceResultId: id, sourceLocator: { objectPath: `C:/Private/GPO_Backup/${id}/{1667E9C3-865B-4ABA-A288-71C8A18AD5E0}/DomainSysvol/GPO/Machine/registry.pol#records=0` }, policyScope: 'computer', policyBackupInstanceId: 'backup-' + id,
policyValues: [{ kind: 'registry-policy', key: 'Software\\Policies\\Synthetic', valueName: 'Mode', typeCode: 4, operation: 'set-value', data: { kind: 'uint32', value } }] } as unknown as UnifiedResultProjection;
}
describe('GPO source presentation', () => {
it('shows only the customer-safe GPO-internal source reference', () => {
const item = source('one');
const before = JSON.stringify(item);
expect(formatPolicySources([item])).toBe('{1667E9C3-865B-4ABA-A288-71C8A18AD5E0}/DomainSysvol/GPO/Machine/registry.pol#records=0');
expect(formatPolicySources([item])).not.toMatch(/Private|GPO_Backup|Scope|Registry path|Backup|Record/);
expect(JSON.stringify(item)).toBe(before);
});
it('shows every source immediately without headings or duplicated source values', () => {
const formatted = formatPolicySources([source('one', 0), source('two', 1)]);
expect(formatted.split('\n')).toHaveLength(2);
expect(formatted).not.toMatch(/Source \d|Value:|Show source/);
expect(formatPolicySources(Array.from({ length: 2300 }, (_, index) => source(String(index)))).split('\n')).toHaveLength(2300);
});
it('fails closed when no GPO-internal reference is present and handles an absent source list', () => {
expect(policySourceReference('C:/Private/customer/report.xml')).toBe('GPO source reference unavailable');
expect(policySourceReference('C:/Private/{1667E9C3-865B-4ABA-A288-71C8A18AD5E0}/customer/report.xml')).toBe('GPO source reference unavailable');
expect(policySourceReference('C:/Private/DomainSysvol/GPO/User/registry.pol#records=2')).toBe('DomainSysvol/GPO/User/registry.pol#records=2');
expect(formatPolicySources([])).toBe('');
});
it('renders source text without interpreting private paths or markup as links', () => {
const item = source('markup');
item.sourceLocator = { objectPath: '<img src="https://private.invalid/secret">' };
const record: FindingRecord = { id: 'synthetic', index: 0, title: 'Synthetic', filled: [], meta: [], fields: [{ index: 0, label: 'Sources', value: formatPolicySources([item]) }] };
const html = renderToStaticMarkup(createElement(FindingReader, { record, title: record.title, linkedSheets: [], resultReferences: [], search: '', position: 0, recordCount: 1, toolId: 'group-policy', onPrevious() {}, onNext() {}, onReview() {} }));
expect(html).toContain('class="policy-guidance-text">GPO source reference unavailable');
expect(html).not.toContain('private.invalid');
expect(html).not.toContain('<img');
expect(html).not.toContain('href="https://private.invalid');
});
});