Skip to content

Commit 328620a

Browse files
authored
Update CVE items to be unique and update tests see #905 (#914)
2 parents 3b9a7ea + 773470e commit 328620a

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

data/schema/v2/Decision_Point_Value_Selection-2-0-0.schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@
191191
"type": "string"
192192
},
193193
"minItems": 1,
194-
"type": "array"
194+
"type": "array",
195+
"uniqueItems": true
195196
},
196197
"selections": {
197198
"title": "Selections",

src/ssvc/selection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ class SelectionList(_Timestamped, BaseModel):
224224
["VU#999999", "GHSA-0123-4567-89ab"],
225225
],
226226
min_length=1,
227+
json_schema_extra={"uniqueItems": True},
227228
)
228229
selections: list[Selection] = Field(
229230
...,
@@ -297,6 +298,8 @@ def validate_target_ids(
297298
for item in value:
298299
if not isinstance(item, str):
299300
raise ValueError("Each target_id must be a string.")
301+
if len(value) != len(set(value)):
302+
raise ValueError("target_ids must not contain duplicates.")
300303
return value
301304

302305
def add_selection(self, selection: Selection) -> None:

src/test/test_selections.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,15 @@ def test_target_ids_validation(self):
282282
target_ids=[123], # Invalid: not a string
283283
)
284284

285+
# Test invalid target_ids (duplicate items)
286+
with self.assertRaises(ValueError):
287+
SelectionList(
288+
selections=[self.s1],
289+
timestamp=datetime.now(),
290+
# Invalid: due to duplicates
291+
target_ids=["CVE-1900-1234","CVE-1900-1234"],
292+
)
293+
285294
def test_add_selection_method(self):
286295
"""Test the add_selection method."""
287296
initial_count = len(self.selections.selections)

0 commit comments

Comments
 (0)