diff --git a/opencti-platform/opencti-graphql/src/modules/case/case-incident/case-incident.ts b/opencti-platform/opencti-graphql/src/modules/case/case-incident/case-incident.ts index 2c12a437787cd..729f0d69f0f65 100644 --- a/opencti-platform/opencti-graphql/src/modules/case/case-incident/case-incident.ts +++ b/opencti-platform/opencti-graphql/src/modules/case/case-incident/case-incident.ts @@ -5,6 +5,7 @@ import type { ModuleDefinition } from '../../../schema/module'; import { registerDefinition } from '../../../schema/module'; import convertCaseIncidentToStix from './case-incident-converter'; import { createdBy, objectAssignee, objectMarking, objectParticipant } from '../../../schema/stixRefRelationship'; +import { authorizedMembers } from '../../../schema/attribute-definition'; const CASE_INCIDENT_DEFINITION: ModuleDefinition = { type: { @@ -28,6 +29,7 @@ const CASE_INCIDENT_DEFINITION: ModuleDefinition { describe('Case Incident Response authorized_members standard behavior', () => { let caseIncidentResponseAuthorizedMembers: CaseIncident; - it('should Case Incident Response created with authorized_members activated', async () => { + it('should Case Incident Response created with authorized_members activated via settings', async () => { // Activate authorized members for IR - const UPDATE_SETTINGS_QUERY = gql` + const ENTITY_SETTINGS_READ_QUERY_BY_TARGET_TYPE = gql` + query entitySettingsByTargetType($targetType: String!) { + entitySettingByType(targetType: $targetType) { + id + target_type + platform_entity_files_ref + platform_hidden_type + enforce_reference + } + } + `; + + const ENTITY_SETTINGS_UPDATE_QUERY = gql` mutation entitySettingsEdit($ids: [ID!]!, $input: [EditInput!]!) { entitySettingsFieldPatch(ids: $ids, input: $input) { id @@ -148,21 +162,21 @@ describe('Case Incident Response authorized_members standard behavior', () => { } } `; - const variables = { - ids: [ - '5a18d85f-6e4b-4191-9e23-eeeedd6ca41a' - ], - input: { - key: 'attributes_configuration', - value: '[{"name":"authorized_members","default_values":["{\\"id\\":\\"CREATOR\\",\\"access_right\\":\\"admin\\"}"]}]' - } - }; - // TODO use JSON.stringify( - await queryAsAdmin({ - query: UPDATE_SETTINGS_QUERY, - variables, + + const caseIncidentResponseSettingsQueryResult = await queryAsAdmin({ + query: ENTITY_SETTINGS_READ_QUERY_BY_TARGET_TYPE, + variables: { targetType: ENTITY_TYPE_CONTAINER_CASE_INCIDENT } + }); + expect(caseIncidentResponseSettingsQueryResult.data?.entitySettingByType.target_type).toEqual(ENTITY_TYPE_CONTAINER_CASE_INCIDENT); + const caseIncidentEntitySetting = caseIncidentResponseSettingsQueryResult.data?.entitySettingByType; + + const authorizedMembersConfiguration = JSON.stringify([{ name: 'authorized_members', default_values: [{ id: ADMIN_USER.id, access_right: 'admin' }] }]); + + const updateEntitySettingsResult = await queryAsAdmin({ + query: ENTITY_SETTINGS_UPDATE_QUERY, + variables: { ids: [caseIncidentEntitySetting.id], input: { key: 'attributes_configuration', value: [authorizedMembersConfiguration] } }, }); - // TODO ADD assertion to check that entitysettings have been modify? + expect(updateEntitySettingsResult.data?.entitySettingsFieldPatch[0].attribute_configuration).toEqual([authorizedMembersConfiguration]); const caseIncidentResponseAuthorizedMembersData = await queryAsAdmin({ query: CREATE_QUERY, @@ -182,6 +196,11 @@ describe('Case Incident Response authorized_members standard behavior', () => { } ]); caseIncidentResponseAuthorizedMembers = caseIncidentResponseAuthorizedMembersData?.data?.caseIncidentAdd; + // Clean + await queryAsAdmin({ + query: ENTITY_SETTINGS_UPDATE_QUERY, + variables: { ids: [caseIncidentEntitySetting.id], input: { key: 'attributes_configuration', value: [] } }, + }); }); it('should Case Incident Response deleted', async () => { // Delete the case