Skip to content

Commit

Permalink
[backend] improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
labo-flg committed Feb 23, 2024
1 parent 93496ec commit ea5aee0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export const stixCoreObjectImportPush = async (context, user, id, file, noTrigge
await elUpdateElement({
_index: previous._index,
internal_id: internalId,
entity_type: previous.entity_type,
entity_type: previous.entity_type, // required for schema validation
updated_at: now(),
x_opencti_files: files
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const isNonFLatObjectAttributeMapping = (schemaDef: AttributeDefinition)
const validateInputAgainstSchema = (input: any, schemaDef: AttributeDefinition) => {
const isMandatory = isMandatoryAttributeMapping(schemaDef);
if (isMandatory && R.isNil(input)) {
throw FunctionalError(`Validation against schema failed on attribute [${schemaDef.name}]: attribute is mandatory but not present`);
throw FunctionalError(`Validation against schema failed on attribute [${schemaDef.name}]: this mandatory field cannot be nil`, { value: input });
}

if (isNonFLatObjectAttributeMapping(schemaDef)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ describe('validateDataBeforeIndexing', () => {
expect(() => validateDataBeforeIndexing(invalidUser))
.toThrowError('Validation against schema failed on attribute [overrides]: mandatory field [entity_type] is not present');

invalidUser = {
...user,
user_confidence_level: {
max_confidence: null, // mandatory field to null
overrides: [{
max_confidence: 77,
entity_type: 'Report'
}]
},
};
expect(() => validateDataBeforeIndexing(invalidUser))
.toThrowError('Validation against schema failed on attribute [max_confidence]: this mandatory field cannot be nil');

const invalidThreatActorIndividual = {
...threatActorIndividual,
height: [{
Expand Down

0 comments on commit ea5aee0

Please sign in to comment.