From 336b2474298dda59807ff19aac184d0b1b69a611 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 6 Feb 2022 15:07:17 -0500 Subject: cvss: add v2scores and tests (busted atm) --- cvss/v2scores_test.go | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 cvss/v2scores_test.go (limited to 'cvss/v2scores_test.go') diff --git a/cvss/v2scores_test.go b/cvss/v2scores_test.go new file mode 100644 index 0000000..b47cf05 --- /dev/null +++ b/cvss/v2scores_test.go @@ -0,0 +1,80 @@ +package cvss + +import ( + "reflect" + "testing" +) + +// build v2scores from slice of floats +func getTestScores(vals []float64) (v2Scores, error) { + // build expected score list + scores := make([]v2Score, 3) + for i, val := range(vals) { + if score, err := newV2Score(val); err != nil { + return v2Scores{}, err + } else { + scores[i] = score + } + } + + // build expected scores + return v2Scores { + scores[0], + scores[1], + scores[2], + }, nil +} + +func TestNewV2Scores(t *testing.T) { + passTests := []struct { + name string // test name + val string // test cvss v2 vector + exps []float64 // expected base, temporal, and env scores + } {{ + name: "CVE-2002-0392", + val: "AV:N/AC:L/Au:N/C:N/I:N/A:C", + exps: []float64 { 7.8, 6.4, 9.2 }, + }} + + for _, test := range(passTests) { + t.Run(test.name, func(t *testing.T) { + // build expected score list + expScores := make([]v2Score, 3) + for i, val := range(test.exps) { + if s, err := newV2Score(val); err != nil { + t.Error(err) + return + } else { + expScores[i] = s + } + } + + // build expected scores + exp := v2Scores { + expScores[0], + expScores[1], + expScores[2], + } + + // create vector, check for error + vec, err := newV2Vector(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) + return + } + }) + } +} -- cgit v1.2.3