Skip to content

Commit 15c7246

Browse files
ozgengreenbonebot
authored andcommitted
add: add get_report_closed_cves GMP request
Implement the get_report_closed_cves GMP request command. Add unit tests to verify required arguments, filters, pagination handling, and details output.
1 parent b145895 commit 15c7246

5 files changed

Lines changed: 126 additions & 0 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
IntegrationConfigs,
2121
OCIImageTargets,
2222
ReportApplications,
23+
ReportClosedCVEs,
2324
ReportCVEs,
2425
ReportHosts,
2526
ReportOperatingSystems,
@@ -1178,3 +1179,27 @@ def get_report_cves(
11781179
details=details,
11791180
)
11801181
)
1182+
1183+
def get_report_closed_cves(
1184+
self,
1185+
report_id: EntityID,
1186+
*,
1187+
ignore_pagination: bool | None = None,
1188+
details: bool | None = True,
1189+
) -> T:
1190+
"""Request closed CVEs of a single report.
1191+
1192+
Args:
1193+
report_id: UUID of an existing report.
1194+
ignore_pagination: Whether to ignore the filter terms "first" and
1195+
"rows".
1196+
details: Request additional report closed CVE information details.
1197+
Defaults to True.
1198+
"""
1199+
return self._send_request_and_transform_response(
1200+
ReportClosedCVEs.get_report_closed_cves(
1201+
report_id=report_id,
1202+
ignore_pagination=ignore_pagination,
1203+
details=details,
1204+
)
1205+
)

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_closed_cves import (
21+
ReportClosedCVEs,
22+
)
2023
from gvm.protocols.gmp.requests.next._report_cves import (
2124
ReportCVEs,
2225
)
@@ -152,6 +155,7 @@
152155
"PortRangeType",
153156
"ReportApplications",
154157
"ReportCVEs",
158+
"ReportClosedCVEs",
155159
"ReportConfigParameter",
156160
"ReportConfigs",
157161
"ReportFormatType",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 ReportClosedCVEs:
9+
@classmethod
10+
def get_report_closed_cves(
11+
cls,
12+
report_id: EntityID,
13+
*,
14+
ignore_pagination: bool | None = None,
15+
details: bool | None = True,
16+
) -> Request:
17+
"""Request closed CVEs of a single report.
18+
19+
Args:
20+
report_id: UUID of an existing report.
21+
ignore_pagination: Whether to ignore the filter terms "first" and
22+
"rows".
23+
details: Request additional report closed CVE information details.
24+
Defaults to True.
25+
"""
26+
cmd = XmlCommand("get_report_closed_cves")
27+
28+
if not report_id:
29+
raise RequiredArgument(
30+
function=cls.get_report_closed_cves.__name__,
31+
argument="report_id",
32+
)
33+
34+
cmd.set_attribute("report_id", str(report_id))
35+
36+
if ignore_pagination is not None:
37+
cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination))
38+
39+
cmd.set_attribute("details", to_bool(details))
40+
41+
return cmd
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 GmpGetReportClosedCVEsTestMixin:
10+
def test_get_report_closed_cves_without_id(self):
11+
with self.assertRaises(RequiredArgument):
12+
self.gmp.get_report_closed_cves(None)
13+
14+
with self.assertRaises(RequiredArgument):
15+
self.gmp.get_report_closed_cves("")
16+
17+
def test_get_report_closed_cves_with_ignore_pagination(self):
18+
self.gmp.get_report_closed_cves(report_id="r1", ignore_pagination=True)
19+
20+
self.connection.send.has_been_called_with(
21+
b'<get_report_closed_cves report_id="r1" ignore_pagination="1" details="1"/>'
22+
)
23+
24+
self.gmp.get_report_closed_cves(report_id="r1", ignore_pagination=False)
25+
26+
self.connection.send.has_been_called_with(
27+
b'<get_report_closed_cves report_id="r1" ignore_pagination="0" details="1"/>'
28+
)
29+
30+
def test_get_report_closed_cves_with_details(self):
31+
self.gmp.get_report_closed_cves(report_id="r1", details=True)
32+
33+
self.connection.send.has_been_called_with(
34+
b'<get_report_closed_cves report_id="r1" details="1"/>'
35+
)
36+
37+
self.gmp.get_report_closed_cves(report_id="r1", details=False)
38+
39+
self.connection.send.has_been_called_with(
40+
b'<get_report_closed_cves report_id="r1" details="0"/>'
41+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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_closed_cves.test_get_report_closed_cves import (
8+
GmpGetReportClosedCVEsTestMixin,
9+
)
10+
11+
12+
class GmpGetReportClosedCVEsTestCase(
13+
GmpGetReportClosedCVEsTestMixin, GMPTestCase
14+
):
15+
pass

0 commit comments

Comments
 (0)