Assessor_2.0/tests/features/cve-enrichment-display-orde...

41 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { CveEnrichmentRecord } from '../../src/domain/cve-enrichment';
import { cveFieldsForDisplay } from '../../src/features/project-import/canonical-model-to-dataset';
const enrichment: CveEnrichmentRecord = {
version: 2,
cveId: 'CVE-2012-3037',
source: 'nvd',
sourceIdentifier: 'CVE-2012-3037',
sourceUrl: 'https://nvd.nist.gov/vuln/detail/CVE-2012-3037',
apiVersion: '2.0',
publishedAt: '2012-09-25T11:07:46.470Z',
lastModifiedAt: '2026-06-16T23:42:32.803Z',
fetchedAt: '2026-09-10T10:00:00.000Z',
description: 'Synthetic description.',
vulnerabilityStatus: 'Modified',
metrics: [],
weaknesses: [],
references: [],
affectedConfigurations: [{
operator: 'AND', negate: false,
vulnerableMatches: [{ criteria: 'cpe:2.3:o:example:firmware:*:*:*:*:*:*:*:*' }],
runningOnWith: [{ criteria: 'cpe:2.3:h:example:device:*:*:*:*:*:*:*:*' }]
}],
attributes: {}
};
describe('CVE enrichment display order', () => {
it('places NVD Affected Configurations at the very bottom of the finding fields', () => {
const fields = cveFieldsForDisplay(enrichment);
expect(fields.at(-1)?.label).toBe('NVD Affected Configurations');
expect(fields.findIndex(field => field.label === 'NVD Record'))
.toBeLessThan(fields.findIndex(field => field.label === 'NVD Affected Configurations'));
const value = fields.at(-1)?.value;
expect(typeof value).toBe('string');
expect(value).toContain('### Configuration 1');
expect(value).toContain('| **Running on/with** | |');
expect(String(value).match(/\| CPE \| Version range \|/g)).toHaveLength(1);
});
});