aboutsummaryrefslogtreecommitdiff
path: root/internal/cvss/v2vector_test.go
blob: a9439573d9eee999c26505871520e5be6b3d68b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cvss

import (
  "testing"
)

// Test cvss v2
func TestCvssV2Parser(t *testing.T) {
  // test v2 vector
  test := "AV:L/AC:L/Au:N/C:N/I:N/A:P"
  expMetrics := []string { "AV:L", "AC:L", "Au:N", "C:N", "I:N", "A:P" }

  t.Run("TestV2Parser", func(t *testing.T) {
    // parse vector
    vec, err := NewVector(test)
    if err != nil {
      t.Error(err)
      return
    }

    // check version
    if vec.Version() != V20 {
      t.Errorf("got %s, exp %s", vec.Version(), V20)
      return
    }

    for i, m := range(vec.Metrics()) {
      got := m.String()
      if got != expMetrics[i] {
        t.Errorf("got %s, exp %s", got, expMetrics[i])
      }
    }
  })
}

// Test cvss v2
func TestInvalidV2Vector(t *testing.T) {
  // test invalid vector
  test := "AV:L/junk/Au:N/C:N/I:N/A:P"
  exp := "invalid CVSS 2.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
  }
}