@@ -30,6 +30,94 @@ func TestLoadCSAF(t *testing.T) {
3030 require .Equal (t , vexDoc .Metadata .ID , "2022-EVD-UC-01-NA-001" )
3131}
3232
33+ func TestEffectiveStatement (t * testing.T ) {
34+ date1 := time .Date (2023 , 4 , 17 , 20 , 34 , 58 , 0 , time .UTC )
35+ date2 := time .Date (2023 , 4 , 18 , 20 , 34 , 58 , 0 , time .UTC )
36+ for _ , tc := range []struct {
37+ vexDoc * VEX
38+ vulnID string
39+ product string
40+ shouldNil bool
41+ expectedDate * time.Time
42+ expectedStatus Status
43+ }{
44+ {
45+ // Single statement
46+ vexDoc : & VEX {
47+ Statements : []Statement {
48+ {
49+ Vulnerability : "CVE-2014-123456" ,
50+ Timestamp : & date1 ,
51+ Products : []
string {
"pkg://[email protected] " },
52+ Status : StatusNotAffected ,
53+ },
54+ },
55+ },
56+ vulnID : "CVE-2014-123456" ,
57+ product :
"pkg://[email protected] " ,
58+ shouldNil : false ,
59+ expectedDate : & date1 ,
60+ expectedStatus : StatusNotAffected ,
61+ },
62+ {
63+ // Two consecutive statemente
64+ vexDoc : & VEX {
65+ Statements : []Statement {
66+ {
67+ Vulnerability : "CVE-2014-123456" ,
68+ Timestamp : & date1 ,
69+ Products : []
string {
"pkg://[email protected] " },
70+ Status : StatusUnderInvestigation ,
71+ },
72+ {
73+ Vulnerability : "CVE-2014-123456" ,
74+ Timestamp : & date2 ,
75+ Products : []
string {
"pkg://[email protected] " },
76+ Status : StatusNotAffected ,
77+ },
78+ },
79+ },
80+ vulnID : "CVE-2014-123456" ,
81+ product :
"pkg://[email protected] " ,
82+ shouldNil : false ,
83+ expectedDate : & date2 ,
84+ expectedStatus : StatusNotAffected ,
85+ },
86+ {
87+ // Different products
88+ vexDoc : & VEX {
89+ Statements : []Statement {
90+ {
91+ Vulnerability : "CVE-2014-123456" ,
92+ Timestamp : & date1 ,
93+ Products : []
string {
"pkg://[email protected] " },
94+ Status : StatusUnderInvestigation ,
95+ },
96+ {
97+ Vulnerability : "CVE-2014-123456" ,
98+ Timestamp : & date2 ,
99+ Products : []
string {
"pkg://[email protected] " },
100+ Status : StatusNotAffected ,
101+ },
102+ },
103+ },
104+ vulnID : "CVE-2014-123456" ,
105+ product :
"pkg://[email protected] " ,
106+ shouldNil : false ,
107+ expectedDate : & date1 ,
108+ expectedStatus : StatusUnderInvestigation ,
109+ },
110+ } {
111+ s := tc .vexDoc .EffectiveStatement (tc .product , tc .vulnID )
112+ if tc .shouldNil {
113+ require .Nil (t , s )
114+ } else {
115+ require .Equal (t , tc .expectedDate , s .Timestamp )
116+ require .Equal (t , tc .expectedStatus , s .Status )
117+ }
118+ }
119+ }
120+
33121func genTestDoc (t * testing.T ) VEX {
34122 ts , err := time .Parse (time .RFC3339 , "2022-12-22T16:36:43-05:00" )
35123 require .NoError (t , err )
0 commit comments