diff --git a/gvm/protocols/gmp/_gmpnext.py b/gvm/protocols/gmp/_gmpnext.py index bd55f222..83768976 100644 --- a/gvm/protocols/gmp/_gmpnext.py +++ b/gvm/protocols/gmp/_gmpnext.py @@ -27,6 +27,7 @@ ReportOperatingSystems, ReportPorts, ReportTlsCertificates, + ReportVulnerabilities, Tasks, ) from .requests.v224 import HostsOrdering @@ -1234,3 +1235,33 @@ def get_report_errors( details=details, ) ) + + def get_report_vulnerabilities( + self, + report_id: EntityID, + *, + filter_string: str | None = None, + filter_id: str | None = None, + ignore_pagination: bool | None = None, + details: bool | None = True, + ) -> T: + """Request vulnerabilities of a single report. + + Args: + report_id: UUID of an existing report. + filter_string: Filter term to use to filter results in the report + filter_id: UUID of filter to use to filter results in the report + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Request additional report vulnerability information details. + Defaults to True. + """ + return self._send_request_and_transform_response( + ReportVulnerabilities.get_report_vulnerabilities( + report_id=report_id, + filter_string=filter_string, + filter_id=filter_id, + ignore_pagination=ignore_pagination, + details=details, + ) + ) diff --git a/gvm/protocols/gmp/requests/next/__init__.py b/gvm/protocols/gmp/requests/next/__init__.py index 569761bb..71c2cd28 100644 --- a/gvm/protocols/gmp/requests/next/__init__.py +++ b/gvm/protocols/gmp/requests/next/__init__.py @@ -38,6 +38,9 @@ from gvm.protocols.gmp.requests.next._report_tls_certificates import ( ReportTlsCertificates, ) +from gvm.protocols.gmp.requests.next._report_vulnerabilities import ( + ReportVulnerabilities, +) from gvm.protocols.gmp.requests.next._tasks import Tasks from .._entity_id import EntityID @@ -168,6 +171,7 @@ "ReportOperatingSystems", "ReportPorts", "ReportTlsCertificates", + "ReportVulnerabilities", "Reports", "ResourceNames", "ResourceType", diff --git a/gvm/protocols/gmp/requests/next/_report_vulnerabilities.py b/gvm/protocols/gmp/requests/next/_report_vulnerabilities.py new file mode 100644 index 00000000..a5a9b18a --- /dev/null +++ b/gvm/protocols/gmp/requests/next/_report_vulnerabilities.py @@ -0,0 +1,47 @@ +from gvm.errors import RequiredArgument +from gvm.protocols.core import Request +from gvm.protocols.gmp.requests import EntityID +from gvm.utils import to_bool +from gvm.xml import XmlCommand + + +class ReportVulnerabilities: + @classmethod + def get_report_vulnerabilities( + cls, + report_id: EntityID, + *, + filter_string: str | None = None, + filter_id: str | None = None, + ignore_pagination: bool | None = None, + details: bool | None = True, + ) -> Request: + """Request vulnerabilities of a single report. + + Args: + report_id: UUID of an existing report. + filter_string: Filter term to use to filter results in the report + filter_id: UUID of filter to use to filter results in the report + ignore_pagination: Whether to ignore the filter terms "first" and + "rows". + details: Request additional report vulnerability information details. + Defaults to True. + """ + cmd = XmlCommand("get_report_vulns") + + if not report_id: + raise RequiredArgument( + function=cls.get_report_vulnerabilities.__name__, + argument="report_id", + ) + + cmd.set_attribute("report_id", str(report_id)) + + cmd.add_filter(filter_string, filter_id) + + if ignore_pagination is not None: + cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination)) + + cmd.set_attribute("details", to_bool(details)) + + return cmd diff --git a/tests/protocols/gmpnext/entities/report_vulnerabilities/test_get_report_vulnerabilities.py b/tests/protocols/gmpnext/entities/report_vulnerabilities/test_get_report_vulnerabilities.py new file mode 100644 index 00000000..a823ce61 --- /dev/null +++ b/tests/protocols/gmpnext/entities/report_vulnerabilities/test_get_report_vulnerabilities.py @@ -0,0 +1,61 @@ +# SPDX-FileCopyrightText: 2026 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import RequiredArgument + + +class GmpGetReportVulnerabilitiesTestMixin: + def test_get_report_vulns_without_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_report_vulnerabilities(None) + + with self.assertRaises(RequiredArgument): + self.gmp.get_report_vulnerabilities("") + + def test_get_report_vulns_with_filter_string(self): + self.gmp.get_report_vulnerabilities( + report_id="r1", filter_string="name=foo" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_report_vulns_with_filter_id(self): + self.gmp.get_report_vulnerabilities(report_id="r1", filter_id="f1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_report_vulns_with_ignore_pagination(self): + self.gmp.get_report_vulnerabilities( + report_id="r1", ignore_pagination=True + ) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_report_vulnerabilities( + report_id="r1", ignore_pagination=False + ) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_report_vulns_with_details(self): + self.gmp.get_report_vulnerabilities(report_id="r1", details=True) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_report_vulnerabilities(report_id="r1", details=False) + + self.connection.send.has_been_called_with( + b'' + ) diff --git a/tests/protocols/gmpnext/entities/test_report_vulnerabilities.py b/tests/protocols/gmpnext/entities/test_report_vulnerabilities.py new file mode 100644 index 00000000..19f99928 --- /dev/null +++ b/tests/protocols/gmpnext/entities/test_report_vulnerabilities.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2026 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from ...gmpnext import GMPTestCase +from .report_vulnerabilities.test_get_report_vulnerabilities import ( + GmpGetReportVulnerabilitiesTestMixin, +) + + +class GmpGetReportVulnerabilitiesTestCase( + GmpGetReportVulnerabilitiesTestMixin, GMPTestCase +): + pass diff --git a/uv.lock b/uv.lock index c8c2ee9e..969592a7 100644 --- a/uv.lock +++ b/uv.lock @@ -1267,7 +1267,7 @@ wheels = [ [[package]] name = "python-gvm" -version = "27.0.3.dev1" +version = "27.1.1.dev1" source = { editable = "." } dependencies = [ { name = "httpx", extra = ["http2"] },