Merge pull request #12194 from reasonerjt/unknown-serverity-lower

Lower the severity of a "Unknown" vulnerability
This commit is contained in:
Daniel Jiang 2020-06-10 20:31:26 +08:00 committed by GitHub
commit 9b4f2cb0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -49,7 +49,7 @@ type Severity string
// Code returns the int code of the severity for comparing. // Code returns the int code of the severity for comparing.
func (s Severity) Code() int { func (s Severity) Code() int {
switch s { switch s {
case None: case None, Unknown:
return 0 return 0
case Negligible: case Negligible:
return 1 return 1
@ -62,7 +62,7 @@ func (s Severity) Code() int {
case Critical: case Critical:
return 5 return 5
default: default:
// Assign the highest code to the unknown severity to provide more secure protection. // Assign the highest code to the unrecognized severity to provide more secure protection.
return 99 return 99
} }
} }

View File

@ -16,6 +16,8 @@ package vuln
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestParseSeverityVersion3(t *testing.T) { func TestParseSeverityVersion3(t *testing.T) {
@ -50,3 +52,12 @@ func TestParseSeverityVersion3(t *testing.T) {
}) })
} }
} }
func TestCode(t *testing.T) {
assert.True(t, Critical.Code() > High.Code())
assert.True(t, High.Code() > Medium.Code())
assert.True(t, Medium.Code() > Low.Code())
assert.True(t, Low.Code() > Negligible.Code())
assert.True(t, Negligible.Code() > Unknown.Code())
assert.True(t, Unknown.Code() == None.Code())
}