aboutsummaryrefslogtreecommitdiff
path: root/cvss/v2key_test.go
blob: a54f4e79d68d917f4fcd7a0abf6f70209e50cfd4 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package cvss

import "testing"

func TestV2KeyString(t *testing.T) {
  tests := []struct {
    key v2Key
    exp string
  } {
    { v2AccessVector, "AV" },
    { v2AccessComplexity, "AC" },
    { v2Authentication, "Au" },
    { v2ConfidentialityImpact, "C" },
    { v2IntegrityImpact, "I" },
    { v2AvailabilityImpact, "A" },
    { v2Exploitability, "E" },
    { v2RemediationLevel, "RL" },
    { v2ReportConfidence, "RC" },
    { v2CollateralDamagePotential, "CDP" },
    { v2TargetDistribution, "TD" },
    { v2ConfidentialityRequirement, "CR" },
    { v2IntegrityRequirement, "IR" },
    { v2AvailabilityRequirement, "AR" },

    { v2Key(255), "v2Key(255)" },
  }

  for _, test := range(tests) {
    t.Run(test.exp, func(t *testing.T) {
      got := test.key.String()
      if got != test.exp {
        t.Errorf("got: \"%s\", exp: \"%s\"", got, test.exp)
      }
    })
  }
}

func TestV2KeyName(t *testing.T) {
  tests := []struct {
    key v2Key
    exp string
  } {
    { v2AccessVector, "Access Vector" },
    { v2AccessComplexity, "Access Complexity" },
    { v2Authentication, "Authentication" },
    { v2ConfidentialityImpact, "Confidentiality Impact" },
    { v2IntegrityImpact, "Integrity Impact" },
    { v2AvailabilityImpact, "Availability Impact" },
    { v2Exploitability, "Exploitability" },
    { v2RemediationLevel, "Remediation Level" },
    { v2ReportConfidence, "Report Confidence" },
    { v2CollateralDamagePotential, "Collateral Damage Potential" },
    { v2TargetDistribution, "Target Distribution" },
    { v2ConfidentialityRequirement, "Confidentiality Requirement" },
    { v2IntegrityRequirement, "Integrity Requirement" },
    { v2AvailabilityRequirement, "Availability Requirement" },
  }

  for _, test := range(tests) {
    t.Run(test.exp, func(t *testing.T) {
      got := test.key.Name()
      if got != test.exp {
        t.Errorf("got: \"%s\", exp: \"%s\"", got, test.exp)
      }
    })
  }
}

func TestV2KeyCategory(t *testing.T) {
  tests := []struct {
    key v2Key
    exp Category
  } {
    { v2AccessVector, Base },
    { v2AccessComplexity, Base },
    { v2Authentication, Base },
    { v2ConfidentialityImpact, Base },
    { v2IntegrityImpact, Base },
    { v2AvailabilityImpact, Base },
    { v2Exploitability, Temporal },
    { v2RemediationLevel, Temporal },
    { v2ReportConfidence, Temporal },
    { v2CollateralDamagePotential, Environmental },
    { v2TargetDistribution, Environmental},
    { v2ConfidentialityRequirement, Environmental},
    { v2IntegrityRequirement, Environmental},
    { v2AvailabilityRequirement, Environmental},
  }

  for _, test := range(tests) {
    t.Run(test.key.String(), func(t *testing.T) {
      got := test.key.Category()
      if got != test.exp {
        t.Errorf("got: \"%s\", exp: \"%s\"", got, test.exp)
      }
    })
  }
}

func TestInvalidV2KeyName(t *testing.T) {
  exp := "invalid"
  got := v2Key(255).Name()

  if got != exp {
    t.Errorf("got: \"%s\", exp: \"%s\"", got, exp)
  }
}

func TestInvalidV2KeyCategory(t *testing.T) {
  exp := InvalidCategory
  got := v2Key(255).Category()

  if got != exp {
    t.Errorf("got: \"%s\", exp: \"%s\"", got, exp)
  }
}