Skip to content

Commit

Permalink
[backend] Fix on instance trigger incorrect message when updating the…
Browse files Browse the repository at this point in the history
… standard Id (#6198)
  • Loading branch information
Kedae authored and Archidoit committed Jun 3, 2024
1 parent 1f70f0d commit d43657a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ENTITY_TYPE_RESOLVED_FILTERS } from '../../schema/stixDomainObject';
import { extractFilterGroupValues, isFilterGroupNotEmpty } from './filtering-utils';
import { ENTITY_TYPE_STATUS } from '../../schema/internalObject';
import type { BasicWorkflowStatus } from '../../types/store';
import { STIX_EXT_OCTI } from '../../types/stix-extensions';

// list of all filters that needs resolution
export const RESOLUTION_FILTERS = [
Expand Down Expand Up @@ -125,7 +126,7 @@ export const resolveFilterGroup = async (
/**
* Build a resolution map thanks to the cache
*/
const buildResolutionMapForFilter = async (context: AuthContext, user: AuthUser, filter: Filter, cache: Map<string, StixObject>) : Promise<FilterResolutionMap> => {
const buildResolutionMapForFilter = async (context: AuthContext, user: AuthUser, filter: Filter, cache: Map<string, StixObject>): Promise<FilterResolutionMap> => {
const map: Map<string, string> = new Map();
if (Object.keys(STIX_RESOLUTION_MAP_PATHS).includes(filter.key[0])) {
for (let index = 0; index < filter.values.length; index += 1) {
Expand All @@ -139,8 +140,9 @@ const buildResolutionMapForFilter = async (context: AuthContext, user: AuthUser,
if (!(await isUserCanAccessStixElement(context, user, cachedObject))) {
// invalidate the filter value; it won't match ever, but we keep track of this invalidation for debug purposes
map.set(v, '<restricted-or-deleted>');
} else if (filter.key[0] === CONNECTED_TO_INSTANCE_FILTER) {
map.set(v, cachedObject.extensions[STIX_EXT_OCTI].id);
} else {
// resolve according to path
const cachedValue = cachedObject[path];
if (typeof cachedValue === 'string') {
map.set(v, cachedValue);
Expand All @@ -153,7 +155,7 @@ const buildResolutionMapForFilter = async (context: AuthContext, user: AuthUser,
return map;
};

const mergeMaps = <K, V>(mapArray: Map<K, V>[]) : Map<K, V> => {
const mergeMaps = <K, V>(mapArray: Map<K, V>[]): Map<K, V> => {
const mergedMap = new Map<K, V>();

mapArray.forEach((map) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const testConnectedTo = (stix: any, filter: Filter) => {
if (filter.operator && filter.operator !== 'eq') {
return false;
}
return testStringFilter(filter, [stix.id]);
return testStringFilter(filter, [stix.extensions[STIX_EXT_OCTI].id]);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ describe('Stix filter testers', () => {
key: ['connectedToId'],
mode: 'or',
operator: 'eq',
values: ['<some-id>', 'report--f3e554eb-60f5-587c-9191-4f25e9ba9f32']
values: ['<some-id>', 'f13cd64f-9268-4d77-9850-eb6fbe322463']
} as Filter;
expect(testers.testConnectedTo(stixReport, filter)).toEqual(true);
expect(testers.testConnectedTo(stixSighting, filter)).toEqual(false);
Expand Down

0 comments on commit d43657a

Please sign in to comment.