From 1f8212e1deab6307b1ac4163d4fa52d37db00767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Thu, 12 Nov 2020 18:20:51 +0100 Subject: [PATCH 1/7] Adding an info message if get_report gets called without details --- gvm/protocols/gmpv7/gmpv7.py | 6 +++++ .../gmpv7/testcmds/test_get_report.py | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gvm/protocols/gmpv7/gmpv7.py b/gvm/protocols/gmpv7/gmpv7.py index fa165608c..5dd353b68 100644 --- a/gvm/protocols/gmpv7/gmpv7.py +++ b/gvm/protocols/gmpv7/gmpv7.py @@ -3774,6 +3774,12 @@ def get_report( if ignore_pagination is not None: cmd.set_attribute("ignore_pagination", _to_bool(ignore_pagination)) + if not details: + logger.info( + msg='Your report will be without report details.' + 'If you want a report with details, please' + 'pass the details=True to the function call.' + ) if details is not None: cmd.set_attribute("details", _to_bool(details)) diff --git a/tests/protocols/gmpv7/testcmds/test_get_report.py b/tests/protocols/gmpv7/testcmds/test_get_report.py index dc99e2861..1db8fa616 100644 --- a/tests/protocols/gmpv7/testcmds/test_get_report.py +++ b/tests/protocols/gmpv7/testcmds/test_get_report.py @@ -18,6 +18,8 @@ import unittest +from unittest.mock import patch + from gvm.errors import RequiredArgument from gvm.protocols.gmpv7 import ( ReportFormatType, @@ -99,6 +101,26 @@ def test_get_report_with_details(self): '' ) + @patch('gvm.protocols.gmpv7.gmpv7.logger') + def test_get_report_without_details(self, logger_mock): + self.gmp.get_report(report_id='r1') + + logger_mock.info.assert_called_with( + msg='Your report will be without report details.' + 'If you want a report with details, please' + 'pass the details=True to the function call.' + ) + + self.connection.send.has_been_called_with( + '' + ) + + self.gmp.get_report(report_id='r1', details=False) + + self.connection.send.has_been_called_with( + '' + ) + if __name__ == '__main__': unittest.main() From c85b8b14a4928d0e2eb94f8bc5f581501c595f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Thu, 12 Nov 2020 18:26:17 +0100 Subject: [PATCH 2/7] Also informed if false --- tests/protocols/gmpv7/testcmds/test_get_report.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/protocols/gmpv7/testcmds/test_get_report.py b/tests/protocols/gmpv7/testcmds/test_get_report.py index 1db8fa616..1e06b4d65 100644 --- a/tests/protocols/gmpv7/testcmds/test_get_report.py +++ b/tests/protocols/gmpv7/testcmds/test_get_report.py @@ -115,12 +115,20 @@ def test_get_report_without_details(self, logger_mock): '' ) + logger_mock.reset_mock() + self.gmp.get_report(report_id='r1', details=False) self.connection.send.has_been_called_with( '' ) + logger_mock.info.assert_called_with( + msg='Your report will be without report details.' + 'If you want a report with details, please' + 'pass the details=True to the function call.' + ) + if __name__ == '__main__': unittest.main() From da37e93c47a30d9b399431ec49efd89a131fbe04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Thu, 12 Nov 2020 18:28:15 +0100 Subject: [PATCH 3/7] Changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f21f8b69..a5c889855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added the `get_x_from_string()` functions to `latest` [#308](https://github.com/greenbone/python-gvm/pull/308) * Added the `ReportFormatType` that can be used instead of a report_format_id [#311](https://github.com/greenbone/python-gvm/pull/311) * Added tests for constructor of SSHConnection, TLSConnection, UnixSocketConnection and GvmConnection [#321](https://github.com/greenbone/python-gvm/pull/321) +* Added information message to `get_report()` if called without `details`. [#333](https://github.com/greenbone/python-gvm/pull/333) ### Fixed * Corrected `seconds_active` parameter to `days_active` for notes and overrides. [#307](https://github.com/greenbone/python-gvm/pull/307) From e7e6e69856d3a2b22774eeca487fde493cac76c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Thu, 12 Nov 2020 18:41:30 +0100 Subject: [PATCH 4/7] get_report() details defaults to True now. --- gvm/protocols/gmpv7/gmpv7.py | 11 ++--- .../gmpv7/testcmds/test_get_report.py | 44 +++---------------- 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/gvm/protocols/gmpv7/gmpv7.py b/gvm/protocols/gmpv7/gmpv7.py index 5dd353b68..d6d3cf910 100644 --- a/gvm/protocols/gmpv7/gmpv7.py +++ b/gvm/protocols/gmpv7/gmpv7.py @@ -3747,6 +3747,7 @@ def get_report( ignore_pagination: Whether to ignore the filter terms "first" and "rows". details: Request additional report information details + defaults to True Returns: The response. See :py:meth:`send_command` for details. @@ -3774,14 +3775,10 @@ def get_report( if ignore_pagination is not None: cmd.set_attribute("ignore_pagination", _to_bool(ignore_pagination)) - if not details: - logger.info( - msg='Your report will be without report details.' - 'If you want a report with details, please' - 'pass the details=True to the function call.' - ) - if details is not None: + if details is False: cmd.set_attribute("details", _to_bool(details)) + else: + cmd.set_attribute("details", _to_bool(True)) return self._send_xml_command(cmd) diff --git a/tests/protocols/gmpv7/testcmds/test_get_report.py b/tests/protocols/gmpv7/testcmds/test_get_report.py index 1e06b4d65..c76236b8a 100644 --- a/tests/protocols/gmpv7/testcmds/test_get_report.py +++ b/tests/protocols/gmpv7/testcmds/test_get_report.py @@ -18,8 +18,6 @@ import unittest -from unittest.mock import patch - from gvm.errors import RequiredArgument from gvm.protocols.gmpv7 import ( ReportFormatType, @@ -39,21 +37,21 @@ def test_get_report_with_filter(self): self.gmp.get_report(report_id='r1', filter='name=foo') self.connection.send.has_been_called_with( - '' + '' ) def test_get_report_with_filter_id(self): self.gmp.get_report(report_id='r1', filter_id='f1') self.connection.send.has_been_called_with( - '' + '' ) def test_get_report_with_report_format_id(self): self.gmp.get_report(report_id='r1', report_format_id='bar') self.connection.send.has_been_called_with( - '' + '' ) def test_get_report_with_report_format_type(self): @@ -63,7 +61,7 @@ def test_get_report_with_report_format_type(self): report_format_id = get_report_format_id_from_string('txt').value self.connection.send.has_been_called_with( - ''.format( + ''.format( report_format_id ) ) @@ -72,20 +70,20 @@ def test_get_report_with_delta_report_id(self): self.gmp.get_report(report_id='r1', delta_report_id='r2') self.connection.send.has_been_called_with( - '' + '' ) def test_get_report_with_ignore_pagination(self): self.gmp.get_report(report_id='r1', ignore_pagination=True) self.connection.send.has_been_called_with( - '' + '' ) self.gmp.get_report(report_id='r1', ignore_pagination=False) self.connection.send.has_been_called_with( - '' + '' ) def test_get_report_with_details(self): @@ -101,34 +99,6 @@ def test_get_report_with_details(self): '' ) - @patch('gvm.protocols.gmpv7.gmpv7.logger') - def test_get_report_without_details(self, logger_mock): - self.gmp.get_report(report_id='r1') - - logger_mock.info.assert_called_with( - msg='Your report will be without report details.' - 'If you want a report with details, please' - 'pass the details=True to the function call.' - ) - - self.connection.send.has_been_called_with( - '' - ) - - logger_mock.reset_mock() - - self.gmp.get_report(report_id='r1', details=False) - - self.connection.send.has_been_called_with( - '' - ) - - logger_mock.info.assert_called_with( - msg='Your report will be without report details.' - 'If you want a report with details, please' - 'pass the details=True to the function call.' - ) - if __name__ == '__main__': unittest.main() From 1bfe32cd58a096a2a49773459caa28c46bf48c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Thu, 12 Nov 2020 18:41:52 +0100 Subject: [PATCH 5/7] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c889855..ed713b981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Moved tests for `SeverityLevel` Enum and `get_severity_level_from_string()` [#327](https://github.com/greenbone/python-gvm/pull/327) ### Changed +* In `get_report()` the `details` parameter is `True` on default now. [#333](https://github.com/greenbone/python-gvm/pull/333) + ### Deprecated ### Removed ### Fixed @@ -23,7 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added the `get_x_from_string()` functions to `latest` [#308](https://github.com/greenbone/python-gvm/pull/308) * Added the `ReportFormatType` that can be used instead of a report_format_id [#311](https://github.com/greenbone/python-gvm/pull/311) * Added tests for constructor of SSHConnection, TLSConnection, UnixSocketConnection and GvmConnection [#321](https://github.com/greenbone/python-gvm/pull/321) -* Added information message to `get_report()` if called without `details`. [#333](https://github.com/greenbone/python-gvm/pull/333) ### Fixed * Corrected `seconds_active` parameter to `days_active` for notes and overrides. [#307](https://github.com/greenbone/python-gvm/pull/307) From c1c7eae6852e646ff864abbf5476c343d48154ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Thu, 12 Nov 2020 18:44:34 +0100 Subject: [PATCH 6/7] Copyright --- gvm/protocols/gmpv7/gmpv7.py | 2 +- tests/protocols/gmpv7/testcmds/test_get_report.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gvm/protocols/gmpv7/gmpv7.py b/gvm/protocols/gmpv7/gmpv7.py index d6d3cf910..0335d9583 100644 --- a/gvm/protocols/gmpv7/gmpv7.py +++ b/gvm/protocols/gmpv7/gmpv7.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2018 - 2019 Greenbone Networks GmbH +# Copyright (C) 2018 - 2020 Greenbone Networks GmbH # # SPDX-License-Identifier: GPL-3.0-or-later # diff --git a/tests/protocols/gmpv7/testcmds/test_get_report.py b/tests/protocols/gmpv7/testcmds/test_get_report.py index c76236b8a..2ac640804 100644 --- a/tests/protocols/gmpv7/testcmds/test_get_report.py +++ b/tests/protocols/gmpv7/testcmds/test_get_report.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2018 Greenbone Networks GmbH +# Copyright (C) 2018-2020 Greenbone Networks GmbH # # SPDX-License-Identifier: GPL-3.0-or-later # From bf57aaada83e3201fa1868f37f74ae3d08c415bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaspar=20L=C3=B6chte?= Date: Fri, 13 Nov 2020 07:58:09 +0100 Subject: [PATCH 7/7] Details=True --- gvm/protocols/gmpv7/gmpv7.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gvm/protocols/gmpv7/gmpv7.py b/gvm/protocols/gmpv7/gmpv7.py index 0335d9583..afc7345ef 100644 --- a/gvm/protocols/gmpv7/gmpv7.py +++ b/gvm/protocols/gmpv7/gmpv7.py @@ -3733,7 +3733,7 @@ def get_report( delta_report_id: Optional[str] = None, report_format_id: Optional[Union[str, ReportFormatType]] = None, ignore_pagination: Optional[bool] = None, - details: Optional[bool] = None + details: Optional[bool] = True ) -> Any: """Request a single report @@ -3775,10 +3775,7 @@ def get_report( if ignore_pagination is not None: cmd.set_attribute("ignore_pagination", _to_bool(ignore_pagination)) - if details is False: - cmd.set_attribute("details", _to_bool(details)) - else: - cmd.set_attribute("details", _to_bool(True)) + cmd.set_attribute("details", _to_bool(details)) return self._send_xml_command(cmd)