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

Add temp env ratings #67

Merged
merged 6 commits into from
Oct 21, 2020
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Sometimes it is useful to get a qualitative rating of a score
const vector = CVSS("CVSS:3.0/AV:N/AC:H/PR:L/UI:R/S:C/C:N/I:L/A:L");

console.log(vector.getRating()); // Medium
console.log(vector.getTemporalRating()); // Medium
console.log(vector.getEnvironmentalRating()); // Low
```

A few useful variables/functions to work with the vectors:
Expand Down
24 changes: 23 additions & 1 deletion lib/cvss.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function CVSS(vector) {
}

/**
* Calculates the Rating of the given vector
* Calculates the Base Rating of the given vector
* Calls a function from util.js
*
* @returns {String} returns one of the five possible ratings
Expand All @@ -37,6 +37,26 @@ function CVSS(vector) {
return util.getRating(getScore());
}

/**
* Calculates the Temporal Rating of the given vector
* Calls a function from util.js
*
* @returns {String} returns one of the five possible ratings
*/
function getTemporalRating() {
return util.getRating(getTemporalScore());
}

/**
* Calculates the Environmental Rating of the given vector
* Calls a function from util.js
*
* @returns {String} returns one of the five possible ratings
*/
function getEnvironmentalRating() {
return util.getRating(getEnvironmentalScore());
}

/**
* Checks if the given vector is valid
* Calls a function from util.js
Expand Down Expand Up @@ -127,6 +147,8 @@ function CVSS(vector) {
getTemporalScore,
getEnvironmentalScore,
getRating,
getTemporalRating,
getEnvironmentalRating,
getVectorObject,
getDetailedVectorObject,
getVersion,
Expand Down
21 changes: 21 additions & 0 deletions test/cvss.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,52 @@ describe("Rating Tests", () => {
const vector = CVSS("CVSS:3.0/AV:N/AC:H/PR:H/UI:R/S:U/C:N/I:N/A:N");
expect(vector.getScore()).toBe(0);
expect(vector.getRating()).toBe("None");
expect(vector.getTemporalRating()).toBe("None");
expect(vector.getEnvironmentalRating()).toBe("None");
});

it("Should return 'Low' if the vector's score is >= 0.1 and <= 3.9", () => {
const vector = CVSS("CVSS:3.0/AV:N/AC:H/PR:H/UI:R/S:U/C:N/I:L/A:N");
expect(vector.getScore()).toBe(2);
expect(vector.getRating()).toBe("Low");
expect(vector.getTemporalRating()).toBe("Low");
expect(vector.getEnvironmentalRating()).toBe("Low");
});

it("Should return 'Medium' if the vector's score is >= 4.0 and <= 6.9", () => {
const vector = CVSS("CVSS:3.0/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:N/A:N");
expect(vector.getScore()).toBe(4.2);
expect(vector.getRating()).toBe("Medium");
expect(vector.getTemporalRating()).toBe("Medium");
expect(vector.getEnvironmentalRating()).toBe("Medium");
});

it("Should return 'High' if the vector's score is >= 7.0 and <= 8.9", () => {
const vector = CVSS("CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H");
expect(vector.getScore()).toBe(8.8);
expect(vector.getRating()).toBe("High");
expect(vector.getTemporalRating()).toBe("High");
expect(vector.getEnvironmentalRating()).toBe("High");
});

it("Should return 'Critical' if the vector's score is >= 9.0 and <= 10.0", () => {
const vector = CVSS("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H");
expect(vector.getScore()).toBe(9.8);
expect(vector.getRating()).toBe("Critical");
expect(vector.getTemporalRating()).toBe("Critical");
expect(vector.getEnvironmentalRating()).toBe("Critical");
});

it("Should be able to discern individual ratings (base, temp, env) even if these don't match", () => {
const vector = CVSS("CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:N/A:N/E:U/RL:O/RC:U/CR:H/IR:H/AR:H/MAV:N/MAC:L/MPR:N/MUI:N/MS:U/MC:H/MI:H/MA:H");
expect(vector.getScore()).toBe(4.3);
expect(vector.getRating()).toBe("Medium");
expect(vector.getTemporalScore()).toBe(3.5);
expect(vector.getTemporalRating()).toBe("Low");
expect(vector.getEnvironmentalScore()).toBe(7.8);
expect(vector.getEnvironmentalRating()).toBe("High");
});

});

describe("Vector Object Tests", () => {
Expand Down