Skip to content

Commit

Permalink
[frontend/backend] clean
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 committed Dec 12, 2024
1 parent 5c95071 commit 0b182f0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ export const generateOpenBasScenario = async (
);

// Get kill chin phases
const sortByPhaseOrder = R.sortBy(R.prop('phase_order'));
const obasKillChainPhases = await getKillChainPhases();
const sortedObasKillChainPhases = sortByPhaseOrder(obasKillChainPhases);
const sortedObasKillChainPhases = obasKillChainPhases.sort((a, b) => a.phase_order - b.phase_order);

Check warning on line 125 in opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js#L125

Added line #L125 was not covered by tests
const killChainPhasesListOfNames = sortedObasKillChainPhases.map((n) => n.phase_name).join(', ');
const indexedSortedObasKillChainPhase = R.indexBy(R.prop('phase_id'), sortedObasKillChainPhases);
const indexedSortedObasKillChainPhase = sortedObasKillChainPhases.reduce((acc, phase) => {
acc[phase.phase_id] = phase;
return acc;
}, {});

Check warning on line 130 in opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js#L127-L130

Added lines #L127 - L130 were not covered by tests

let dependsOnDuration = 0;
if (simulationType !== 'technical' && attackPatterns.length === 0) {

Check warning on line 133 in opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js#L133

Added line #L133 was not covered by tests
Expand Down Expand Up @@ -235,13 +237,17 @@ export const generateOpenBasScenario = async (
const filteredObasAttackPatterns = obasAttackPatterns.filter((n) => attackPatternsMitreIds.includes(n.attack_pattern_external_id));

// Enrich with the earliest kill chain phase
const enrichedFilteredObasAttackPatterns = filteredObasAttackPatterns.map(
(n) => R.assoc('attack_pattern_kill_chain_phase', sortByPhaseOrder(n.attack_pattern_kill_chain_phases.map((o) => indexedSortedObasKillChainPhase[o])).at(0), n)
);
const enrichedFilteredObasAttackPatterns = filteredObasAttackPatterns.map((n) => {
const earliestKillChainPhase = n.attack_pattern_kill_chain_phases
.map((phaseId) => indexedSortedObasKillChainPhase[phaseId])
.sort((a, b) => a.phase_order - b.phase_order)[0];
return { ...n, attack_pattern_kill_chain_phase: earliestKillChainPhase };
});

Check warning on line 245 in opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js#L240-L245

Added lines #L240 - L245 were not covered by tests

// Sort attack pattern by kill chain phase
const sortByKillChainPhase = R.sortBy(R.path(['attack_pattern_kill_chain_phase', 'phase_order']));
const sortedEnrichedFilteredObasAttackPatterns = sortByKillChainPhase(enrichedFilteredObasAttackPatterns);
const sortedEnrichedFilteredObasAttackPatterns = enrichedFilteredObasAttackPatterns.sort((a, b) => {
return a.attack_pattern_kill_chain_phase.phase_order - b.attack_pattern_kill_chain_phase.phase_order;
});

Check warning on line 250 in opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js#L248-L250

Added lines #L248 - L250 were not covered by tests

// Initialize an array to collect attack patterns without contracts
const attackPatternsWithoutInjectorContracts = [];

Check warning on line 253 in opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/modules/xtm/xtm-domain.js#L252-L253

Added lines #L252 - L253 were not covered by tests
Expand Down

0 comments on commit 0b182f0

Please sign in to comment.