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 7e4d743 commit cd07267
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 31 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
@@ -1,40 +1,48 @@
import { describe, it, expect } from 'vitest';
import gql from 'graphql-tag';
import { queryAsAdmin } from '../../utils/testQuery';
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';

describe('Case Incident Response resolver standard behavior', () => {
let caseIncidentResponse: CaseIncident;
const CREATE_QUERY = gql`
mutation CaseIncidentAdd($input: CaseIncidentAddInput!) {
caseIncidentAdd(input: $input){
id
standard_id
name
description
authorized_members {
id
access_right
}
}
}
`;

const READ_QUERY = gql`
query caseIncident($id: String!) {
caseIncident(id: $id) {
const READ_QUERY = gql`
query caseIncident($id: String!) {
caseIncident(id: $id) {
id
standard_id
name
description
toStix
authorized_members {
id
standard_id
name
description
toStix
authorized_members {
id
}
}
}
}
`;

const DELETE_QUERY = gql`
mutation CaseIncidentDelete($id: ID!) {
caseIncidentDelete(id: $id)
}
`;

describe('Case Incident Response resolver standard behavior', () => {
let caseIncidentResponse: CaseIncident;
it('should Case Incident Response created', async () => {
const CREATE_QUERY = gql`
mutation CaseIncidentAdd($input: CaseIncidentAddInput!) {
caseIncidentAdd(input: $input){
id
standard_id
name
description
authorized_members {
id
}
}
}
`;
const caseIncidentResponseData = await queryAsAdmin({
query: CREATE_QUERY,
variables: {
Expand All @@ -45,6 +53,7 @@ describe('Case Incident Response resolver standard behavior', () => {
});
expect(caseIncidentResponseData).not.toBeNull();
expect(caseIncidentResponseData?.data?.caseIncidentAdd.authorized_members).not.toBeUndefined();
expect(caseIncidentResponseData?.data?.caseIncidentAdd.authorized_members).toEqual([]); // authorized members not activated
caseIncidentResponse = caseIncidentResponseData?.data?.caseIncidentAdd;
});
it('should Case Incident Response loaded by internal id', async () => {
Expand Down Expand Up @@ -111,12 +120,8 @@ describe('Case Incident Response resolver standard behavior', () => {
});
expect(queryResult?.data?.stixDomainObjectEdit.fieldPatch.name).toEqual('Case - updated');
});
// TODO ADD context test even if i don't understand what it is?
it('should Case Incident Response deleted', async () => {
const DELETE_QUERY = gql`
mutation CaseIncidentDelete($id: ID!) {
caseIncidentDelete(id: $id)
}
`;
// Delete the case
await queryAsAdmin({
query: DELETE_QUERY,
Expand All @@ -128,3 +133,84 @@ describe('Case Incident Response resolver standard behavior', () => {
expect(queryResult?.data?.caseIncident).toBeNull();
});
});

describe('Case Incident Response authorized_members standard behavior', () => {
let caseIncidentResponseAuthorizedMembers: CaseIncident;
it('should Case Incident Response created with authorized_members activated via settings', async () => {
// Activate authorized members for IR
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
target_type
platform_entity_files_ref
platform_hidden_type
enforce_reference
attributes_configuration
}
}
`;

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] } },
});
expect(updateEntitySettingsResult.data?.entitySettingsFieldPatch[0].attribute_configuration).toEqual([authorizedMembersConfiguration]);

const caseIncidentResponseAuthorizedMembersData = await queryAsAdmin({
query: CREATE_QUERY,
variables: {
input: {
name: 'Case Incident Response With Authorized Members'
}
}
});
expect(caseIncidentResponseAuthorizedMembersData).not.toBeNull();
expect(caseIncidentResponseAuthorizedMembersData?.data?.caseIncidentAdd.authorized_members).not.toBeUndefined();
expect(caseIncidentResponseAuthorizedMembersData?.data?.caseIncidentAdd.authorized_members).toEqual([
{
id: ADMIN_USER.id,
name: ADMIN_USER.name,
access_right: 'admin'
}
]);
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
await queryAsAdmin({
query: DELETE_QUERY,
variables: { id: caseIncidentResponseAuthorizedMembers.id },
});
// Verify is no longer found
const queryResult = await queryAsAdmin({ query: READ_QUERY, variables: { id: caseIncidentResponseAuthorizedMembers.id } });
expect(queryResult).not.toBeNull();
expect(queryResult?.data?.caseIncident).toBeNull();
});
});

0 comments on commit cd07267

Please sign in to comment.