@@ -118,3 +118,36 @@ def test_non_nvd_advisory_ignored(self):
118
118
# Check that the vulnerability still has no summary
119
119
vulnerability .refresh_from_db ()
120
120
self .assertEqual (vulnerability .summary , "" )
121
+
122
+ def test_multiple_matching_advisories (self ):
123
+ """
124
+ Test that the most recent matching advisory is used when there are multiple.
125
+ """
126
+ vulnerability = Vulnerability .objects .create (
127
+ vulnerability_id = "VCID-1234" ,
128
+ summary = "" ,
129
+ )
130
+ alias = Alias .objects .create (alias = "CVE-2024-1234" , vulnerability = vulnerability )
131
+
132
+ # Create two NVD advisories with the same alias
133
+ Advisory .objects .create (
134
+ summary = "First matching advisory" ,
135
+ created_by = "nvd_importer" ,
136
+ date_collected = datetime .datetime (2024 , 1 , 1 , tzinfo = pytz .UTC ),
137
+ aliases = ["CVE-2024-1234" ],
138
+ )
139
+
140
+ Advisory .objects .create (
141
+ summary = "Second matching advisory" ,
142
+ created_by = "nvd_importer" ,
143
+ date_collected = datetime .datetime (2024 , 1 , 2 , tzinfo = pytz .UTC ),
144
+ aliases = ["CVE-2024-1234" ],
145
+ )
146
+
147
+ # Run the pipeline
148
+ pipeline = FillVulnerabilitySummariesPipeline ()
149
+ pipeline .fill_missing_summaries ()
150
+
151
+ # Check that the vulnerability now has the most recent summary
152
+ vulnerability .refresh_from_db ()
153
+ self .assertEqual (vulnerability .summary , "Second matching advisory" )
0 commit comments