Skip to content

Commit

Permalink
[backend] WIP Update model: authorized members activation via settings(
Browse files Browse the repository at this point in the history
  • Loading branch information
marieflorescontact committed Jul 16, 2024
1 parent 6752d48 commit 552d470
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoreEntityCaseIncident, StixCaseIncident> = {
type: {
Expand All @@ -28,6 +29,7 @@ const CASE_INCIDENT_DEFINITION: ModuleDefinition<StoreEntityCaseIncident, StixCa
{ name: 'severity', label: 'Severity', type: 'string', format: 'vocabulary', vocabularyCategory: 'case_severity_ov', mandatoryType: 'customizable', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'priority', label: 'Priority', type: 'string', format: 'vocabulary', vocabularyCategory: 'case_priority_ov', mandatoryType: 'customizable', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'response_types', label: 'Incident response type', type: 'string', format: 'vocabulary', vocabularyCategory: 'incident_response_types_ov', mandatoryType: 'customizable', editDefault: true, multiple: true, upsert: true, isFilterable: true },
{ ...authorizedMembers, editDefault: true }
],
relations: [],
relationsRefs: [createdBy, objectMarking, objectAssignee, objectParticipant],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
import gql from 'graphql-tag';
import { ADMIN_USER, queryAsAdmin } from '../../utils/testQuery';
import type { CaseIncident } from '../../../src/generated/graphql';
import { ENTITY_TYPE_CONTAINER_CASE_INCIDENT } from '../../../src/modules/case/case-incident/case-incident-types';

const CREATE_QUERY = gql`
mutation CaseIncidentAdd($input: CaseIncidentAddInput!) {
Expand All @@ -12,6 +13,7 @@ const CREATE_QUERY = gql`
description
authorized_members {
id
access_right
}
}
}
Expand Down Expand Up @@ -134,9 +136,21 @@ describe('Case Incident Response resolver standard behavior', () => {

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
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 552d470

Please sign in to comment.