From dc17bfd31af98db1feb0070ca21923a9e0ce6d03 Mon Sep 17 00:00:00 2001 From: marie flores Date: Mon, 16 Sep 2024 17:21:30 +0200 Subject: [PATCH 01/11] [backend] Fix missing entities in shared Report (#8333) --- opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts b/opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts index 9ff70b550859..1cc69735cd26 100644 --- a/opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts +++ b/opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts @@ -186,6 +186,8 @@ export const STIX_ORGANIZATIONS_UNRESTRICTED = [ ABSTRACT_STIX_REF_RELATIONSHIP, ENTITY_TYPE_IDENTITY_ORGANIZATION, ENTITY_TYPE_IDENTITY_SECTOR, + ENTITY_TYPE_IDENTITY_SYSTEM, + ENTITY_TYPE_IDENTITY_INDIVIDUAL, ENTITY_TYPE_LOCATION, ENTITY_TYPE_WORK, // Work is defined as an history object ENTITY_TYPE_TAXII_COLLECTION, // TODO TaxiiCollection must be migrate to add according parent types From 21734381bb995a150fb5098d35b5e0b21c1ce41d Mon Sep 17 00:00:00 2001 From: marie flores Date: Wed, 18 Sep 2024 08:57:13 +0200 Subject: [PATCH 02/11] [backend] WIP: test (#8333) --- .../opencti-graphql/src/database/stix.ts | 20 +- .../src/manager/taskManager.js | 3 +- .../stixDomainObject-registrationRef.ts | 2 +- .../src/schema/stixDomainObject.ts | 2 - .../src/schema/stixRefRelationship.ts | 6 +- .../container-organization-sharing-test.ts | 200 ++++++++++++++++ .../04-manager/taskManager-test.ts | 13 +- .../tests/data/DATA-TEST-STIX2_v2.json | 213 ++++++++++++++++++ 8 files changed, 448 insertions(+), 11 deletions(-) create mode 100644 opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts diff --git a/opencti-platform/opencti-graphql/src/database/stix.ts b/opencti-platform/opencti-graphql/src/database/stix.ts index 2bf6aa8b0cbe..629850f50597 100644 --- a/opencti-platform/opencti-graphql/src/database/stix.ts +++ b/opencti-platform/opencti-graphql/src/database/stix.ts @@ -76,7 +76,7 @@ import { RELATION_USES, RELATION_VARIANT_OF } from '../schema/stixCoreRelationship'; -import { isStixRefRelationship } from '../schema/stixRefRelationship'; +import { isStixRefRelationship, RELATION_GRANTED_TO } from '../schema/stixRefRelationship'; import { ABSTRACT_STIX_CYBER_OBSERVABLE, ENTITY_TYPE_THREAT_ACTOR } from '../schema/general'; import { ENTITY_TYPE_EVENT } from '../modules/event/event-types'; import { ENTITY_TYPE_NARRATIVE } from '../modules/narrative/narrative-types'; @@ -89,6 +89,7 @@ import { FunctionalError, UnsupportedError } from '../config/errors'; import { ENTITY_TYPE_THREAT_ACTOR_INDIVIDUAL } from '../modules/threatActorIndividual/threatActorIndividual-types'; import { ENTITY_TYPE_IDENTITY_ORGANIZATION } from '../modules/organization/organization-types'; import { ENTITY_TYPE_INDICATOR } from '../modules/indicator/indicator-types'; +import { logApp } from '../config/conf'; const MAX_TRANSIENT_STIX_IDS = 200; export const STIX_SPEC_VERSION = '2.1'; @@ -267,7 +268,8 @@ export const stixCoreRelationshipsMapping: RelationshipMappings = { { name: RELATION_PART_OF, type: REL_NEW } ], [`${ENTITY_TYPE_IDENTITY_INDIVIDUAL}_${ENTITY_TYPE_IDENTITY_ORGANIZATION}`]: [ - { name: RELATION_PART_OF, type: REL_NEW } + { name: RELATION_PART_OF, type: REL_NEW }, + { name: RELATION_GRANTED_TO, type: REL_BUILT_IN } ], [`${ENTITY_TYPE_IDENTITY_INDIVIDUAL}_${ENTITY_TYPE_LOCATION_POSITION}`]: [ { name: RELATION_LOCATED_AT, type: REL_BUILT_IN } @@ -307,10 +309,14 @@ export const stixCoreRelationshipsMapping: RelationshipMappings = { [`${ENTITY_TYPE_IDENTITY_SECTOR}_${ENTITY_TYPE_LOCATION_REGION}`]: [ { name: RELATION_LOCATED_AT, type: REL_BUILT_IN } ], + [`${ENTITY_TYPE_IDENTITY_SECTOR}_${ENTITY_TYPE_IDENTITY_ORGANIZATION}`]: [ + { name: RELATION_GRANTED_TO, type: REL_BUILT_IN } + ], // endregion // region SYSTEM [`${ENTITY_TYPE_IDENTITY_SYSTEM}_${ENTITY_TYPE_IDENTITY_ORGANIZATION}`]: [ - { name: RELATION_BELONGS_TO, type: REL_EXTENDED } + { name: RELATION_BELONGS_TO, type: REL_EXTENDED }, + { name: RELATION_GRANTED_TO, type: REL_BUILT_IN } ], [`${ENTITY_TYPE_IDENTITY_SYSTEM}_${ENTITY_TYPE_LOCATION_POSITION}`]: [ { name: RELATION_LOCATED_AT, type: REL_BUILT_IN } @@ -1171,7 +1177,12 @@ export const isRelationBuiltin = (instance: StoreRelation): boolean => { }; export const checkRelationshipRef = (fromType: string, toType: string, relationshipType: string) => { - const relationRefs = schemaRelationsRefDefinition.getRelationsRef(fromType).filter((rel) => rel.databaseName === relationshipType); + 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 }); } @@ -1179,6 +1190,7 @@ export const checkRelationshipRef = (fromType: string, toType: string, relations 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 }); } diff --git a/opencti-platform/opencti-graphql/src/manager/taskManager.js b/opencti-platform/opencti-graphql/src/manager/taskManager.js index 7b42fcbc11fd..7d928d07494f 100644 --- a/opencti-platform/opencti-graphql/src/manager/taskManager.js +++ b/opencti-platform/opencti-graphql/src/manager/taskManager.js @@ -401,7 +401,8 @@ const executeRuleElementRescan = async (context, user, actionContext, element) = } } }; -const executeShare = 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]; diff --git a/opencti-platform/opencti-graphql/src/modules/relationsRef/stixDomainObject-registrationRef.ts b/opencti-platform/opencti-graphql/src/modules/relationsRef/stixDomainObject-registrationRef.ts index 9ca4141e7f2e..35d5ef503469 100644 --- a/opencti-platform/opencti-graphql/src/modules/relationsRef/stixDomainObject-registrationRef.ts +++ b/opencti-platform/opencti-graphql/src/modules/relationsRef/stixDomainObject-registrationRef.ts @@ -67,7 +67,7 @@ schemaRelationsRefDefinition.registerRelationsRef(ENTITY_TYPE_CONTAINER_GROUPING schemaRelationsRefDefinition.registerRelationsRef(ENTITY_TYPE_VULNERABILITY, [objectOrganization]); schemaRelationsRefDefinition.registerRelationsRef(ENTITY_TYPE_IDENTITY_SYSTEM, [objectOrganization]); -schemaRelationsRefDefinition.registerRelationsRef(ENTITY_TYPE_IDENTITY_SECTOR, []); +schemaRelationsRefDefinition.registerRelationsRef(ENTITY_TYPE_IDENTITY_SECTOR, [objectOrganization]); schemaRelationsRefDefinition.registerRelationsRef(ENTITY_TYPE_IDENTITY_INDIVIDUAL, [objectOrganization]); schemaRelationsRefDefinition.registerRelationsRef(ENTITY_TYPE_LOCATION_REGION, []); diff --git a/opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts b/opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts index 1cc69735cd26..9ff70b550859 100644 --- a/opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts +++ b/opencti-platform/opencti-graphql/src/schema/stixDomainObject.ts @@ -186,8 +186,6 @@ export const STIX_ORGANIZATIONS_UNRESTRICTED = [ ABSTRACT_STIX_REF_RELATIONSHIP, ENTITY_TYPE_IDENTITY_ORGANIZATION, ENTITY_TYPE_IDENTITY_SECTOR, - ENTITY_TYPE_IDENTITY_SYSTEM, - ENTITY_TYPE_IDENTITY_INDIVIDUAL, ENTITY_TYPE_LOCATION, ENTITY_TYPE_WORK, // Work is defined as an history object ENTITY_TYPE_TAXII_COLLECTION, // TODO TaxiiCollection must be migrate to add according parent types diff --git a/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts b/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts index 3265a43ab416..02db08f1d835 100644 --- a/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts +++ b/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts @@ -51,6 +51,7 @@ import { ENTITY_WINDOWS_REGISTRY_VALUE_TYPE } from './stixCyberObservable'; import { ATTRIBUTE_SAMPLE } from '../modules/malwareAnalysis/malwareAnalysis-types'; +import { logApp } from '../config/conf'; export const ABSTRACT_STIX_NESTED_REF_RELATIONSHIP = 'stix-nested-ref-relationship'; // Only for front usage @@ -727,13 +728,14 @@ export const objectOrganization: RefAttribute = { multiple: true, upsert: true, isRefExistingForTypes(this, fromType, toType) { - return !(fromType === ENTITY_TYPE_EVENT || isStixDomainObjectIdentity(fromType) + logApp.info(`ANGIE isRefExistingForTypes this.type:${this.type}, fromType:${fromType}, toType:${toType} `); + return !(fromType === ENTITY_TYPE_EVENT /* || isStixDomainObjectIdentity(fromType) */ || isStixDomainObjectLocation(fromType)) && this.toTypes.includes(toType); }, datable: false, isFilterable: true, - toTypes: [ENTITY_TYPE_IDENTITY_ORGANIZATION], + toTypes: [ENTITY_TYPE_IDENTITY_ORGANIZATION], // ANGIE }; export const objectAssignee: RefAttribute = { diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts new file mode 100644 index 000000000000..868417b926e2 --- /dev/null +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts @@ -0,0 +1,200 @@ +import { describe, expect, it } from 'vitest'; +import gql from 'graphql-tag'; +import { + ADMIN_API_TOKEN, + ADMIN_USER, + adminQuery, + API_URI, + FIVE_MINUTES, + getOrganizationIdByName, + PLATFORM_ORGANIZATION, + PYTHON_PATH, + TEST_ORGANIZATION, + testContext, + USER_EDITOR, +} from '../../utils/testQuery'; +import { adminQueryWithSuccess, queryAsUserWithSuccess } from '../../utils/testQueryHelper'; +import { findById } from '../../../src/domain/report'; +import { execChildPython } from '../../../src/python/pythonBridge'; +import { wait } from '../../../src/database/utils'; + +const READ_QUERY = gql` + query caseIncident($id: String!) { + caseIncident(id: $id) { + id + standard_id + name + authorized_members { + id + access_right + } + currentUserAccessRight + } + } +`; + +const DELETE_QUERY = gql` + mutation CaseIncidentDelete($id: ID!) { + caseIncidentDelete(id: $id) + } +`; + +const PLATFORM_ORGANIZATION_QUERY = gql` + mutation PoliciesFieldPatchMutation($id: ID!, $input: [EditInput]!) { + settingsEdit(id: $id) { + fieldPatch(input: $input) { + platform_organization { + id + name + } + enterprise_edition + id + } + } + } +`; + +const ORGANIZATION_SHARING_QUERY = gql` + mutation StixCoreObjectSharingGroupAddMutation( + $id: ID! + $organizationId: ID! + ) { + stixCoreObjectEdit(id: $id) { + restrictionOrganizationAdd(organizationId: $organizationId) { + id + objectOrganization { + id + name + } + } + } + } +`; + +const importOpts: string[] = [API_URI, ADMIN_API_TOKEN, './tests/data/DATA-TEST-STIX2_v2.json']; + +describe('Database provision', () => { + it('Should import creation succeed', async () => { + // Inject data + const execution = await execChildPython(testContext, ADMIN_USER, PYTHON_PATH, 'local_importer.py', importOpts); + expect(execution).not.toBeNull(); + expect(execution.status).toEqual('success'); + }, FIVE_MINUTES); + // Python lib is fixed but we need to wait for a new release + it('Should import update succeed', async () => { + const execution = await execChildPython(testContext, ADMIN_USER, PYTHON_PATH, 'local_importer.py', importOpts); + expect(execution).not.toBeNull(); + expect(execution.status).toEqual('success'); + }, FIVE_MINUTES); +}); + +describe('Organization sharing standard behavior for container', () => { + let reportInternalId: string; + let organizationId: string; + let settingsInternalId: string; + let platformOrganizationId: string; + it('should load Report', async () => { + const report = await findById(testContext, ADMIN_USER, 'report--57162a65-2a58-560b-9a65-47c3f040f3d4'); // Report is in DATA-TEST-STIX_v2.json + reportInternalId = report.internal_id; + }); + it('should plateform organization sharing and EE activated', async () => { // TODO extract set/unset EE and orga platfor in testQueryHelpers + // Get organization id + platformOrganizationId = await getOrganizationIdByName(PLATFORM_ORGANIZATION.name); + + // Get settings ID + const SETTINGS_READ_QUERY = gql` + query settings { + settings { + id + platform_organization { + id + name + } + } + } + `; + const queryResult = await adminQuery({ query: SETTINGS_READ_QUERY, variables: {} }); + settingsInternalId = queryResult.data?.settings?.id; + + // Set plateform organization + const platformOrganization = await adminQueryWithSuccess({ + query: PLATFORM_ORGANIZATION_QUERY, + variables: { + id: settingsInternalId, + input: [ + { key: 'platform_organization', value: platformOrganizationId }, + { key: 'enterprise_edition', value: new Date().getTime() }, + ] + } + }); + expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization).not.toBeUndefined(); + expect(platformOrganization?.data?.settingsEdit.fieldPatch.enterprise_edition).not.toBeUndefined(); + expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization.name).toEqual(PLATFORM_ORGANIZATION.name); + }); + it('should share Report with Organization', async () => { + // Get organization id + organizationId = await getOrganizationIdByName(TEST_ORGANIZATION.name); + const organizationSharingQueryResult = await adminQueryWithSuccess({ + query: ORGANIZATION_SHARING_QUERY, + variables: { id: reportInternalId, organizationId } + }); + 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); + }); + it('should Editor user access all objects', async () => { + const REPORT_STIX_DOMAIN_ENTITIES = gql` + query report($id: String!) { + report(id: $id) { + id + standard_id + objects(first: 30) { + edges { + node { + ... on BasicObject { + id + standard_id + } + ... on BasicRelationship { + id + standard_id + } + } + } + } + } + } + `; + const queryResult = await queryAsUserWithSuccess(USER_EDITOR.client, { + query: REPORT_STIX_DOMAIN_ENTITIES, + variables: { id: reportInternalId }, + }); + expect(queryResult.data.report.objects.edges.length).toEqual(10); + }); + it.skip('should delete Report', async () => { + // Delete the case + await adminQuery({ + query: DELETE_QUERY, + variables: { id: reportInternalId }, + }); + // Verify is no longer found + const queryResult = await adminQueryWithSuccess({ query: READ_QUERY, variables: { id: reportInternalId } }); + expect(queryResult?.data?.caseIncident).toBeNull(); + }); + it.skip('should plateform organization sharing and EE deactivated', async () => { + // Remove plateform organization + const platformOrganization = await adminQueryWithSuccess({ + query: PLATFORM_ORGANIZATION_QUERY, + variables: { + id: settingsInternalId, + input: [ + { key: 'platform_organization', value: [] }, + { key: 'enterprise_edition', value: [] }, + ] + } + }); + expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization).toBeNull(); + }); +}); diff --git a/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts index bef51aef190d..7f706689ecc3 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts @@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import type { BasicStoreEntity } from '../../../src/types/store'; import { addIndicator, promoteIndicatorToObservables } from '../../../src/modules/indicator/indicator-domain'; import { addStixCyberObservable, promoteObservableToIndicator, stixCyberObservableDelete } from '../../../src/domain/stixCyberObservable'; -import { executePromoteIndicatorToObservables, executePromoteObservableToIndicator, executeReplace } from '../../../src/manager/taskManager'; +import { executePromoteIndicatorToObservables, executePromoteObservableToIndicator, executeReplace, executeShare } from '../../../src/manager/taskManager'; import type { AuthContext } from '../../../src/types/user'; import { ADMIN_USER, TEST_ORGANIZATION, testContext } from '../../utils/testQuery'; import { MARKING_TLP_AMBER, MARKING_TLP_CLEAR } from '../../../src/schema/identifier'; @@ -362,4 +362,15 @@ describe('TaskManager executePromote tests', () => { createdObservableId = createdObservables.map(({ id }) => id); }); }); + + /* describe('TaskManager execute SHARE ', () => { + it('Enable EE and platform Organisation', async () => { + + }); + + it('SHARE a report', async () => { + await executeShare(testContext, ADMIN_USER,); + }); + }); + */ }); diff --git a/opencti-platform/opencti-graphql/tests/data/DATA-TEST-STIX2_v2.json b/opencti-platform/opencti-graphql/tests/data/DATA-TEST-STIX2_v2.json index de2f6ee8d15a..5877ef83d0fc 100644 --- a/opencti-platform/opencti-graphql/tests/data/DATA-TEST-STIX2_v2.json +++ b/opencti-platform/opencti-graphql/tests/data/DATA-TEST-STIX2_v2.json @@ -982,6 +982,219 @@ "stop_time": "2020-02-29T23:00:00.000Z", "created_by_ref": "identity--7b82b010-b1c0-4dae-981f-7756374a17df", "object_marking_refs": ["marking-definition--78ca4366-f5b8-4764-83f7-34ce38198e27"] + }, + { + "id": "report--57162a65-2a58-560b-9a65-47c3f040f3d4", + "spec_version": "2.1", + "revoked": false, + "confidence": 100, + "created": "2024-09-12T09:47:15.000Z", + "modified": "2024-09-17T08:52:19.988Z", + "name": "organization sharing test", + "published": "2024-09-12T09:47:15.000Z", + "x_opencti_workflow_id": "19b6920b-9e66-4c3d-9b2e-d2bf072679a6", + "labels": [ + "test" + ], + "x_opencti_id": "b2412082-1829-4cdc-afd8-0eb466a9d1c8", + "x_opencti_type": "Report", + "type": "report", + "object_refs": [ + "ipv4-addr--cbd67181-b9f8-595b-8bc3-3971e34fa1cc", + "identity--08e1548d-f976-57df-97fc-286e6fb4e6ff", + "identity--01d38593-14c7-5bb1-b8b5-2f6f3809858c", + "identity--000a81f3-b583-51f6-81cd-21b52e322a7a", + "file--86b44f11-7d87-59b4-abf2-045fa0d98172", + "identity--09d26702-b557-58ef-86cb-f511909943c5", + "location--0359730b-8b68-596e-ad90-92f5e5f05062", + "location--45471973-3952-5edd-97b8-5341505abd20", + "indicator--0036303b-99e3-5ed2-9498-49c1ba8409dd", + "attack-pattern--90a3f7f1-d15e-5756-80cb-0f3b84be23b7" + ] + }, + { + "id": "ipv4-addr--cbd67181-b9f8-595b-8bc3-3971e34fa1cc", + "spec_version": "2.1", + "x_opencti_description": "this is a test", + "x_opencti_score": 0, + "value": "1.1.1.1", + "x_opencti_id": "c93f1a85-30fe-4c42-b874-5833e50946ae", + "x_opencti_type": "IPv4-Addr", + "type": "ipv4-addr" + }, + { + "id": "identity--e52b2fa3-2af0-5e53-ad38-17d54b3d61cb", + "spec_version": "2.1", + "identity_class": "organization", + "name": "AlienVault", + "x_opencti_reliability": "D - Not usually reliable", + "created": "2023-08-20T17:43:55.001Z", + "modified": "2024-07-16T15:06:24.952Z", + "x_opencti_organization_type": "vendor", + "x_opencti_id": "af7eb059-fee9-4a82-8587-ce9a7dda441a", + "x_opencti_type": "Organization", + "type": "identity" + }, + { + "id": "identity--08e1548d-f976-57df-97fc-286e6fb4e6ff", + "spec_version": "2.1", + "revoked": false, + "confidence": 45, + "created": "2023-08-23T06:05:34.697Z", + "modified": "2024-09-09T13:01:36.274Z", + "identity_class": "class", + "name": "Public Health", + "x_opencti_id": "8df446ee-4c5a-4b83-b175-cbfe5c3cdce3", + "x_opencti_type": "Sector", + "type": "identity", + "created_by_ref": "identity--e52b2fa3-2af0-5e53-ad38-17d54b3d61cb" + }, + { + "id": "identity--01d38593-14c7-5bb1-b8b5-2f6f3809858c", + "spec_version": "2.1", + "revoked": false, + "confidence": 100, + "created": "2024-03-28T09:18:58.835Z", + "modified": "2024-03-28T09:21:22.628Z", + "identity_class": "individual", + "name": "Indivual A", + "x_opencti_aliases": [ + "IndA", + "IndA ter" + ], + "x_opencti_id": "4e4a32a1-fe3b-43eb-824b-b6c3c5d92c39", + "x_opencti_type": "Individual", + "type": "identity" + }, + { + "id": "identity--000a81f3-b583-51f6-81cd-21b52e322a7a", + "spec_version": "2.1", + "revoked": false, + "confidence": 100, + "created": "2024-02-27T20:23:49.779Z", + "modified": "2024-09-12T13:28:26.033Z", + "identity_class": "system", + "name": "Gootkit C&C", + "x_opencti_id": "ad921110-2611-450a-b3d4-50197e4c9d45", + "x_opencti_type": "System", + "type": "identity" + }, + { + "id": "file--86b44f11-7d87-59b4-abf2-045fa0d98172", + "spec_version": "2.1", + "name": "activeds.dll", + "x_opencti_id": "9d3ed2cf-75bc-40f8-aeb0-b4448c3a2132", + "x_opencti_type": "StixFile", + "type": "file" + }, + { + "id": "identity--09d26702-b557-58ef-86cb-f511909943c5", + "spec_version": "2.1", + "revoked": false, + "confidence": 0, + "created": "2024-02-07T15:24:28.697Z", + "modified": "2024-02-07T15:24:28.697Z", + "identity_class": "organization", + "name": "iop", + "x_opencti_organization_type": "other", + "x_opencti_id": "2d10f4fa-4a78-407f-ac47-d72652aaba49", + "x_opencti_type": "Organization", + "type": "identity" + }, + { + "id": "identity--f29f12ba-3980-5642-9b3e-d11e9b296aed", + "spec_version": "2.1", + "identity_class": "organization", + "name": "Crowdstrike", + "contact_information": "crowdstrike.com", + "created": "2023-11-24T10:03:15.887Z", + "modified": "2024-09-09T13:02:05.899Z", + "x_opencti_id": "a3cf8078-e2f0-4796-8168-2c88008e3d9b", + "x_opencti_type": "Organization", + "type": "identity" + }, + { + "id": "location--0359730b-8b68-596e-ad90-92f5e5f05062", + "spec_version": "2.1", + "revoked": false, + "confidence": 0, + "created": "2023-12-08T09:31:17.992Z", + "modified": "2023-12-08T09:31:20.002Z", + "name": "Slovakia", + "x_opencti_aliases": [ + "SK" + ], + "x_opencti_location_type": "Country", + "country": "Slovakia", + "x_opencti_id": "bbbe2f55-603c-4c2f-a6e5-4fdfe3e9f373", + "x_opencti_type": "Country", + "type": "location", + "created_by_ref": "identity--f29f12ba-3980-5642-9b3e-d11e9b296aed" + }, + { + "id": "location--45471973-3952-5edd-97b8-5341505abd20", + "spec_version": "2.1", + "revoked": false, + "confidence": 0, + "created": "2023-12-08T09:31:17.992Z", + "modified": "2023-12-08T09:31:19.603Z", + "name": "North America", + "x_opencti_location_type": "Region", + "region": "North America", + "x_opencti_id": "431eb49a-a584-4ef7-99b6-3bf4d39a42df", + "x_opencti_type": "Region", + "type": "location", + "created_by_ref": "identity--f29f12ba-3980-5642-9b3e-d11e9b296aed" + }, + { + "id": "identity--b2a8fbec-b4fb-563c-a052-7b5b4ab23070", + "spec_version": "2.1", + "identity_class": "organization", + "name": "Recorded Future", + "contact_information": "recordedfuture.com", + "created": "2023-11-30T08:40:08.623Z", + "modified": "2024-06-06T09:53:22.957Z", + "x_opencti_id": "4a4b8079-399a-4f9d-ad53-53478ae4677f", + "x_opencti_type": "Organization", + "type": "identity" + }, + { + "id": "indicator--0036303b-99e3-5ed2-9498-49c1ba8409dd", + "spec_version": "2.1", + "revoked": false, + "confidence": 0, + "created": "2023-11-30T15:06:07.288Z", + "modified": "2024-09-17T08:52:27.631Z", + "pattern_type": "stix", + "pattern_version": "2.1", + "pattern": "[ipv4-addr:value = '72.18.130.48']", + "name": "72.18.130.48", + "valid_from": "2023-11-30T16:06:07.288Z", + "valid_until": "2024-11-29T16:06:07.288Z", + "x_opencti_score": 92, + "x_opencti_detection": false, + "x_opencti_main_observable_type": "Unknown", + "labels": [ + "test" + ], + "x_opencti_id": "6c19513d-6a44-402c-81ba-44d63bf03b5f", + "x_opencti_type": "Indicator", + "type": "indicator", + "created_by_ref": "identity--b2a8fbec-b4fb-563c-a052-7b5b4ab23070" + }, + { + "id": "attack-pattern--90a3f7f1-d15e-5756-80cb-0f3b84be23b7", + "spec_version": "2.1", + "revoked": false, + "confidence": 0, + "created": "2023-11-30T14:59:09.037Z", + "modified": "2024-09-17T08:52:27.689Z", + "name": "T1190", + "x_mitre_id": "T1190", + "x_opencti_id": "8c0942ab-da38-4b39-9755-9317c8b8a6bb", + "x_opencti_type": "Attack-Pattern", + "type": "attack-pattern", + "created_by_ref": "identity--b2a8fbec-b4fb-563c-a052-7b5b4ab23070" } ] } From e2fd944308fd6ccce0ca2e6c34f1abe6a3112cd2 Mon Sep 17 00:00:00 2001 From: Angelique Date: Fri, 20 Sep 2024 07:32:46 +0200 Subject: [PATCH 03/11] Add trigger of tasks in tests --- opencti-platform/opencti-graphql/src/database/stix.ts | 5 ----- opencti-platform/opencti-graphql/src/manager/taskManager.js | 3 +-- .../opencti-graphql/src/schema/stixRefRelationship.ts | 4 ++-- .../02-resolvers/container-organization-sharing-test.ts | 6 +++--- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/opencti-platform/opencti-graphql/src/database/stix.ts b/opencti-platform/opencti-graphql/src/database/stix.ts index 629850f50597..294251820b0e 100644 --- a/opencti-platform/opencti-graphql/src/database/stix.ts +++ b/opencti-platform/opencti-graphql/src/database/stix.ts @@ -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 }); } diff --git a/opencti-platform/opencti-graphql/src/manager/taskManager.js b/opencti-platform/opencti-graphql/src/manager/taskManager.js index 7d928d07494f..cce7a3a05dec 100644 --- a/opencti-platform/opencti-graphql/src/manager/taskManager.js +++ b/opencti-platform/opencti-graphql/src/manager/taskManager.js @@ -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]; @@ -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 diff --git a/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts b/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts index 02db08f1d835..78cc626bc122 100644 --- a/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts +++ b/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts @@ -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 = { diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts index 868417b926e2..81daa73cb424 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts @@ -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!) { @@ -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` From 61238757af30ce1f02ec3b26aee0bbe566444bdc Mon Sep 17 00:00:00 2001 From: Angelique Date: Fri, 20 Sep 2024 13:59:36 +0200 Subject: [PATCH 04/11] Add enable org method in testQuery --- .../container-organization-sharing-test.ts | 52 ++----------------- .../04-manager/taskManager-test.ts | 6 ++- .../opencti-graphql/tests/utils/testQuery.ts | 2 +- .../tests/utils/testQueryHelper.ts | 48 ++++++++++++++++- 4 files changed, 56 insertions(+), 52 deletions(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts index 81daa73cb424..d20a82d04635 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts @@ -13,7 +13,7 @@ import { testContext, USER_EDITOR, } from '../../utils/testQuery'; -import { adminQueryWithSuccess, queryAsUserWithSuccess } from '../../utils/testQueryHelper'; +import { adminQueryWithSuccess, enableCEAndUnSetOrganization, enableEEAndSetOrganization, queryAsUserWithSuccess } from '../../utils/testQueryHelper'; import { findById } from '../../../src/domain/report'; import { execChildPython } from '../../../src/python/pythonBridge'; import { taskHandler } from '../../../src/manager/taskManager'; @@ -91,45 +91,12 @@ describe('Database provision', () => { describe('Organization sharing standard behavior for container', () => { let reportInternalId: string; let organizationId: string; - let settingsInternalId: string; - let platformOrganizationId: string; it('should load Report', async () => { const report = await findById(testContext, ADMIN_USER, 'report--57162a65-2a58-560b-9a65-47c3f040f3d4'); // Report is in DATA-TEST-STIX_v2.json reportInternalId = report.internal_id; }); - it('should plateform organization sharing and EE activated', async () => { // TODO extract set/unset EE and orga platfor in testQueryHelpers - // Get organization id - platformOrganizationId = await getOrganizationIdByName(PLATFORM_ORGANIZATION.name); - - // Get settings ID - const SETTINGS_READ_QUERY = gql` - query settings { - settings { - id - platform_organization { - id - name - } - } - } - `; - const queryResult = await adminQuery({ query: SETTINGS_READ_QUERY, variables: {} }); - settingsInternalId = queryResult.data?.settings?.id; - - // Set plateform organization - const platformOrganization = await adminQueryWithSuccess({ - query: PLATFORM_ORGANIZATION_QUERY, - variables: { - id: settingsInternalId, - input: [ - { key: 'platform_organization', value: platformOrganizationId }, - { key: 'enterprise_edition', value: new Date().getTime() }, - ] - } - }); - expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization).not.toBeUndefined(); - expect(platformOrganization?.data?.settingsEdit.fieldPatch.enterprise_edition).not.toBeUndefined(); - expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization.name).toEqual(PLATFORM_ORGANIZATION.name); + it('should platform organization sharing and EE activated', async () => { + await enableEEAndSetOrganization(PLATFORM_ORGANIZATION); }); it('should share Report with Organization', async () => { // Get organization id @@ -184,17 +151,6 @@ describe('Organization sharing standard behavior for container', () => { expect(queryResult?.data?.caseIncident).toBeNull(); }); it.skip('should plateform organization sharing and EE deactivated', async () => { - // Remove plateform organization - const platformOrganization = await adminQueryWithSuccess({ - query: PLATFORM_ORGANIZATION_QUERY, - variables: { - id: settingsInternalId, - input: [ - { key: 'platform_organization', value: [] }, - { key: 'enterprise_edition', value: [] }, - ] - } - }); - expect(platformOrganization?.data?.settingsEdit.fieldPatch.platform_organization).toBeNull(); + await enableCEAndUnSetOrganization(); }); }); diff --git a/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts index 7f706689ecc3..197b3a2a58f8 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts @@ -4,7 +4,7 @@ import { addIndicator, promoteIndicatorToObservables } from '../../../src/module import { addStixCyberObservable, promoteObservableToIndicator, stixCyberObservableDelete } from '../../../src/domain/stixCyberObservable'; import { executePromoteIndicatorToObservables, executePromoteObservableToIndicator, executeReplace, executeShare } from '../../../src/manager/taskManager'; import type { AuthContext } from '../../../src/types/user'; -import { ADMIN_USER, TEST_ORGANIZATION, testContext } from '../../utils/testQuery'; +import { ADMIN_USER, getOrganizationIdByName, PLATFORM_ORGANIZATION, TEST_ORGANIZATION, testContext } from '../../utils/testQuery'; import { MARKING_TLP_AMBER, MARKING_TLP_CLEAR } from '../../../src/schema/identifier'; import { addReport, findById as findReportById } from '../../../src/domain/report'; import { findById as findMarkingById } from '../../../src/domain/markingDefinition'; @@ -13,6 +13,8 @@ import { stixDomainObjectDelete } from '../../../src/domain/stixDomainObject'; import { type OrganizationAddInput } from '../../../src/generated/graphql'; import { RELATION_OBJECT } from '../../../src/schema/stixRefRelationship'; import { promoteObservableInput, promoteIndicatorInput, promoteReportInput } from './taskManager-promote-values/promoteValues'; +import { getSettings, settingsEditField } from '../../../src/domain/settings'; +import type { BasicStoreEntityEntitySetting } from '../../../src/modules/entitySetting/entitySetting-types'; describe('TaskManager executeReplace tests ', () => { const adminContext: AuthContext = { user: ADMIN_USER, tracing: undefined, source: 'taskManager-integration-test', otp_mandatory: false }; @@ -281,7 +283,7 @@ describe('TaskManager executeReplace tests ', () => { }); }); -describe('TaskManager executePromote tests', () => { +describe.skip('TaskManager executePromote tests', () => { const prepareTestContext = async () => { const createdIndicator = await addIndicator(testContext, ADMIN_USER, promoteIndicatorInput); const createObservable = await addStixCyberObservable(testContext, ADMIN_USER, promoteObservableInput); diff --git a/opencti-platform/opencti-graphql/tests/utils/testQuery.ts b/opencti-platform/opencti-graphql/tests/utils/testQuery.ts index 5996e215dd87..24ca3996438d 100644 --- a/opencti-platform/opencti-graphql/tests/utils/testQuery.ts +++ b/opencti-platform/opencti-graphql/tests/utils/testQuery.ts @@ -275,7 +275,7 @@ export const PLATFORM_ADMIN_GROUP: Group = { TESTING_GROUPS.push(PLATFORM_ADMIN_GROUP); // Organization -interface Organization { +export interface Organization { name: string, id: string } diff --git a/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts b/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts index 2553d4018188..2eaf64c751fb 100644 --- a/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts +++ b/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts @@ -1,10 +1,22 @@ import { expect } from 'vitest'; import { print } from 'graphql/index'; import type { AxiosInstance } from 'axios'; -import { adminQuery, createUnauthenticatedClient, executeInternalQuery, queryAsAdmin } from './testQuery'; +import { + ADMIN_USER, + adminQuery, + createUnauthenticatedClient, + executeInternalQuery, + getOrganizationIdByName, + Organization, + PLATFORM_ORGANIZATION, + queryAsAdmin, + TEST_ORGANIZATION, + testContext +} from './testQuery'; import { downloadFile, streamConverter } from '../../src/database/file-storage'; import { logApp } from '../../src/config/conf'; import { AUTH_REQUIRED, FORBIDDEN_ACCESS } from '../../src/config/errors'; +import { getSettings, settingsEditField } from '../../src/domain/settings'; // Helper for test usage whit expect inside. // vitest cannot be an import of testQuery, so it must be a separate file. @@ -88,3 +100,37 @@ export const requestFileFromStorageAsAdmin = async (storageId: string) => { expect(stream, `No stream mean no file found in storage or error for ${storageId}`).not.toBeNull(); return streamConverter(stream); }; + +/** + * Enable Enterprise edition and set the platform organisation. + * @param organization: organization to use as platform organization. + */ +export const enableEEAndSetOrganization = async (organization: Organization) => { + const platformOrganizationId = await getOrganizationIdByName(organization.name); + const platformSettings: any = await getSettings(testContext); + console.log('platformSettings:', platformSettings); + + const input = [ + { key: 'enterprise_edition', value: [new Date().getTime()] }, + { key: 'platform_organization', value: [platformOrganizationId] } + ]; + const settingsResult = await settingsEditField(testContext, ADMIN_USER, platformSettings.id, input); + console.log('settingsResult:', settingsResult); + + expect(settingsResult.platform_organization).not.toBeUndefined(); + expect(settingsResult.enterprise_edition).not.toBeUndefined(); + expect(settingsResult.platform_organization.id).toEqual(platformOrganizationId); +}; + +/** + * Remove any platform organization and go back to comunity edition. + */ +export const enableCEAndUnSetOrganization = async () => { + const platformSettings: any = await getSettings(testContext); + + const input = [ + { key: 'enterprise_edition', value: [] }, + { key: 'platform_organization', value: [] } + ]; + const result = await settingsEditField(testContext, ADMIN_USER, platformSettings.id, input); +}; From 45fba44d6ca31048a60c98a8348d793b50306982 Mon Sep 17 00:00:00 2001 From: marie flores Date: Fri, 20 Sep 2024 15:31:13 +0200 Subject: [PATCH 05/11] [backend] WIP: test (#8333) --- .../container-organization-sharing-test.ts | 19 ++-------------- .../tests/utils/testQueryHelper.ts | 22 +++++-------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts index d20a82d04635..49e4fa4815be 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts @@ -39,21 +39,6 @@ const DELETE_QUERY = gql` } `; -const PLATFORM_ORGANIZATION_QUERY = gql` - mutation PoliciesFieldPatchMutation($id: ID!, $input: [EditInput]!) { - settingsEdit(id: $id) { - fieldPatch(input: $input) { - platform_organization { - id - name - } - enterprise_edition - id - } - } - } -`; - const ORGANIZATION_SHARING_QUERY = gql` mutation StixCoreObjectSharingGroupAddMutation( $id: ID! @@ -140,7 +125,7 @@ describe('Organization sharing standard behavior for container', () => { }); expect(queryResult.data.report.objects.edges.length).toEqual(10); }); - it.skip('should delete Report', async () => { + it('should delete Report', async () => { // Delete the case await adminQuery({ query: DELETE_QUERY, @@ -150,7 +135,7 @@ describe('Organization sharing standard behavior for container', () => { const queryResult = await adminQueryWithSuccess({ query: READ_QUERY, variables: { id: reportInternalId } }); expect(queryResult?.data?.caseIncident).toBeNull(); }); - it.skip('should plateform organization sharing and EE deactivated', async () => { + it('should plateform organization sharing and EE deactivated', async () => { await enableCEAndUnSetOrganization(); }); }); diff --git a/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts b/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts index 2eaf64c751fb..fb4da793ccb3 100644 --- a/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts +++ b/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts @@ -1,18 +1,7 @@ import { expect } from 'vitest'; import { print } from 'graphql/index'; import type { AxiosInstance } from 'axios'; -import { - ADMIN_USER, - adminQuery, - createUnauthenticatedClient, - executeInternalQuery, - getOrganizationIdByName, - Organization, - PLATFORM_ORGANIZATION, - queryAsAdmin, - TEST_ORGANIZATION, - testContext -} from './testQuery'; +import { ADMIN_USER, adminQuery, createUnauthenticatedClient, executeInternalQuery, getOrganizationIdByName, Organization, queryAsAdmin, testContext } from './testQuery'; import { downloadFile, streamConverter } from '../../src/database/file-storage'; import { logApp } from '../../src/config/conf'; import { AUTH_REQUIRED, FORBIDDEN_ACCESS } from '../../src/config/errors'; @@ -108,18 +97,16 @@ export const requestFileFromStorageAsAdmin = async (storageId: string) => { export const enableEEAndSetOrganization = async (organization: Organization) => { const platformOrganizationId = await getOrganizationIdByName(organization.name); const platformSettings: any = await getSettings(testContext); - console.log('platformSettings:', platformSettings); const input = [ { key: 'enterprise_edition', value: [new Date().getTime()] }, { key: 'platform_organization', value: [platformOrganizationId] } ]; const settingsResult = await settingsEditField(testContext, ADMIN_USER, platformSettings.id, input); - console.log('settingsResult:', settingsResult); expect(settingsResult.platform_organization).not.toBeUndefined(); expect(settingsResult.enterprise_edition).not.toBeUndefined(); - expect(settingsResult.platform_organization.id).toEqual(platformOrganizationId); + expect(settingsResult.platform_organization).toEqual(platformOrganizationId); }; /** @@ -132,5 +119,8 @@ export const enableCEAndUnSetOrganization = async () => { { key: 'enterprise_edition', value: [] }, { key: 'platform_organization', value: [] } ]; - const result = await settingsEditField(testContext, ADMIN_USER, platformSettings.id, input); + const settingsResult = await settingsEditField(testContext, ADMIN_USER, platformSettings.id, input); + + expect(settingsResult.platform_organization).toBeUndefined(); + expect(settingsResult.enterprise_edition).toBeUndefined(); }; From 58741934d8af458565931a08a4f678e5f8692741 Mon Sep 17 00:00:00 2001 From: marie flores Date: Fri, 20 Sep 2024 15:49:06 +0200 Subject: [PATCH 06/11] [backend] drone (#8333) --- opencti-platform/opencti-graphql/src/database/stix.ts | 1 - .../opencti-graphql/src/schema/stixRefRelationship.ts | 2 -- .../tests/02-integration/04-manager/taskManager-test.ts | 4 +--- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/opencti-platform/opencti-graphql/src/database/stix.ts b/opencti-platform/opencti-graphql/src/database/stix.ts index 294251820b0e..eb8872819195 100644 --- a/opencti-platform/opencti-graphql/src/database/stix.ts +++ b/opencti-platform/opencti-graphql/src/database/stix.ts @@ -89,7 +89,6 @@ import { FunctionalError, UnsupportedError } from '../config/errors'; import { ENTITY_TYPE_THREAT_ACTOR_INDIVIDUAL } from '../modules/threatActorIndividual/threatActorIndividual-types'; import { ENTITY_TYPE_IDENTITY_ORGANIZATION } from '../modules/organization/organization-types'; import { ENTITY_TYPE_INDICATOR } from '../modules/indicator/indicator-types'; -import { logApp } from '../config/conf'; const MAX_TRANSIENT_STIX_IDS = 200; export const STIX_SPEC_VERSION = '2.1'; diff --git a/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts b/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts index 78cc626bc122..ff7c2afcf305 100644 --- a/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts +++ b/opencti-platform/opencti-graphql/src/schema/stixRefRelationship.ts @@ -23,7 +23,6 @@ import { ENTITY_TYPE_IDENTITY_SYSTEM, ENTITY_TYPE_LOCATION_COUNTRY, isStixDomainObjectContainer, - isStixDomainObjectIdentity, isStixDomainObjectLocation } from './stixDomainObject'; import { ENTITY_TYPE_EXTERNAL_REFERENCE, ENTITY_TYPE_KILL_CHAIN_PHASE, ENTITY_TYPE_LABEL, ENTITY_TYPE_MARKING_DEFINITION } from './stixMetaObject'; @@ -51,7 +50,6 @@ import { ENTITY_WINDOWS_REGISTRY_VALUE_TYPE } from './stixCyberObservable'; import { ATTRIBUTE_SAMPLE } from '../modules/malwareAnalysis/malwareAnalysis-types'; -import { logApp } from '../config/conf'; export const ABSTRACT_STIX_NESTED_REF_RELATIONSHIP = 'stix-nested-ref-relationship'; // Only for front usage diff --git a/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts index 197b3a2a58f8..ba97803d6e6c 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts @@ -4,7 +4,7 @@ import { addIndicator, promoteIndicatorToObservables } from '../../../src/module import { addStixCyberObservable, promoteObservableToIndicator, stixCyberObservableDelete } from '../../../src/domain/stixCyberObservable'; import { executePromoteIndicatorToObservables, executePromoteObservableToIndicator, executeReplace, executeShare } from '../../../src/manager/taskManager'; import type { AuthContext } from '../../../src/types/user'; -import { ADMIN_USER, getOrganizationIdByName, PLATFORM_ORGANIZATION, TEST_ORGANIZATION, testContext } from '../../utils/testQuery'; +import { ADMIN_USER, TEST_ORGANIZATION, testContext } from '../../utils/testQuery'; import { MARKING_TLP_AMBER, MARKING_TLP_CLEAR } from '../../../src/schema/identifier'; import { addReport, findById as findReportById } from '../../../src/domain/report'; import { findById as findMarkingById } from '../../../src/domain/markingDefinition'; @@ -13,8 +13,6 @@ import { stixDomainObjectDelete } from '../../../src/domain/stixDomainObject'; import { type OrganizationAddInput } from '../../../src/generated/graphql'; import { RELATION_OBJECT } from '../../../src/schema/stixRefRelationship'; import { promoteObservableInput, promoteIndicatorInput, promoteReportInput } from './taskManager-promote-values/promoteValues'; -import { getSettings, settingsEditField } from '../../../src/domain/settings'; -import type { BasicStoreEntityEntitySetting } from '../../../src/modules/entitySetting/entitySetting-types'; describe('TaskManager executeReplace tests ', () => { const adminContext: AuthContext = { user: ADMIN_USER, tracing: undefined, source: 'taskManager-integration-test', otp_mandatory: false }; From 81eda4892adcd9e57cdb1b7db73de29ca9cd431d Mon Sep 17 00:00:00 2001 From: marie flores Date: Fri, 20 Sep 2024 15:53:29 +0200 Subject: [PATCH 07/11] [backend] drone (#8333) --- .../tests/02-integration/04-manager/taskManager-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts index ba97803d6e6c..98c6d44bd9e2 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/04-manager/taskManager-test.ts @@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import type { BasicStoreEntity } from '../../../src/types/store'; import { addIndicator, promoteIndicatorToObservables } from '../../../src/modules/indicator/indicator-domain'; import { addStixCyberObservable, promoteObservableToIndicator, stixCyberObservableDelete } from '../../../src/domain/stixCyberObservable'; -import { executePromoteIndicatorToObservables, executePromoteObservableToIndicator, executeReplace, executeShare } from '../../../src/manager/taskManager'; +import { executePromoteIndicatorToObservables, executePromoteObservableToIndicator, executeReplace } from '../../../src/manager/taskManager'; import type { AuthContext } from '../../../src/types/user'; import { ADMIN_USER, TEST_ORGANIZATION, testContext } from '../../utils/testQuery'; import { MARKING_TLP_AMBER, MARKING_TLP_CLEAR } from '../../../src/schema/identifier'; From b8a1ee1f4fc9b6d17e0bcf0d437e523da56c4441 Mon Sep 17 00:00:00 2001 From: marie flores Date: Fri, 20 Sep 2024 16:27:30 +0200 Subject: [PATCH 08/11] [backend] drone (#8333) --- .../opencti-graphql/tests/utils/testQueryHelper.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts b/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts index fb4da793ccb3..a322f2b53ec0 100644 --- a/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts +++ b/opencti-platform/opencti-graphql/tests/utils/testQueryHelper.ts @@ -1,7 +1,8 @@ import { expect } from 'vitest'; import { print } from 'graphql/index'; import type { AxiosInstance } from 'axios'; -import { ADMIN_USER, adminQuery, createUnauthenticatedClient, executeInternalQuery, getOrganizationIdByName, Organization, queryAsAdmin, testContext } from './testQuery'; +import { ADMIN_USER, adminQuery, createUnauthenticatedClient, executeInternalQuery, getOrganizationIdByName, queryAsAdmin, testContext } from './testQuery'; +import type { Organization } from './testQuery'; import { downloadFile, streamConverter } from '../../src/database/file-storage'; import { logApp } from '../../src/config/conf'; import { AUTH_REQUIRED, FORBIDDEN_ACCESS } from '../../src/config/errors'; From 661db602956d41ffe07c37b757ee276335646369 Mon Sep 17 00:00:00 2001 From: marie flores Date: Mon, 30 Sep 2024 14:24:13 +0200 Subject: [PATCH 09/11] [backend] fix counters --- .../01-database/elasticSearch-test.js | 24 +++++++-------- .../01-database/filterGroup-test.js | 30 +++++++++---------- .../01-database/middleware-test.js | 8 ++--- .../01-database/taxii-filtering-test.js | 6 ++-- .../container-organization-sharing-test.ts | 19 ++---------- 5 files changed, 37 insertions(+), 50 deletions(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/01-database/elasticSearch-test.js b/opencti-platform/opencti-graphql/tests/02-integration/01-database/elasticSearch-test.js index da2ab4801ba2..3042a3013130 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/01-database/elasticSearch-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/01-database/elasticSearch-test.js @@ -136,7 +136,7 @@ describe('Elasticsearch computation', () => { ); const aggregationMap = new Map(malwaresAggregation.map((i) => [i.label, i.value])); expect(aggregationMap.get('Malware')).toEqual(2); - expect(aggregationMap.get('Indicator')).toEqual(3); + expect(aggregationMap.get('Indicator')).toEqual(4); }); it('should entity aggregation with date accurate', async () => { const mostRecentMalware = await elLoadById(testContext, ADMIN_USER, 'malware--c6006dd5-31ca-45c2-8ae0-4e428e712f88'); @@ -232,7 +232,7 @@ describe('Elasticsearch computation', () => { // noinspection JSUnresolvedVariable const storedFormat = moment(R.head(data).date)._f; expect(storedFormat).toEqual('YYYY-MM-DD'); - expect(R.head(data).value).toEqual(36); + expect(R.head(data).value).toEqual(48); }); it('should month histogram accurate', async () => { const data = await elHistogramCount( @@ -404,7 +404,7 @@ describe('Elasticsearch pagination', () => { it('should entity paginate everything', async () => { const data = await elPaginate(testContext, ADMIN_USER, READ_ENTITIES_INDICES, { first: ES_MAX_PAGINATION }); expect(data).not.toBeNull(); - expect(data.edges.length).toEqual(537); + expect(data.edges.length).toEqual(552); const filterBaseTypes = R.uniq(R.map((e) => e.node.base_type, data.edges)); expect(filterBaseTypes.length).toEqual(1); expect(R.head(filterBaseTypes)).toEqual('ENTITY'); @@ -500,7 +500,7 @@ describe('Elasticsearch pagination', () => { filterGroups: [], }; const data = await elPaginate(testContext, ADMIN_USER, READ_ENTITIES_INDICES, { filters, first: ES_MAX_PAGINATION }); - expect(data.edges.length).toEqual(526); + expect(data.edges.length).toEqual(541); }); it('should entity paginate with field exist filter', async () => { const filters = { @@ -563,7 +563,7 @@ describe('Elasticsearch pagination', () => { filterGroups: [], }; data = await elPaginate(testContext, ADMIN_USER, READ_ENTITIES_INDICES, { filters, first: ES_MAX_PAGINATION }); - expect(data.edges.length).toEqual(368); + expect(data.edges.length).toEqual(380); filters = { mode: 'and', filters: [ @@ -581,7 +581,7 @@ describe('Elasticsearch pagination', () => { orderMode: 'asc', first: ES_MAX_PAGINATION }); - expect(data.edges.length).toEqual(519 + TESTING_USERS.length + TESTING_ROLES.length + TESTING_GROUPS.length); + expect(data.edges.length).toEqual(534 + TESTING_USERS.length + TESTING_ROLES.length + TESTING_GROUPS.length); const createdDates = R.map((e) => e.node.created, data.edges); let previousCreatedDate = null; for (let index = 0; index < createdDates.length; index += 1) { @@ -681,24 +681,24 @@ describe('Elasticsearch pagination', () => { const groupByIndices = R.groupBy((e) => e.node._index, data.edges); expect(groupByIndices[`${ES_INDEX_PREFIX}_internal_relationships-000001`].length).toEqual(94); expect(groupByIndices[`${ES_INDEX_PREFIX}_stix_core_relationships-000001`].length).toEqual(24); - expect(groupByIndices[`${ES_INDEX_PREFIX}_stix_meta_relationships-000001`].length).toEqual(129); + expect(groupByIndices[`${ES_INDEX_PREFIX}_stix_meta_relationships-000001`].length).toEqual(146); expect(groupByIndices[`${ES_INDEX_PREFIX}_stix_sighting_relationships-000001`].length).toEqual(2); const metas = groupByIndices[`${ES_INDEX_PREFIX}_stix_meta_relationships-000001`].map((m) => m.node); const metaByEntityType = R.groupBy((m) => m.entity_type, metas); - expect(metaByEntityType.object.length).toEqual(38); - expect(metaByEntityType['object-label'].length).toEqual(30); - expect(metaByEntityType['created-by'].length).toEqual(22); + expect(metaByEntityType.object.length).toEqual(48); + expect(metaByEntityType['object-label'].length).toEqual(32); + expect(metaByEntityType['created-by'].length).toEqual(27); expect(metaByEntityType['external-reference'].length).toEqual(7); expect(metaByEntityType['object-marking'].length).toEqual(28); expect(metaByEntityType['kill-chain-phase'].length).toEqual(3); - expect(data.edges.length).toEqual(249); + expect(data.edges.length).toEqual(266); let filterBaseTypes = R.uniq(R.map((e) => e.node.base_type, data.edges)); expect(filterBaseTypes.length).toEqual(1); expect(R.head(filterBaseTypes)).toEqual('RELATION'); // Same query with no pagination data = await elPaginate(testContext, ADMIN_USER, READ_RELATIONSHIPS_INDICES, { connectionFormat: false }); expect(data).not.toBeNull(); - expect(data.length).toEqual(249); + expect(data.length).toEqual(266); filterBaseTypes = R.uniq(R.map((e) => e.base_type, data)); expect(filterBaseTypes.length).toEqual(1); expect(R.head(filterBaseTypes)).toEqual('RELATION'); diff --git a/opencti-platform/opencti-graphql/tests/02-integration/01-database/filterGroup-test.js b/opencti-platform/opencti-graphql/tests/02-integration/01-database/filterGroup-test.js index 4efd5ef89d95..53986381dbf3 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/01-database/filterGroup-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/01-database/filterGroup-test.js @@ -246,9 +246,9 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.reports.edges.length).toEqual(5); // the 4 reports created + the report in DATA-TEST-STIX2_v2.json + expect(queryResult.data.reports.edges.length).toEqual(6); // the 4 reports created + the 2 report in DATA-TEST-STIX2_v2.json queryResult = await queryAsAdmin({ query: REPORT_LIST_QUERY }); - expect(queryResult.data.reports.edges.length).toEqual(5); + expect(queryResult.data.reports.edges.length).toEqual(6); }); it('should list entities according to filters: one filter', async () => { const queryResult = await queryAsAdmin({ @@ -327,7 +327,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.reports.edges.length).toEqual(3); // report1 and report3 and report in DATA-TEST-STIX2_v2.json + expect(queryResult.data.reports.edges.length).toEqual(4); // report1 and report3 and 2 reports in DATA-TEST-STIX2_v2.json expect(queryResult.data.reports.edges.map((n) => n.node.name).includes('Report1')).toBeTruthy(); expect(queryResult.data.reports.edges.map((n) => n.node.name).includes('Report3')).toBeTruthy(); expect(queryResult.data.reports.edges.map((n) => n.node.name)).includes('A demo report for testing purposes').toBeTruthy(); @@ -588,7 +588,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.reports.edges.length).toEqual(2); + expect(queryResult.data.reports.edges.length).toEqual(3); expect(queryResult.data.reports.edges.map((n) => n.node.name).includes('Report2')).toBeTruthy(); expect(queryResult.data.reports.edges.map((n) => n.node.name).includes('Report4')).toBeTruthy(); }); @@ -680,7 +680,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.reports.edges.length).toEqual(1); + expect(queryResult.data.reports.edges.length).toEqual(2); expect(queryResult.data.reports.edges[0].node.name).toEqual('Report3'); // test for 'not_nil': objectMarking is not empty queryResult = await queryAsAdmin({ @@ -724,7 +724,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.reports.edges.length).toEqual(2); + expect(queryResult.data.reports.edges.length).toEqual(3); expect(queryResult.data.reports.edges.map((n) => n.node.name).includes('Report3')).toBeTruthy(); // description is empty string expect(queryResult.data.reports.edges.map((n) => n.node.name).includes('Report4')).toBeTruthy(); // description is null // description is not empty @@ -937,7 +937,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(8); // 8 containers: 4 reports in this file + 1 report, 1 note, 1 observed-data, 1 opinion in DATA-TEST-STIXv2_v2 + expect(queryResult.data.globalSearch.edges.length).toEqual(9); // 8 containers: 4 reports in this file + 1 report, 1 note, 1 observed-data, 1 opinion in DATA-TEST-STIXv2_v2 // (entity_type = Report AND container) queryResult = await queryAsAdmin({ query: LIST_QUERY, @@ -957,7 +957,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(5); // 5 reports + expect(queryResult.data.globalSearch.edges.length).toEqual(6); // 5 reports // (entity_type = Report AND container AND Stix-Core-Object) queryResult = await queryAsAdmin({ query: LIST_QUERY, @@ -977,7 +977,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(5); // 5 reports + expect(queryResult.data.globalSearch.edges.length).toEqual(6); // 5 reports // (entity_type = Malware OR Software) queryResult = await queryAsAdmin({ query: LIST_QUERY, @@ -1237,7 +1237,7 @@ describe('Complex filters combinations for elastic queries', () => { filters: undefined, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(44); + expect(queryResult.data.globalSearch.edges.length).toEqual(58); // (source_reliability is empty) queryResult = await queryAsAdmin({ query: LIST_QUERY, @@ -1257,7 +1257,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(33); // 44 entities - 11 entities with a source reliability = 33 + expect(queryResult.data.globalSearch.edges.length).toEqual(46); // 46 entities - 11 entities with a source reliability = 33 // (source_reliability is not empty) queryResult = await queryAsAdmin({ query: LIST_QUERY, @@ -1277,7 +1277,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(11); // 11 entities with a source reliability + expect(queryResult.data.globalSearch.edges.length).toEqual(12); // 12 entities with a source reliability // (source_reliability = A - Completely reliable) queryResult = await queryAsAdmin({ query: LIST_QUERY, @@ -1317,7 +1317,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(38); // 44 entities - 6 entities with source reliability equals to A = 38 + expect(queryResult.data.globalSearch.edges.length).toEqual(52); // 58 entities - 6 entities with source reliability equals to A = 38 // (source_reliability = A - Completely reliable OR B - Usually reliable) queryResult = await queryAsAdmin({ query: LIST_QUERY, @@ -1420,7 +1420,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(31); // 44 - 11 with a source reliability - 2 with a reliability (and no source reliability) = 31 + expect(queryResult.data.globalSearch.edges.length).toEqual(43); // 56 - 11 with a source reliability - 2 with a reliability (and no source reliability) = 31 // (computed_reliability is not empty) queryResult = await queryAsAdmin({ query: LIST_QUERY, @@ -1440,7 +1440,7 @@ describe('Complex filters combinations for elastic queries', () => { }, } }); - expect(queryResult.data.globalSearch.edges.length).toEqual(13); // 11 entities with a source reliability + 2 entities with a reliability = 13 + expect(queryResult.data.globalSearch.edges.length).toEqual(15); // 13 entities with a source reliability + 2 entities with a reliability = 13 // (computed_reliability = A - Completely reliable) queryResult = await queryAsAdmin({ query: LIST_QUERY, diff --git a/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js b/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js index c73ff87c42ec..5226161e1c67 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/01-database/middleware-test.js @@ -184,7 +184,7 @@ describe('Entities listing', () => { it('should list multiple entities', async () => { const entities = await listEntities(testContext, ADMIN_USER, ['Malware', 'Organization']); expect(entities).not.toBeNull(); - expect(entities.edges.length).toEqual(10); // 2 malwares + 8 organizations + expect(entities.edges.length).toEqual(14); // 2 malwares + 12 organizations const aggregationMap = new Map(entities.edges.map((i) => [i.node.name, i.node])); expect(aggregationMap.get('Paradise Ransomware')).not.toBeUndefined(); expect(aggregationMap.get('Allied Universal')).not.toBeUndefined(); @@ -196,7 +196,7 @@ describe('Entities listing', () => { const indicators = await listEntities(testContext, ADMIN_USER, ['Indicator'], options); expect(indicators.edges.length).toEqual(1); const indicator = R.head(indicators.edges).node; - expect(indicator.name).toEqual('www.xolod-teplo.ru'); + expect(indicator.name).toEqual('72.18.130.48'); }); it('should list entities with search', async () => { let options = { search: 'xolod' }; @@ -210,7 +210,7 @@ describe('Entities listing', () => { expect(indicators.edges.length).toEqual(2); options = { search: 'i want a location' }; indicators = await listEntities(testContext, ADMIN_USER, ['Indicator'], options); - expect(indicators.edges.length).toEqual(3); + expect(indicators.edges.length).toEqual(4); }); it('should list entities with attribute filters', async () => { const filters = { @@ -255,7 +255,7 @@ describe('Relations listing', () => { expect(stixCoreRelationships.edges.length).toEqual(24); const stixRefRelationships = await listRelations(testContext, ADMIN_USER, 'stix-ref-relationship'); expect(stixRefRelationships).not.toBeNull(); - expect(stixRefRelationships.edges.length).toEqual(129); + expect(stixRefRelationships.edges.length).toEqual(146); }); it('should list relations with roles', async () => { const stixRelations = await listRelations(testContext, ADMIN_USER, 'uses', { diff --git a/opencti-platform/opencti-graphql/tests/02-integration/01-database/taxii-filtering-test.js b/opencti-platform/opencti-graphql/tests/02-integration/01-database/taxii-filtering-test.js index 888952ca9e98..addb8f59f748 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/01-database/taxii-filtering-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/01-database/taxii-filtering-test.js @@ -208,7 +208,7 @@ describe('Complex filters combinations, behavior tested on taxii collections', ( const { edges: results1 } = await collectionQuery(testContext, ADMIN_USER, taxiiCollection, {}); edgeIds = results1.map((e) => e.node.internal_id); const edgeNames = results1.map((e) => e.node.name); - expect(edgeIds.length).toEqual(2); // the report created + the report in DATA-TEST-STIX2_v2 + expect(edgeIds.length).toEqual(3); // the report created + the 2 reports in DATA-TEST-STIX2_v2 expect(edgeIds).includes(reportInternalId).toBeTruthy(); expect(edgeNames).includes('Report').toBeTruthy(); expect(edgeNames).includes('A demo report for testing purposes').toBeTruthy(); @@ -245,7 +245,7 @@ describe('Complex filters combinations, behavior tested on taxii collections', ( taxiiCollection = await storeLoadById(testContext, ADMIN_USER, taxiiInternalId, ENTITY_TYPE_TAXII_COLLECTION); const { edges: results3_1 } = await collectionQuery(testContext, ADMIN_USER, taxiiCollection, {}); edgeIds = results3_1.map((e) => e.node.internal_id); - expect(edgeIds.length).toEqual(3); // the report + city2 + the report in DATA-TEST-STIX2_v2 + expect(edgeIds.length).toEqual(4); // the report + city2 + the 2 reports in DATA-TEST-STIX2_v2 // global mode = 'and' await changeTaxiiFilters({ mode: 'and', @@ -338,7 +338,7 @@ describe('Complex filters combinations, behavior tested on taxii collections', ( taxiiCollection = await storeLoadById(testContext, ADMIN_USER, taxiiInternalId, ENTITY_TYPE_TAXII_COLLECTION); const { edges: results5 } = await collectionQuery(testContext, ADMIN_USER, taxiiCollection, {}); edgeIds = results5.map((e) => e.node.internal_id); - expect(edgeIds.length).toEqual(2); + expect(edgeIds.length).toEqual(3); expect(edgeIds).includes(reportInternalId).toBeTruthy(); expect(edgeIds).includes(city2InternalId).toBeTruthy(); // --- 06. filters with nil operator --- // diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts index 49e4fa4815be..8987ffe73fe3 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts @@ -1,21 +1,8 @@ import { describe, expect, it } from 'vitest'; import gql from 'graphql-tag'; -import { - ADMIN_API_TOKEN, - ADMIN_USER, - adminQuery, - API_URI, - FIVE_MINUTES, - getOrganizationIdByName, - PLATFORM_ORGANIZATION, - PYTHON_PATH, - TEST_ORGANIZATION, - testContext, - USER_EDITOR, -} from '../../utils/testQuery'; +import { ADMIN_USER, adminQuery, getOrganizationIdByName, PLATFORM_ORGANIZATION, TEST_ORGANIZATION, testContext, USER_EDITOR } from '../../utils/testQuery'; import { adminQueryWithSuccess, enableCEAndUnSetOrganization, enableEEAndSetOrganization, queryAsUserWithSuccess } from '../../utils/testQueryHelper'; import { findById } from '../../../src/domain/report'; -import { execChildPython } from '../../../src/python/pythonBridge'; import { taskHandler } from '../../../src/manager/taskManager'; const READ_QUERY = gql` @@ -55,7 +42,7 @@ const ORGANIZATION_SHARING_QUERY = gql` } } `; - +/* const importOpts: string[] = [API_URI, ADMIN_API_TOKEN, './tests/data/DATA-TEST-STIX2_v2.json']; describe('Database provision', () => { @@ -71,7 +58,7 @@ describe('Database provision', () => { expect(execution).not.toBeNull(); expect(execution.status).toEqual('success'); }, FIVE_MINUTES); -}); +}); */ describe('Organization sharing standard behavior for container', () => { let reportInternalId: string; From 398eb65337f9298810940e8104658d4eac18631b Mon Sep 17 00:00:00 2001 From: marie flores Date: Wed, 2 Oct 2024 09:46:41 +0200 Subject: [PATCH 10/11] [backend] fix counters --- .../tests/02-integration/02-resolvers/attackPattern-test.js | 2 +- .../tests/02-integration/02-resolvers/country-test.js | 2 +- .../tests/02-integration/02-resolvers/individual-test.js | 2 +- .../tests/02-integration/02-resolvers/organization-test.js | 2 +- .../tests/02-integration/02-resolvers/region-test.js | 2 +- .../tests/02-integration/02-resolvers/report-test.js | 2 +- .../tests/02-integration/02-resolvers/sector-test.js | 2 +- .../02-integration/02-resolvers/stixCyberObservable-test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/attackPattern-test.js b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/attackPattern-test.js index 513a1d814102..980a5a0b86cb 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/attackPattern-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/attackPattern-test.js @@ -142,7 +142,7 @@ describe('AttackPattern resolver standard behavior', () => { }); it('should list attackPatterns', async () => { const queryResult = await queryAsAdmin({ query: LIST_QUERY, variables: { first: 10 } }); - expect(queryResult.data.attackPatterns.edges.length).toEqual(3); + expect(queryResult.data.attackPatterns.edges.length).toEqual(4); }); it('should query attackPatterns matrix', async () => { const queryResult = await queryAsAdmin({ query: MATRIX_QUERY }); diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/country-test.js b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/country-test.js index 928c9bdce2ba..5ecd95d38259 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/country-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/country-test.js @@ -103,7 +103,7 @@ describe('Country resolver standard behavior', () => { }); it('should list countries', async () => { const queryResult = await queryAsAdmin({ query: LIST_QUERY, variables: { first: 10 } }); - expect(queryResult.data.countries.edges.length).toEqual(2); + expect(queryResult.data.countries.edges.length).toEqual(3); }); it('should update country', async () => { const UPDATE_QUERY = gql` diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/individual-test.js b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/individual-test.js index 7ce2ee17fac4..a0c95d8e05ee 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/individual-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/individual-test.js @@ -109,7 +109,7 @@ describe('Individual resolver standard behavior', () => { }); it('should list individuals', async () => { const queryResult = await queryAsAdmin({ query: LIST_QUERY, variables: { first: 10 } }); - expect(queryResult.data.individuals.edges.length).toEqual(3); + expect(queryResult.data.individuals.edges.length).toEqual(4); }); it('should update individual', async () => { const UPDATE_QUERY = gql` diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/organization-test.js b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/organization-test.js index 54f0eb747a99..c0b9fcc57269 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/organization-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/organization-test.js @@ -132,7 +132,7 @@ describe('Organization resolver standard behavior', () => { }); it('should list organizations', async () => { const queryResult = await queryAsAdmin({ query: LIST_QUERY, variables: { first: 10 } }); - expect(queryResult.data.organizations.edges.length).toEqual(9); + expect(queryResult.data.organizations.edges.length).toEqual(13); }); it('should update organization', async () => { const UPDATE_QUERY = gql` diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/region-test.js b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/region-test.js index 60b4916d7312..014bbcf62f57 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/region-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/region-test.js @@ -132,7 +132,7 @@ describe('Region resolver standard behavior', () => { }); it('should list regions', async () => { const queryResult = await queryAsAdmin({ query: LIST_QUERY, variables: { first: 10 } }); - expect(queryResult.data.regions.edges.length).toEqual(3); + expect(queryResult.data.regions.edges.length).toEqual(4); }); it('should update region', async () => { const UPDATE_QUERY = gql` diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/report-test.js b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/report-test.js index 732fe681e191..58231f327970 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/report-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/report-test.js @@ -223,7 +223,7 @@ describe('Report resolver standard behavior', () => { }); it('should list reports', async () => { const queryResult = await queryAsAdmin({ query: LIST_QUERY, variables: { first: 10 } }); - expect(queryResult.data.reports.edges.length).toEqual(2); + expect(queryResult.data.reports.edges.length).toEqual(3); }); it('should timeseries reports to be accurate', async () => { const queryResult = await queryAsAdmin({ diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/sector-test.js b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/sector-test.js index 945a488392d1..3965253fb8b2 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/sector-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/sector-test.js @@ -135,7 +135,7 @@ describe('Sector resolver standard behavior', () => { }); it('should list sectors', async () => { const queryResult = await queryAsAdmin({ query: LIST_QUERY, variables: { first: 10 } }); - expect(queryResult.data.sectors.edges.length).toEqual(4); + expect(queryResult.data.sectors.edges.length).toEqual(5); }); it('should update sector', async () => { const UPDATE_QUERY = gql` diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/stixCyberObservable-test.js b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/stixCyberObservable-test.js index 54c4d6b359dd..77521ad0f1fe 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/stixCyberObservable-test.js +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/stixCyberObservable-test.js @@ -109,7 +109,7 @@ describe('StixCyberObservable resolver standard behavior', () => { }); it('should list stixCyberObservables', async () => { const queryResult = await queryAsAdmin({ query: gql(LIST_QUERY), variables: { first: 10 } }); - expect(queryResult.data.stixCyberObservables.edges.length).toEqual(6); + expect(queryResult.data.stixCyberObservables.edges.length).toEqual(7); }); it('should list stixCyberObservables orderBy observable_value', async () => { const queryResult = await internalAdminQuery(LIST_QUERY, { first: 10, orderBy: 'observable_value', orderMode: 'desc' }); From f722782aa9ef9e9552c3eec5a80ae42edb249ebc Mon Sep 17 00:00:00 2001 From: marie flores Date: Wed, 2 Oct 2024 10:10:14 +0200 Subject: [PATCH 11/11] [backend] add loader in container-organization-sharing --- .../container-organization-sharing-test.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts index 8987ffe73fe3..007a7ebaeee3 100644 --- a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/container-organization-sharing-test.ts @@ -1,9 +1,22 @@ import { describe, expect, it } from 'vitest'; import gql from 'graphql-tag'; -import { ADMIN_USER, adminQuery, getOrganizationIdByName, PLATFORM_ORGANIZATION, TEST_ORGANIZATION, testContext, USER_EDITOR } from '../../utils/testQuery'; +import { + ADMIN_API_TOKEN, + ADMIN_USER, + adminQuery, + API_URI, + FIVE_MINUTES, + getOrganizationIdByName, + PLATFORM_ORGANIZATION, + PYTHON_PATH, + TEST_ORGANIZATION, + testContext, + USER_EDITOR +} from '../../utils/testQuery'; import { adminQueryWithSuccess, enableCEAndUnSetOrganization, enableEEAndSetOrganization, queryAsUserWithSuccess } from '../../utils/testQueryHelper'; import { findById } from '../../../src/domain/report'; import { taskHandler } from '../../../src/manager/taskManager'; +import { execChildPython } from '../../../src/python/pythonBridge'; const READ_QUERY = gql` query caseIncident($id: String!) { @@ -42,7 +55,7 @@ const ORGANIZATION_SHARING_QUERY = gql` } } `; -/* + const importOpts: string[] = [API_URI, ADMIN_API_TOKEN, './tests/data/DATA-TEST-STIX2_v2.json']; describe('Database provision', () => { @@ -58,7 +71,7 @@ describe('Database provision', () => { expect(execution).not.toBeNull(); expect(execution.status).toEqual('success'); }, FIVE_MINUTES); -}); */ +}); describe('Organization sharing standard behavior for container', () => { let reportInternalId: string;