diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-06 15:07:17 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-06 15:07:17 -0500 |
commit | 336b2474298dda59807ff19aac184d0b1b69a611 (patch) | |
tree | 2f72116ddafd53036e007aa3dbb94a6c78a614ac /cvss/v2scores_test.go | |
parent | 210c57382dfcd1e1d307609d7a34afd4d58b5c1d (diff) | |
download | cvez-336b2474298dda59807ff19aac184d0b1b69a611.tar.bz2 cvez-336b2474298dda59807ff19aac184d0b1b69a611.zip |
cvss: add v2scores and tests (busted atm)
Diffstat (limited to 'cvss/v2scores_test.go')
-rw-r--r-- | cvss/v2scores_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
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 + } + }) + } +} |