diff --git a/gvm/protocols/gmp/_gmpnext.py b/gvm/protocols/gmp/_gmpnext.py index 41261ed3..a77d649d 100644 --- a/gvm/protocols/gmp/_gmpnext.py +++ b/gvm/protocols/gmp/_gmpnext.py @@ -1092,6 +1092,36 @@ def get_report_hosts( ) ) + def get_audit_report_hosts( + 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 hosts of a single audit 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 host information details. + Defaults to True. + """ + return self._send_request_and_transform_response( + ReportHosts.get_audit_report_hosts( + report_id=report_id, + filter_string=filter_string, + filter_id=filter_id, + ignore_pagination=ignore_pagination, + details=details, + ) + ) + def get_report_operating_systems( self, report_id: EntityID, diff --git a/gvm/protocols/gmp/requests/next/_report_hosts.py b/gvm/protocols/gmp/requests/next/_report_hosts.py index cb2f0424..7237163f 100644 --- a/gvm/protocols/gmp/requests/next/_report_hosts.py +++ b/gvm/protocols/gmp/requests/next/_report_hosts.py @@ -44,3 +44,42 @@ def get_report_hosts( cmd.set_attribute("details", to_bool(details)) return cmd + + @classmethod + def get_audit_report_hosts( + 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 hosts of a single audit 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 host information details. + Defaults to True. + """ + cmd = XmlCommand("get_audit_report_hosts") + + if not report_id: + raise RequiredArgument( + function=cls.get_report_hosts.__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_hosts/test_get_audit_report_hosts.py b/tests/protocols/gmpnext/entities/report_hosts/test_get_audit_report_hosts.py new file mode 100644 index 00000000..ffaaa4d9 --- /dev/null +++ b/tests/protocols/gmpnext/entities/report_hosts/test_get_audit_report_hosts.py @@ -0,0 +1,57 @@ +# SPDX-FileCopyrightText: 2026 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gvm.errors import RequiredArgument + + +class GmpGetAuditReportHostsTestMixin: + def test_get_audit_report_hosts_without_id(self): + with self.assertRaises(RequiredArgument): + self.gmp.get_audit_report_hosts(None) + + with self.assertRaises(RequiredArgument): + self.gmp.get_audit_report_hosts("") + + def test_get_audit_report_hosts_with_filter_string(self): + self.gmp.get_audit_report_hosts( + report_id="r1", filter_string="name=foo" + ) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_report_hosts_with_filter_id(self): + self.gmp.get_audit_report_hosts(report_id="r1", filter_id="f1") + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_report_hosts_with_ignore_pagination(self): + self.gmp.get_audit_report_hosts(report_id="r1", ignore_pagination=True) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_audit_report_hosts(report_id="r1", ignore_pagination=False) + + self.connection.send.has_been_called_with( + b'' + ) + + def test_get_audit_report_hosts_with_details(self): + self.gmp.get_audit_report_hosts(report_id="r1", details=True) + + self.connection.send.has_been_called_with( + b'' + ) + + self.gmp.get_audit_report_hosts(report_id="r1", details=False) + + self.connection.send.has_been_called_with( + b'' + ) diff --git a/tests/protocols/gmpnext/entities/test_report_hosts.py b/tests/protocols/gmpnext/entities/test_report_hosts.py index d82f40e6..5d5993ee 100644 --- a/tests/protocols/gmpnext/entities/test_report_hosts.py +++ b/tests/protocols/gmpnext/entities/test_report_hosts.py @@ -4,6 +4,9 @@ # from ...gmpnext import GMPTestCase +from .report_hosts.test_get_audit_report_hosts import ( + GmpGetAuditReportHostsTestMixin, +) from .report_hosts.test_get_report_hosts import ( GmpGetReportHostsTestMixin, ) @@ -11,3 +14,9 @@ class GmpGetReportHostsTestCase(GmpGetReportHostsTestMixin, GMPTestCase): pass + + +class GmpGetAuditReportHostsTestCase( + GmpGetAuditReportHostsTestMixin, GMPTestCase +): + pass