Skip to content

Commit 636e8f4

Browse files
authored
Merge branch 'main' into add/get-report-tls-certs
2 parents a89f04d + 000834d commit 636e8f4

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,
@@ -1147,3 +1148,33 @@ def get_report_applications(
11471148
details=details,
11481149
)
11491150
)
1151+
1152+
def get_report_cves(
1153+
self,
1154+
report_id: EntityID,
1155+
*,
1156+
filter_string: str | None = None,
1157+
filter_id: str | None = None,
1158+
ignore_pagination: bool | None = None,
1159+
details: bool | None = True,
1160+
) -> T:
1161+
"""Request CVEs of a single report.
1162+
1163+
Args:
1164+
report_id: UUID of an existing report.
1165+
filter_string: Filter term to use to filter results in the report
1166+
filter_id: UUID of filter to use to filter results in the report
1167+
ignore_pagination: Whether to ignore the filter terms "first" and
1168+
"rows".
1169+
details: Request additional report CVE information details.
1170+
Defaults to True.
1171+
"""
1172+
return self._send_request_and_transform_response(
1173+
ReportCVEs.get_report_cves(
1174+
report_id=report_id,
1175+
filter_string=filter_string,
1176+
filter_id=filter_id,
1177+
ignore_pagination=ignore_pagination,
1178+
details=details,
1179+
)
1180+
)

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
)
@@ -148,6 +151,7 @@
148151
"PortLists",
149152
"PortRangeType",
150153
"ReportApplications",
154+
"ReportCVEs",
151155
"ReportConfigParameter",
152156
"ReportConfigs",
153157
"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)