diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-07 19:02:59 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-07 19:02:59 -0500 |
commit | f34d8eb8d5de5fe22e13c6dd81b4949c5379522c (patch) | |
tree | 2621d0235ed065b8cff216b061156ee117d6371a /cvss/v31vector_test.go | |
parent | 5919b5a0ee3f1a102a931d7b2147f805b0c15b43 (diff) | |
download | cvez-f34d8eb8d5de5fe22e13c6dd81b4949c5379522c.tar.bz2 cvez-f34d8eb8d5de5fe22e13c6dd81b4949c5379522c.zip |
cvss: add v31Vector.Scores() and initial tests
Diffstat (limited to 'cvss/v31vector_test.go')
-rw-r--r-- | cvss/v31vector_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/cvss/v31vector_test.go b/cvss/v31vector_test.go index d05edca..86fb8eb 100644 --- a/cvss/v31vector_test.go +++ b/cvss/v31vector_test.go @@ -1,6 +1,7 @@ package cvss import ( + "reflect" "testing" ) @@ -559,3 +560,56 @@ func TestIsV31VectorString(t *testing.T) { }) } } + +func TestV31VectorScores(t *testing.T) { + tests := []struct { + name string // test name + val string // v3.1 vector string + exp []float64 // expected scores + } {{ + name: "initial", + val: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N", + exp: []float64 { 0.0, 0.0, 0.0 }, + }, { + name: "initial I:H", + val: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", + exp: []float64 { 9.8, 9.8, 0.0 }, + }, { + name: "initial A:L", + val: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L", + exp: []float64 { 5.3, 5.3, 0.0 }, + }, { + name: "AV:A", + val: "CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L", + exp: []float64 { 6.3, 6.3, 0.0 }, + }} + + for _, test := range(tests) { + t.Run(test.val, func(t *testing.T) { + // create expected value + exp, err := NewScores(test.exp[0], test.exp[1], test.exp[2]) + if err != nil { + t.Error(err) + return + } + + // create vector + vec, err := newV31Vector(test.val) + if err != nil { + t.Error(err) + return + } + + // get scores + got, err := vec.Scores() + if err != nil { + t.Error(err) + return + } + + if !reflect.DeepEqual(got, exp) { + t.Errorf("got %v, exp %v", got, exp) + } + }) + } +} |