Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend/frontend] Use ID instead of label when resolving expectation from OpenBAS #8589

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions opencti-platform/opencti-front/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ const depsToOptimize = [
"@mui/lab/LoadingButton",
"@mui/material/Breadcrumbs",
"classnames",
"react-draggable",
"react-beautiful-dnd"
"react-draggable"
guillaumejparis marked this conversation as resolved.
Show resolved Hide resolved
]

const logger = createLogger()
Expand Down
75 changes: 27 additions & 48 deletions opencti-platform/opencti-graphql/src/database/xtm-obas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,28 @@
}
};

const emptyResult = {
unknown: 1,
success: 0,
failure: 0,
};

const extractExerciseResultByType = (exerciseGlobalScore: any, type: string) => {
const resultType = exerciseGlobalScore.filter((n: { type: string, value: number }) => n.type === type).at(0);
return resultType.avgResult === 'UNKNOWN' ? {
emptyResult
} : {
unknown: resultType.distribution?.filter((n: { id: string, value: number }) => n.id === 'PENDING').at(0)?.value,
success: resultType.distribution?.filter((n: { id: string, value: number }) => n.id === 'SUCCESS').at(0)?.value,
failure: resultType.distribution?.filter((n: { id: string, value: number }) => n.id === 'FAILED').at(0)?.value
};
};

Check warning on line 169 in opencti-platform/opencti-graphql/src/database/xtm-obas.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/database/xtm-obas.ts#L161-L169

Added lines #L161 - L169 were not covered by tests

export const getScenarioResult = async (id: string) => {
const noResult = {
prevention: {
unknown: 1,
success: 0,
failure: 0,
},
detection: {
unknown: 1,
success: 0,
failure: 0,
},
human: {
unknown: 1,
success: 0,
failure: 0,
}
prevention: emptyResult,
detection: emptyResult,
human: emptyResult,

Check warning on line 175 in opencti-platform/opencti-graphql/src/database/xtm-obas.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/database/xtm-obas.ts#L173-L175

Added lines #L173 - L175 were not covered by tests
};
// OpenBAS not configured
if (isEmptyField(XTM_OPENBAS_URL) || isEmptyField(XTM_OPENBAS_TOKEN)) {
Expand All @@ -179,40 +184,14 @@
if (!exercise || !exercise.exercise_id) {
return noResult;
}
const prevention = exercise.exercise_global_score.filter((n: { type: string, value: number }) => n.type === 'PREVENTION').at(0);
const preventionResult = prevention.avgResult === 'UNKNOWN' ? {
unknown: 1,
success: 0,
failure: 0
} : {
unknown: prevention.distribution?.filter((n: { label: string, value: number }) => n.label === 'Pending').at(0).value,
success: prevention.distribution?.filter((n: { label: string, value: number }) => n.label === 'Successful').at(0).value,
failure: prevention.distribution?.filter((n: { label: string, value: number }) => n.label === 'Failed').at(0).value
};
const detection = exercise.exercise_global_score.filter((n: { type: string, value: number }) => n.type === 'DETECTION').at(0);
const detectionResult = detection.avgResult === 'UNKNOWN' ? {
unknown: 1,
success: 0,
failure: 0
} : {
unknown: detection.distribution?.filter((n: { label: string, value: number }) => n.label === 'Pending').at(0).value,
success: detection.distribution?.filter((n: { label: string, value: number }) => n.label === 'Successful').at(0).value,
failure: detection.distribution?.filter((n: { label: string, value: number }) => n.label === 'Failed').at(0).value
};
const humanResponse = exercise.exercise_global_score.filter((n: { type: string, value: number }) => n.type === 'HUMAN_RESPONSE').at(0);
const humanResponseResult = humanResponse.avgResult === 'UNKNOWN' ? {
unknown: 1,
success: 0,
failure: 0
} : {
unknown: humanResponse.distribution?.filter((n: { label: string, value: number }) => n.label === 'Pending').at(0).value,
success: humanResponse.distribution?.filter((n: { label: string, value: number }) => n.label === 'Successful').at(0).value,
failure: humanResponse.distribution?.filter((n: { label: string, value: number }) => n.label === 'Failed').at(0).value
};
const { exercise_global_score: exerciseGlobalScore } = exercise;
const prevention = extractExerciseResultByType(exerciseGlobalScore, 'PREVENTION');
const detection = extractExerciseResultByType(exerciseGlobalScore, 'DETECTION');
const human = extractExerciseResultByType(exerciseGlobalScore, 'HUMAN_RESPONSE');

Check warning on line 190 in opencti-platform/opencti-graphql/src/database/xtm-obas.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/database/xtm-obas.ts#L187-L190

Added lines #L187 - L190 were not covered by tests
return {
prevention: preventionResult,
detection: detectionResult,
human: humanResponseResult
prevention,
detection,
human,

Check warning on line 194 in opencti-platform/opencti-graphql/src/database/xtm-obas.ts

View check run for this annotation

Codecov / codecov/patch

opencti-platform/opencti-graphql/src/database/xtm-obas.ts#L192-L194

Added lines #L192 - L194 were not covered by tests
};
} catch (err) {
logApp.info('Scenario not found in OpenBAS', { err });
Expand Down