aboutsummaryrefslogtreecommitdiff
path: root/internal/cvss/v3key_test.go
blob: ccf2b8f90a882dbb4926ff585369472506fe5fc1 (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
117
118
119
120
121
122
123
124
package cvss

import (
  "testing"
)

func TestV3KeyString(t *testing.T) {
  tests := []struct {
    val v3Key
    exp string
  } {
    { v3AttackVector, "AV" },
    { v3AttackComplexity, "AC" },
    { v3PrivilegesRequired, "PR" },
    { v3UserInteraction, "UI" },
    { v3Scope, "S" },
    { v3Confidentiality, "C" },
    { v3Integrity, "I" },
    { v3Availability, "A" },
    { v3ExploitCodeMaturity, "E" },
    { v3RemediationLevel, "RL" },
    { v3ReportConfidence, "RC" },
    { v3ConfidentialityRequirement, "CR" },
    { v3IntegrityRequirement, "IR" },
    { v3AvailabilityRequirement, "AR" },
    { v3ModifiedAttackVector, "MAV" },
    { v3ModifiedAttackComplexity, "MAC" },
    { v3ModifiedPrivilegesRequired, "MPR" },
    { v3ModifiedUserInteraction, "MUI" },
    { v3ModifiedScope, "MS" },
    { v3ModifiedConfidentiality, "MC" },
    { v3ModifiedIntegrity, "MI" },
    { v3ModifiedAvailability, "MA" },

    { v3Key(255), "v3Key(255)" },
  }

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

func TestV3KeyName(t *testing.T) {
  tests := []struct {
    val v3Key
    exp string
  } {
    { v3AttackVector, "Attack Vector" },
    { v3AttackComplexity, "Attack Complexity" },
    { v3PrivilegesRequired, "Privileges Required" },
    { v3UserInteraction, "User Interaction" },
    { v3Scope, "Scope" },
    { v3Confidentiality, "Confidentiality" },
    { v3Integrity, "Integrity" },
    { v3Availability, "Availability" },
    { v3ExploitCodeMaturity, "Exploit Code Maturity" },
    { v3RemediationLevel, "Remediation Level" },
    { v3ReportConfidence, "Report Confidence" },
    { v3ConfidentialityRequirement, "Confidentiality Requirement" },
    { v3IntegrityRequirement, "Integrity Requirement" },
    { v3AvailabilityRequirement, "Availability Requirement" },
    { v3ModifiedAttackVector, "Modified Attack Vector" },
    { v3ModifiedAttackComplexity, "Modified Attack Complexity" },
    { v3ModifiedPrivilegesRequired, "Modified Privileges Required" },
    { v3ModifiedUserInteraction, "Modified User Interaction" },
    { v3ModifiedScope, "Modified Scope" },
    { v3ModifiedConfidentiality, "Modified Confidentiality" },
    { v3ModifiedIntegrity, "Modified Integrity" },
    { v3ModifiedAvailability, "Modified Availability" },
  }

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

func TestV3KeyCategory(t *testing.T) {
  tests := []struct {
    val v3Key
    exp Category
  } {
    { v3AttackVector, Base },
    { v3AttackComplexity, Base },
    { v3PrivilegesRequired, Base },
    { v3UserInteraction, Base },
    { v3Scope, Base },
    { v3Confidentiality, Base },
    { v3Integrity, Base },
    { v3Availability, Base },
    { v3ExploitCodeMaturity, Temporal },
    { v3RemediationLevel, Temporal },
    { v3ReportConfidence, Temporal },
    { v3ConfidentialityRequirement, Environmental },
    { v3IntegrityRequirement, Environmental },
    { v3AvailabilityRequirement, Environmental },
    { v3ModifiedAttackVector, Environmental },
    { v3ModifiedAttackComplexity, Environmental },
    { v3ModifiedPrivilegesRequired, Environmental },
    { v3ModifiedUserInteraction, Environmental },
    { v3ModifiedScope, Environmental },
    { v3ModifiedConfidentiality, Environmental },
    { v3ModifiedIntegrity, Environmental },
    { v3ModifiedAvailability, Environmental },
  }

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