diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-01-31 22:07:06 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-01-31 22:07:06 -0500 |
commit | abcd9428d9eb6cc8ac0189e6443930a67ebcabda (patch) | |
tree | dbd3a1f78fe900514244588d50bab7d98eebe0ba /internal/cvss/v30vector_test.go | |
parent | a739c2c0116e3bbe3122ec08b13a38440a3f9b62 (diff) | |
download | cvez-abcd9428d9eb6cc8ac0189e6443930a67ebcabda.tar.bz2 cvez-abcd9428d9eb6cc8ac0189e6443930a67ebcabda.zip |
internal/cvss: add many tests
Diffstat (limited to 'internal/cvss/v30vector_test.go')
-rw-r--r-- | internal/cvss/v30vector_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/cvss/v30vector_test.go b/internal/cvss/v30vector_test.go new file mode 100644 index 0000000..fae3436 --- /dev/null +++ b/internal/cvss/v30vector_test.go @@ -0,0 +1,49 @@ +package cvss + +import ( + "testing" +) + +func TestV30Vector(t *testing.T) { + // test v3 vector + test := "CVSS:3.0/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:N/A:N" + expMetrics := []string { "AV:L", "AC:H", "PR:L", "UI:N", "S:U", "C:H", "I:N", "A:N" } + + t.Run("TestV30Vector", func(t *testing.T) { + // parse vector + vec, err := NewVector(test) + if err != nil { + t.Error(err) + return + } + + // check version + if vec.Version() != V30 { + t.Errorf("got %s, exp %s", vec.Version(), V30) + return + } + + for i, m := range(vec.Metrics()) { + got := m.String() + if got != expMetrics[i] { + t.Errorf("got %s, exp %s", got, expMetrics[i]) + } + } + }) +} + +func TestInvalidV30Vector(t *testing.T) { + // test invalid vector + test := "CVSS:3.0/AV:L/junk/PR:L/UI:N/S:U/C:H/I:N/A:N" + exp := "invalid CVSS 3.0 metric: junk" + + // parse vector + got, err := NewVector(test) + if err != nil && err.Error() != exp { + t.Errorf("got \"%s\", exp \"%s\"", err.Error(), err) + return + } else if err == nil { + t.Errorf("got \"%s\", exp badMetric", got) + return + } +} |