Skip to content

Commit

Permalink
Add trigger of tasks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aHenryJard committed Sep 20, 2024
1 parent 828ef26 commit 33f0c27
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
5 changes: 0 additions & 5 deletions opencti-platform/opencti-graphql/src/database/stix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,20 +1177,15 @@ export const isRelationBuiltin = (instance: StoreRelation): boolean => {
};

export const checkRelationshipRef = (fromType: string, toType: string, relationshipType: string) => {
logApp.info(`ANGIE checkRelationshipRef - from:${fromType}, to:${toType}, relationshipType:${relationshipType}`);
const relationRefs = schemaRelationsRefDefinition.getRelationsRef(fromType).filter((rel) => {
logApp.info(`ANGIE checkRelationshipRef - ${rel.databaseName} ?? ${relationshipType}`);
return rel.databaseName === relationshipType;
});
logApp.info(`ANGIE checkRelationshipRef - relationRefs.length:${relationRefs.length}`);
if (relationRefs.length === 0) {
throw FunctionalError('The relationship is not allowed', { type: relationshipType, from: fromType, to: toType });
}
if (relationRefs.length > 1) {
throw FunctionalError('Invalid relationship schema', { type: relationshipType, from: fromType, to: toType, data: relationRefs });
}

logApp.info(`ANGIE relationRefs[0]=${relationRefs[0].toTypes}`);
if (!relationRefs[0].isRefExistingForTypes(fromType, toType)) {
throw FunctionalError('The relationship is not allowed', { type: relationshipType, from: fromType, to: toType });
}
Expand Down
3 changes: 1 addition & 2 deletions opencti-platform/opencti-graphql/src/manager/taskManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ const executeRuleElementRescan = async (context, user, actionContext, element) =
}
};
export const executeShare = async (context, user, actionContext, element) => {
logApp.info('ANGIE executeShare', { actionContext, element });
const { values } = actionContext;
for (let indexCreate = 0; indexCreate < values.length; indexCreate += 1) {
const target = values[indexCreate];
Expand Down Expand Up @@ -550,7 +549,7 @@ const executeProcessing = async (context, user, job, scope) => {
return errors;
};

const taskHandler = async () => {
export const taskHandler = async () => {
let lock;
try {
// Lock the manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,14 +728,14 @@ export const objectOrganization: RefAttribute = {
multiple: true,
upsert: true,
isRefExistingForTypes(this, fromType, toType) {
logApp.info(`ANGIE isRefExistingForTypes this.type:${this.type}, fromType:${fromType}, toType:${toType} `);
// TODO understand the impact of this
return !(fromType === ENTITY_TYPE_EVENT /* || isStixDomainObjectIdentity(fromType) */
|| isStixDomainObjectLocation(fromType))
&& this.toTypes.includes(toType);
},
datable: false,
isFilterable: true,
toTypes: [ENTITY_TYPE_IDENTITY_ORGANIZATION], // ANGIE
toTypes: [ENTITY_TYPE_IDENTITY_ORGANIZATION],
};

export const objectAssignee: RefAttribute = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { adminQueryWithSuccess, queryAsUserWithSuccess } from '../../utils/testQueryHelper';
import { findById } from '../../../src/domain/report';
import { execChildPython } from '../../../src/python/pythonBridge';
import { wait } from '../../../src/database/utils';
import { taskHandler } from '../../../src/manager/taskManager';

const READ_QUERY = gql`
query caseIncident($id: String!) {
Expand Down Expand Up @@ -141,8 +141,8 @@ describe('Organization sharing standard behavior for container', () => {
expect(organizationSharingQueryResult?.data?.stixCoreObjectEdit.restrictionOrganizationAdd).not.toBeNull();
expect(organizationSharingQueryResult?.data?.stixCoreObjectEdit.restrictionOrganizationAdd.objectOrganization[0].name).toEqual(TEST_ORGANIZATION.name);

// Wait for background task magic to happens
await wait(5000);
// Need background task magic to happens for sharing
await taskHandler();
});
it('should Editor user access all objects', async () => {
const REPORT_STIX_DOMAIN_ENTITIES = gql`
Expand Down

0 comments on commit 33f0c27

Please sign in to comment.