-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
090c04e
commit 36305c7
Showing
6 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package report | ||
|
||
//CvssScoreToSeverity calculate severity by cvss version and score | ||
//accept cvss version and score , return severity | ||
func CvssScoreToSeverity(cvss *CVSS) string { | ||
if cvss == nil { | ||
return "" | ||
} | ||
switch cvss.Version { | ||
case "v2": | ||
return cvssV2SeverityByScore(cvss.BaseScore) | ||
case "v3": | ||
return cvssV3SeverityByScore(cvss.BaseScore) | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
func cvssV3SeverityByScore(score float32) string { | ||
switch { | ||
case score == 0.0: | ||
return "None" | ||
case score >= 0.1 && score <= 3.9: | ||
return "Low" | ||
case score >= 4.0 && score <= 6.9: | ||
return "Medium" | ||
case score >= 7.0 && score <= 8.9: | ||
return "High" | ||
case score >= 9.0 && score <= 10.0: | ||
return "Critical" | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
func cvssV2SeverityByScore(score float32) string { | ||
switch { | ||
case score >= 0.0 && score <= 3.9: | ||
return "Low" | ||
case score >= 4.0 && score <= 6.9: | ||
return "Medium" | ||
case score >= 7.0 && score <= 10.0: | ||
return "High" | ||
default: | ||
return "None" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package report | ||
|
||
import "testing" | ||
|
||
func TestReverseString1(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
version string | ||
baseScore float32 | ||
want string | ||
}{ | ||
{name: "Low v2", version: "v2", baseScore: 1.0, want: "Low"}, | ||
{name: "Medium v2", version: "v2", baseScore: 4.0, want: "Medium"}, | ||
{name: "High v2", version: "v2", baseScore: 7.0, want: "High"}, | ||
{name: "Non Existing score v2", version: "v2", baseScore: 12.0, want: ""}, | ||
{name: "None v3", version: "v3", baseScore: 0.0, want: "None"}, | ||
{name: "low v3", version: "v3", baseScore: 1.0, want: "Low"}, | ||
{name: "Medium v3", version: "v3", baseScore: 4.0, want: "Medium"}, | ||
{name: "High v3", version: "v3", baseScore: 7.0, want: "High"}, | ||
{name: "Critical v3", version: "v3", baseScore: 9.0, want: "Critical"}, | ||
{name: "Non Existing score v3", version: "v3", baseScore: 12.0, want: ""}, | ||
{name: "Non existing version", version: "v1", baseScore: 9.0, want: ""}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := CvssScoreToSeverity(&CVSS{Version: tt.version, BaseScore: tt.baseScore}); got != tt.want { | ||
t.Errorf("CvssScoreToSeverity() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |