Skip to content

Commit 000834d

Browse files
ozgengreenbonebot
authored andcommitted
add: add get_report_cves GMP request
Implement the get_report_cves GMP request command. Add unit tests to verify required arguments, filters, pagination handling, and details output.
1 parent 0f3c5a9 commit 000834d

5 files changed

Lines changed: 149 additions & 0 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
IntegrationConfigs,
2121
OCIImageTargets,
2222
ReportApplications,
23+
ReportCVEs,
2324
ReportHosts,
2425
ReportOperatingSystems,
2526
ReportPorts,
@@ -1116,3 +1117,33 @@ def get_report_applications(
11161117
details=details,
11171118
)
11181119
)
1120+
1121+
def get_report_cves(
1122+
self,
1123+
report_id: EntityID,
1124+
*,
1125+
filter_string: str | None = None,
1126+
filter_id: str | None = None,
1127+
ignore_pagination: bool | None = None,
1128+
details: bool | None = True,
1129+
) -> T:
1130+
"""Request CVEs of a single report.
1131+
1132+
Args:
1133+
report_id: UUID of an existing report.
1134+
filter_string: Filter term to use to filter results in the report
1135+
filter_id: UUID of filter to use to filter results in the report
1136+
ignore_pagination: Whether to ignore the filter terms "first" and
1137+
"rows".
1138+
details: Request additional report CVE information details.
1139+
Defaults to True.
1140+
"""
1141+
return self._send_request_and_transform_response(
1142+
ReportCVEs.get_report_cves(
1143+
report_id=report_id,
1144+
filter_string=filter_string,
1145+
filter_id=filter_id,
1146+
ignore_pagination=ignore_pagination,
1147+
details=details,
1148+
)
1149+
)

gvm/protocols/gmp/requests/next/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from gvm.protocols.gmp.requests.next._report_applications import (
1818
ReportApplications,
1919
)
20+
from gvm.protocols.gmp.requests.next._report_cves import (
21+
ReportCVEs,
22+
)
2023
from gvm.protocols.gmp.requests.next._report_hosts import (
2124
ReportHosts,
2225
)
@@ -145,6 +148,7 @@
145148
"PortLists",
146149
"PortRangeType",
147150
"ReportApplications",
151+
"ReportCVEs",
148152
"ReportConfigParameter",
149153
"ReportConfigs",
150154
"ReportFormatType",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from gvm.errors import RequiredArgument
2+
from gvm.protocols.core import Request
3+
from gvm.protocols.gmp.requests import EntityID
4+
from gvm.utils import to_bool
5+
from gvm.xml import XmlCommand
6+
7+
8+
class ReportCVEs:
9+
@classmethod
10+
def get_report_cves(
11+
cls,
12+
report_id: EntityID,
13+
*,
14+
filter_string: str | None = None,
15+
filter_id: str | None = None,
16+
ignore_pagination: bool | None = None,
17+
details: bool | None = True,
18+
) -> Request:
19+
"""Request CVEs of a single report.
20+
21+
Args:
22+
report_id: UUID of an existing report.
23+
filter_string: Filter term to use to filter results in the report
24+
filter_id: UUID of filter to use to filter results in the report
25+
ignore_pagination: Whether to ignore the filter terms "first" and
26+
"rows".
27+
details: Request additional report CVE information details.
28+
Defaults to True.
29+
"""
30+
cmd = XmlCommand("get_report_cves")
31+
32+
if not report_id:
33+
raise RequiredArgument(
34+
function=cls.get_report_cves.__name__, argument="report_id"
35+
)
36+
37+
cmd.set_attribute("report_id", str(report_id))
38+
39+
cmd.add_filter(filter_string, filter_id)
40+
41+
if ignore_pagination is not None:
42+
cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination))
43+
44+
cmd.set_attribute("details", to_bool(details))
45+
46+
return cmd
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2026 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
from gvm.errors import RequiredArgument
7+
8+
9+
class GmpGetReportCVEsTestMixin:
10+
def test_get_report_cves_without_id(self):
11+
with self.assertRaises(RequiredArgument):
12+
self.gmp.get_report_cves(None)
13+
14+
with self.assertRaises(RequiredArgument):
15+
self.gmp.get_report_cves("")
16+
17+
def test_get_report_cves_with_filter_string(self):
18+
self.gmp.get_report_cves(report_id="r1", filter_string="name=foo")
19+
20+
self.connection.send.has_been_called_with(
21+
b'<get_report_cves report_id="r1" filter="name=foo" details="1"/>'
22+
)
23+
24+
def test_get_report_cves_with_filter_id(self):
25+
self.gmp.get_report_cves(report_id="r1", filter_id="f1")
26+
27+
self.connection.send.has_been_called_with(
28+
b'<get_report_cves report_id="r1" filt_id="f1" details="1"/>'
29+
)
30+
31+
def test_get_report_cves_with_ignore_pagination(self):
32+
self.gmp.get_report_cves(report_id="r1", ignore_pagination=True)
33+
34+
self.connection.send.has_been_called_with(
35+
b'<get_report_cves report_id="r1" ignore_pagination="1" details="1"/>'
36+
)
37+
38+
self.gmp.get_report_cves(report_id="r1", ignore_pagination=False)
39+
40+
self.connection.send.has_been_called_with(
41+
b'<get_report_cves report_id="r1" ignore_pagination="0" details="1"/>'
42+
)
43+
44+
def test_get_report_cves_with_details(self):
45+
self.gmp.get_report_cves(report_id="r1", details=True)
46+
47+
self.connection.send.has_been_called_with(
48+
b'<get_report_cves report_id="r1" details="1"/>'
49+
)
50+
51+
self.gmp.get_report_cves(report_id="r1", details=False)
52+
53+
self.connection.send.has_been_called_with(
54+
b'<get_report_cves report_id="r1" details="0"/>'
55+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: 2026 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
from ...gmpnext import GMPTestCase
7+
from .report_cves.test_get_report_cves import (
8+
GmpGetReportCVEsTestMixin,
9+
)
10+
11+
12+
class GmpGetReportCVEsTestCase(GmpGetReportCVEsTestMixin, GMPTestCase):
13+
pass

0 commit comments

Comments
 (0)