Assessor_2.0/tests/features/maester-environment-detail....

45 lines
3.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { dashboardDomainInformation, dashboardEntraTenantCount, dashboardEnvironmentDetail } from '../../src/features/dashboard/DashboardPanel';
import { maesterEnvironmentContext } from '../../src/importers/maester-environment-context';
import type { EnvironmentSnapshot } from '../../src/domain/environment-context';
describe('Maester context presentation', () => {
const context = maesterEnvironmentContext('synthetic.html', {
TenantId: 'tenant-1', TenantName: 'Synthetic tenant', CurrentVersion: '1.2', ExecutedAt: '2026-09-09T08:00:00Z',
TotalDuration: '00:00:05', Tests: [], SystemInfo: { OSDescription: 'Synthetic scanner OS', MachineName: 'Synthetic runner' }, PowerShellInfo: { Version: '7.4' }
}, '$', 0);
const snapshot: EnvironmentSnapshot = {
version: 1, projectId: 'project-1', scanRunIds: ['run-1'], generatedAt: '2026-09-09T08:00:00Z', sections: [],
observations: context.environmentObservations.map((observation, index) => ({ ...observation, id: `observation-${index}`, tool: { id: 'maester', name: 'Maester' }, scanRunId: 'run-1', importFileId: 'file-1', mappingVersion: '1.1.0' })),
coverage: { observed: 0, empty: 0, explicitlyAbsent: 0, restricted: 0, incomplete: 0 }
};
it('shows labelled tool and runtime facts without treating the scanner host as the assessed host', () => {
const detail = dashboardEnvironmentDetail(snapshot);
expect(detail.toolContext).toContainEqual({ label: 'Maester version', value: '1.2' });
expect(detail.toolContext).toContainEqual({ label: 'Maester Scanner operating system', value: 'Synthetic scanner OS' });
expect(detail.toolContext).toContainEqual({ label: 'Maester PowerShell version', value: '7.4' });
expect(detail.inventory).toContainEqual({ label: 'Assessed host', value: '—' });
});
it('counts distinct reported tenants and does not invent an absent tenant', () => {
expect(dashboardEntraTenantCount(snapshot)).toBe(1);
const tenant = snapshot.observations.find(observation => observation.property === 'entra.tenant_id')!;
expect(dashboardEntraTenantCount({ ...snapshot, observations: [...snapshot.observations, tenant, { ...tenant, normalizedValue: 'tenant-2' }] })).toBe(2);
expect(dashboardEntraTenantCount()).toBeUndefined();
expect(dashboardEnvironmentDetail().toolContext.some(item => item.label.startsWith('Maester'))).toBe(false);
});
it('counts and displays a Purple Knight for Entra ID tenant without Maester', () => {
const maesterTenant = snapshot.observations.find(observation => observation.property === 'entra.tenant_name')!;
const purpleKnightTenant = {
...maesterTenant, id: 'pk-tenant', tool: { id: 'purple-knight', name: 'Purple Knight for Entra ID' },
property: 'entra.tenant_name', subject: { type: 'entra-tenant', identity: 'synthetic.onmicrosoft.com' },
originalValue: 'synthetic.onmicrosoft.com', normalizedValue: 'synthetic.onmicrosoft.com'
};
const purpleKnightSnapshot = { ...snapshot, observations: [purpleKnightTenant] };
expect(dashboardEntraTenantCount(purpleKnightSnapshot)).toBe(1);
expect(dashboardDomainInformation(purpleKnightSnapshot)).toContainEqual({
label: 'Entra ID', value: 'synthetic.onmicrosoft.com'
});
});
});