Skip to content

Commit

Permalink
#7 revamping likelihood and risk system
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewNobes committed Jun 14, 2022
1 parent 683c8c7 commit 631e8cc
Show file tree
Hide file tree
Showing 11 changed files with 418 additions and 410 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import calculateRisk from "../BinaryRiskMatrixLogic/calculateRisk";

import { calculateHarmCapacity } from "../BinaryRiskMatrixLogic/calculateImpact/calculateHarmCapacity/calculateHarmCapacity";
import { calculateImpactValuation } from "../BinaryRiskMatrixLogic/calculateImpact/calculateImpactValuation/calculateImpactValuation";
import { calculateThreatScope } from "../BinaryRiskMatrixLogic/calculateLikelihood/calculateThreatScope/calculateThreatScope";
import { calculateProtectionWeakness } from "../BinaryRiskMatrixLogic/calculateLikelihood/calculateProtectionWeakness/calculateProtectionWeakness";
import { calculateAttackEfficiency } from "../BinaryRiskMatrixLogic/calculateLikelihood/calculateAttackEfficiency/calculateAttackEfficiency";
import { calculateOccurrence } from "../BinaryRiskMatrixLogic/calculateLikelihood/calculateOccurrence/calculateOccurrence";

const calculateValues = (userResponses) => {
const values = {};
Expand All @@ -22,6 +26,26 @@ const calculateValues = (userResponses) => {
);
values.threatImpact = calculateImpact(values.impactValuation);

values.threatScore = calculateThreatScope(userResponses[0], userResponses[1]);
values.protectionWeakness = calculateProtectionWeakness(
values.threatScore,
userResponses[2],
userResponses[3]
);
values.attackEfficiency = calculateAttackEfficiency(
values.protectionWeakness
);
values.occurrence = calculateOccurrence(
values.attackEfficiency,
userResponses[4],
userResponses[5]
);
values.threatLikelihood = calculateLikelihood(values.occurrence);

values.threatRisk = calculateRisk(
values.threatLikelihood,
values.threatImpact
);
return values;
};

Expand Down Expand Up @@ -57,24 +81,18 @@ export const BinaryRiskMatrixForm = () => {
e.preventDefault();

const values = [Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10];
const likelihoodResults = calculateLikelihood(values);
const impactResults = calculateImpact(values);

const calculatedValues = calculateValues(values);

appendHarmCapacity(calculatedValues.harmCapacity);
appendImpactValuation(calculatedValues.impactValuation);

appendThreatScore(likelihoodResults[0]);
appendProtectionWeakness(likelihoodResults[1]);
appendAttackEfficiency(likelihoodResults[2]);
appendOccurrence(likelihoodResults[3]);

appendLikelihood(likelihoodResults[4]);
appendThreatScore(calculatedValues.threatScore);
appendProtectionWeakness(calculatedValues.protectionWeakness);
appendAttackEfficiency(calculatedValues.attackEfficiency);
appendOccurrence(calculatedValues.occurrence);
appendLikelihood(calculatedValues.threatLikelihood);
appendImpact(calculatedValues.threatImpact);

const risk = calculateRisk(likelihoodResults[4], impactResults[2]);
appendRisk(risk);
appendRisk(calculatedValues.threatRisk);
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
*
* @param {string} protectionWeakness The protection weakness (see calculateProtectionWeakness)
* @returns {string} The attack efficiency
*/
export const calculateAttackEfficiency = (protectionWeakness) => {
return protectionWeakness;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { calculateAttackEfficiency } from "./calculateAttackEfficiency";

describe("testing the calculateAttackEfficiency function", () => {
it("should return High if the protectionWeakness is High", () => {
const expectValue = "High";
const protectionWeakness = "High";
expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue);
});

it("should return Medium if the protectionWeakness is Medium", () => {
const expectValue = "Medium";
const protectionWeakness = "Medium";
expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue);
});

it("should return Low if the protectionWeakness is Low", () => {
const expectValue = "Low";
const protectionWeakness = "Low";
expect(calculateAttackEfficiency(protectionWeakness)).toBe(expectValue);
});
});
Original file line number Diff line number Diff line change
@@ -1,110 +1,4 @@
/**
*
* @param {boolean[]} values The users selected values for the questions in the binary risk matrix.
* @returns {string} The threat likelihood.
*/
export const calculateLikelihood = (values) => {
const threatScore = calculateThreatScope(values[0], values[1]);
const protectionWeakness = calculateProtectionWeakness(
threatScore,
values[2],
values[3]
);
const attackEfficiency = calculateAttackEfficiency(protectionWeakness);
const occurrence = calculateOccurrence(
attackEfficiency,
values[4],
values[5]
);

export const calculateLikelihood = (occurrence) => {
const threatLikelihood = occurrence;
const likelihoodResults = [
threatScore,
protectionWeakness,
attackEfficiency,
occurrence,
threatLikelihood,
];
return likelihoodResults;
};

/**
*
* @param {boolean} Q1 The users answer for Q1.
* @param {boolean} Q2 The users answer for Q2.
* @returns {string} The threat scope
*/
export const calculateThreatScope = (Q1, Q2) => {
if (Q1 === true && Q2 === true) {
return "High";
} else {
if (Q1 === true || Q2 === true) {
return "Medium";
} else {
return "Low";
}
}
};

/**
*
* @param {string} threatScore
* @param {boolean} Q3
* @param {boolean} Q4
* @returns {string} The protection weakness
*/
export const calculateProtectionWeakness = (threatScore, Q3, Q4) => {
if (Q3 === true && Q4 === true) {
if (threatScore === "Low") {
return "Medium";
} else {
return "High";
}
} else {
if (Q3 === true || Q4 === true) {
return threatScore;
} else {
if (threatScore === "High") {
return "Medium";
} else {
return "Low";
}
}
}
};

/**
*
* @param {string} protectionWeakness The protection weakness (see calculateProtectionWeakness)
* @returns {string} The attack efficiency
*/
export const calculateAttackEfficiency = (protectionWeakness) => {
return protectionWeakness;
};

/**
*
* @param {string} attackEfficiency The attack efficiency
* @param {boolean} Q5 The answer to Q5.
* @param {boolean} Q6 The answer to Q6.
* @returns {string} The threat occurrence
*/
export const calculateOccurrence = (attackEfficiency, Q5, Q6) => {
if (Q5 === true && Q6 === true) {
if (attackEfficiency === "Low") {
return "Medium";
} else {
return "High";
}
} else {
if (Q5 === true || Q6 === true) {
return attackEfficiency;
} else {
if (attackEfficiency === "High") {
return "Medium";
} else {
return "Low";
}
}
}
return threatLikelihood;
};
Loading

0 comments on commit 631e8cc

Please sign in to comment.