Skip to content

Commit 576a813

Browse files
committed
[frontend/backend] stix filtering tests
1 parent 527c3e9 commit 576a813

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

opencti-platform/opencti-graphql/tests/02-dataInjection/01-dataCount/filterGroup-test.js renamed to opencti-platform/opencti-graphql/tests/02-dataInjection/01-dataCount/dynamicFiltering-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import { getFakeAuthUser } from '../../utils/domainQueryHelper';
2626
import { SETTINGS_SET_ACCESSES } from '../../../src/utils/access';
2727
import { ENTITY_TYPE_MALWARE_ANALYSIS } from '../../../src/modules/malwareAnalysis/malwareAnalysis-types';
2828

29-
// File to test dynamic filtering with different keys, operators, modes, combinations
29+
// -- File to test dynamic filtering (filtering of data in elastic)
30+
// -- with different keys, operators, modes, combinations
3031

3132
// test queries involving dynamic filters
3233

opencti-platform/opencti-graphql/tests/03-integration/01-database/filters-test.js renamed to opencti-platform/opencti-graphql/tests/03-integration/01-database/stixFiltering-test.js

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { isEmptyField } from '../../../src/database/utils';
55
import { ENTITY_TYPE_INTRUSION_SET } from '../../../src/schema/stixDomainObject';
66
import { isStixMatchFilterGroup_MockableForUnitTests } from '../../../src/utils/filtering/filtering-stix/stix-filtering';
77

8+
// -- File to test stix filtering (filters on events: in the context of playbooks, streams, triggers)
9+
// -- with different keys, operators, modes, combinations
10+
811
const WHITE_TLP = { standard_id: 'marking-definition--613f2e26-407d-48c7-9eca-b8e91df99dc9', internal_id: null };
912

1013
const applyFilters = async (filters, user = ADMIN_USER) => {
@@ -131,7 +134,7 @@ describe('Filters testing', () => {
131134
// assignee_filter
132135

133136
it('Should labels filters correctly applied', async () => {
134-
// With eq on marking
137+
// With eq
135138
const filters = {
136139
mode: 'and',
137140
filters: [{
@@ -144,7 +147,7 @@ describe('Filters testing', () => {
144147
};
145148
const filteredObjects = await applyFilters(filters);
146149
expect(filteredObjects.length).toBe(2);
147-
// With _not_eq
150+
// With not_eq
148151
const filtersNot = {
149152
mode: 'and',
150153
filters: [{
@@ -158,6 +161,73 @@ describe('Filters testing', () => {
158161
const filteredObjectsNot = await applyFilters(filtersNot);
159162
expect(stixBundle.objects.length - filteredObjects.length).toBe(filteredObjectsNot.length);
160163
});
164+
it('Should labels filters correctly applied with only_eq_to operator', async () => {
165+
// With only_eq_to
166+
let filters = {
167+
mode: 'and',
168+
filters: [{
169+
key: ['objectLabel'],
170+
values: ['identity'],
171+
operator: 'only_eq_to',
172+
mode: 'or',
173+
}],
174+
filterGroups: [],
175+
};
176+
let filteredObjects = await applyFilters(filters);
177+
expect(filteredObjects.length).toBe(10);
178+
// With not_only_eq_to
179+
let filtersNot = {
180+
mode: 'and',
181+
filters: [{
182+
key: ['objectLabel'],
183+
values: ['attack-pattern'],
184+
operator: 'not_only_eq_to',
185+
mode: 'or',
186+
}],
187+
filterGroups: [],
188+
};
189+
let filteredObjectsNot = await applyFilters(filtersNot);
190+
expect(stixBundle.objects.length - filteredObjects.length).toBe(filteredObjectsNot.length);
191+
// With only_eq_to & AND local mode
192+
filters = {
193+
mode: 'and',
194+
filters: [{
195+
key: ['objectLabel'],
196+
values: ['identity', 'organization'],
197+
operator: 'only_eq_to',
198+
mode: 'and',
199+
}],
200+
filterGroups: [],
201+
};
202+
filteredObjects = await applyFilters(filters);
203+
// With not_only_eq_to & AND local mode
204+
filtersNot = {
205+
mode: 'and',
206+
filters: [{
207+
key: ['objectLabel'],
208+
values: ['identity', 'organization'],
209+
operator: 'not_only_eq_to',
210+
mode: 'and',
211+
}],
212+
filterGroups: [],
213+
};
214+
filteredObjectsNot = await applyFilters(filtersNot);
215+
expect(stixBundle.objects.length - filteredObjects.length).toBe(filteredObjectsNot.length);
216+
expect(filteredObjects.map((n) => n.node.name).includes('ANSSI')).toBeFalsy();
217+
// With only_eq_to & OR local mode
218+
filters = {
219+
mode: 'and',
220+
filters: [{
221+
key: ['objectLabel'],
222+
values: ['identity', 'organization'],
223+
operator: 'only_eq_to',
224+
mode: 'or',
225+
}],
226+
filterGroups: [],
227+
};
228+
filteredObjects = await applyFilters(filters);
229+
expect(filteredObjects.length).toBe(10);
230+
});
161231

162232
// revoked
163233

opencti-platform/opencti-graphql/tests/data/DATA-TEST-STIX2_v2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"spec_version": "2.1",
99
"name": "ANSSI",
1010
"identity_class": "organization",
11-
"labels": ["identity"],
11+
"labels": ["identity", "organization"],
1212
"created": "2020-02-23T23:40:53.575Z",
1313
"modified": "2020-02-27T08:45:39.351Z",
1414
"x_opencti_organization_type": "CSIRT",
@@ -57,7 +57,7 @@
5757
"id": "threat-actor--dfaa8d77-07e2-4e28-b2c8-92e9f7b04429",
5858
"created": "2018-11-19T23:39:03.893Z",
5959
"modified": "2018-11-19T23:39:03.893Z",
60-
"name": "Jhon Threat Actor Individual",
60+
"name": "John Threat Actor Individual",
6161
"description": "This organized threat actor individual.",
6262
"threat_actor_types": [
6363
"crime-syndicate"

0 commit comments

Comments
 (0)