Assessor_2.0/tests/domain/result-db-supplemental-disc...

73 lines
3.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { EnvironmentObservation } from '../../src/domain/environment-context';
import {
discloseSupplementalObservation,
RESULT_DB_SUPPLEMENTAL_DISCLOSURE_POLICY_VERSION
} from '../../src/domain/result-db-supplemental-disclosure';
function observation(overrides: Partial<EnvironmentObservation> = {}): EnvironmentObservation {
return {
version: 1,
id: 'synthetic-observation',
scanRunId: 'synthetic-run',
importFileId: 'synthetic-file',
tool: { id: 'pingcastle', name: 'PingCastle', version: 'synthetic' },
subject: { type: 'domain-information', identity: 'private.synthetic.example', label: 'Private Customer' },
property: 'domain.functional_level',
label: 'Customer supplied label',
originalValue: 'Windows Server 2016 for Private Customer',
normalizedValue: 2016,
valueType: 'number',
state: 'observed',
source: { objectPath: 'html/private/customer/path' },
mappingVersion: 'synthetic',
attributes: { customer: 'Private Customer' },
...overrides
};
}
describe('Result DB supplemental disclosure boundary', () => {
it('rebuilds an approved value from controlled metadata without carrying source identity or raw context', () => {
const disclosed = discloseSupplementalObservation(observation());
expect(disclosed).toEqual({
policyVersion: RESULT_DB_SUPPLEMENTAL_DISCLOSURE_POLICY_VERSION,
disclosureClass: 'technical-metadata',
property: 'domain.functional_level',
title: 'Domain functional level',
subjectType: 'active-directory-environment',
value: 2016,
valueType: 'number',
state: 'observed'
});
expect(JSON.stringify(disclosed)).not.toMatch(/Private Customer|private\.synthetic|customer\/path/i);
});
it('fails closed for identifying, unknown, future-tool and malformed supplemental values', () => {
expect(discloseSupplementalObservation(observation({
property: 'domain.fqdn', normalizedValue: 'private.synthetic.example', valueType: 'string'
}))).toBeUndefined();
expect(discloseSupplementalObservation(observation({
property: 'future.private.field', normalizedValue: 'Private Customer', valueType: 'string'
}))).toBeUndefined();
expect(discloseSupplementalObservation(observation({
tool: { id: 'future-scanner', name: 'Future Scanner' }
}))).toBeUndefined();
expect(discloseSupplementalObservation(observation({
normalizedValue: '2016.private.synthetic.example', valueType: 'string'
}))).toBeUndefined();
});
it('allows bounded aggregate and boolean configuration values only', () => {
expect(discloseSupplementalObservation(observation({
property: 'risk.domain', normalizedValue: 42, originalValue: 'Private score 42'
}))).toMatchObject({ value: 42, disclosureClass: 'aggregate' });
expect(discloseSupplementalObservation(observation({
property: 'domain.recycle_bin_enabled', normalizedValue: true, originalValue: 'Private enabled', valueType: 'boolean'
}))).toMatchObject({ value: true, disclosureClass: 'configuration-state' });
expect(discloseSupplementalObservation(observation({
property: 'risk.domain', normalizedValue: 101
}))).toBeUndefined();
});
});