Implement uniqueness validation for STIX bundle objects #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements validation to:
idkeyx_mitre_contentsare present in theobjectsarrayChanges
New Features
Reusable Refinement Functions
src/refinements/index.ts: ImplementedvalidateNoDuplicates, which can be used in any schema to validate that no duplicates exist for any key (including composite keys)src/refinements/index.ts: ImplementedvalidateXMitreContentsReferences, which validates that all STIX IDs referenced inx_mitre_contentsactually exist in the bundle'sobjectsarraySTIX Bundle Schema
objectsarary is of typex-mitre-collectionsx_mitre_contentsare present in theobjectsarrayobjectsarrayRefactors
analytics.schema.ts: Replaced custom refinement withvalidateNoDuplicatesfor validating that no duplicate log source references existdata-component.schema.ts: Replaced custom refinement withvalidateNoDuplicatesfor validating that no duplicate log sources inx_mitre_log_sourcesexistdetection-strategy.schema.ts: Replaced custom refinement withvalidateNoDuplicatesfor validating that no duplicate analytic refs inx_mitre_analytic_refsexistTesting
test/objects/detection-strategy.test.ts: Changed one of the test conditions to throw when the schema detections duplicate analytic refstest/objects/stix-bundle.test.ts: Added the following tests'should accept bundle with unique object IDs (true positive)''should reject bundle with duplicate object IDs (true negative)''should report the duplicate ID in error message''should handle multiple duplicates in a single bundle'x_mitre_contentsconstraints:'should accept bundle where all x_mitre_contents references exist in objects (true positive)''should reject bundle where x_mitre_contents references a missing object (true negative)''should report the missing STIX ID in error message''should handle multiple missing references in x_mitre_contents''should accept bundle with mix of valid and present references in x_mitre_contents'**test/refinements/validate-no-duplicates.test.ts:validateNoDuplicatesrefinement factory function.refinements/index.tsin a future change.