Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CPE match API tests + small fixes #1074

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pontos/nvd/cpe_match/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async def cpe_match(self, match_criteria_id: str) -> CPEMatchString:
raise PontosError("Missing Match Criteria ID.")

response = await self._get(
params={"matchCriteriaId": match_criteria_id}
params={"matchCriteriaId": str(match_criteria_id)}
)
response.raise_for_status()
data = response.json(object_hook=convert_camel_case)
Expand Down
4 changes: 2 additions & 2 deletions pontos/nvd/models/cpe_match_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CPEMatchString(Model):
version_end_including: Optional end of the matching version range, including the given version
version_end_excluding: Optional end of the matching version range, excluding the given version
status: Status of the CPE match
cpe_last_modified: The date the CPEs list of the match was last modified
cpe_last_modified: Optional date the CPEs list of the match was last modified
created: Creation date of the CPE
last_modified: Last modification date of the CPE
matches: List of CPEs matching the criteria string and the optional range limits
Expand All @@ -47,9 +47,9 @@ class CPEMatchString(Model):
match_criteria_id: UUID
criteria: str
status: str
cpe_last_modified: datetime
created: datetime
last_modified: datetime
cpe_last_modified: Optional[datetime] = None
matches: List[CPEMatch] = field(default_factory=list)
version_start_including: Optional[str] = None
version_start_excluding: Optional[str] = None
Expand Down
40 changes: 40 additions & 0 deletions tests/nvd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@ def get_cpe_data(update: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
return data


def get_cpe_match_data(
update: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
data = {
"cpe_last_modified": "2019-07-22T16:37:38.133",
"created": "2019-06-17T09:16:33.960",
"criteria": "cpe:2.3:a:sun:jre:*:update3:*:*:*:*:*:*",
"last_modified": "2019-06-17T09:16:44.000",
"match_criteria_id": "EAB2C9C2-F685-450B-9980-553966FC3B63",
"matches": [
{
"cpe_name": "cpe:2.3:a:sun:jre:1.3.0:update3:*:*:*:*:*:*",
"cpe_name_id": "2D284534-DA21-43D5-9D89-07F19AE400EA",
},
{
"cpe_name": "cpe:2.3:a:sun:jre:1.4.1:update3:*:*:*:*:*:*",
"cpe_name_id": "CE55E1DF-8EA2-41EA-9C51-1BAE728CA094",
},
{
"cpe_name": "cpe:2.3:a:sun:jre:1.4.2:update3:*:*:*:*:*:*",
"cpe_name_id": "A09C4E47-6548-40C5-8458-5C07C3292C86",
},
{
"cpe_name": "cpe:2.3:a:sun:jre:1.5.0:update3:*:*:*:*:*:*",
"cpe_name_id": "C484A93A-2677-4501-A6E0-E4ADFFFB549E",
},
{
"cpe_name": "cpe:2.3:a:sun:jre:1.6.0:update3:*:*:*:*:*:*",
"cpe_name_id": "C518A954-369E-453E-8E17-2AF639150115",
},
],
"status": "Active",
"version_end_including": "1.6.0",
}

if update:
data.update(update)
return data


def get_cve_change_data(
data: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
Expand Down
4 changes: 4 additions & 0 deletions tests/nvd/cpe_match/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
Loading
Loading