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) } }