From 1f3435d6715ebb8a4e37a031ec105fcd11417eb9 Mon Sep 17 00:00:00 2001 From: Niklas Hargarter Date: Mon, 5 Aug 2024 15:59:37 +0200 Subject: [PATCH] Change: fix ruff warnings in tests/ --- .../changed_packages/test_changed_packages.py | 1 + tests/standalone_plugins/test_changed_oid.py | 5 ++-- .../standalone_plugins/test_deprecate_vts.py | 24 +++++++++---------- .../test_version_updated.py | 2 +- tests/test_results.py | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/standalone_plugins/changed_packages/test_changed_packages.py b/tests/standalone_plugins/changed_packages/test_changed_packages.py index 1877d314..0434d381 100644 --- a/tests/standalone_plugins/changed_packages/test_changed_packages.py +++ b/tests/standalone_plugins/changed_packages/test_changed_packages.py @@ -30,6 +30,7 @@ class ChangedPackagesTestCase(TestCase): def test_get_package(self): + # ruff: noqa: E501 content = """ ...some NASL... if(!isnull(res = isdpkgvuln(pkg:"libwpewebkit-1.0-3", ver:"2.38.3-1~deb11u1", rls:"DEB11"))) { diff --git a/tests/standalone_plugins/test_changed_oid.py b/tests/standalone_plugins/test_changed_oid.py index 11534cfc..994644c8 100644 --- a/tests/standalone_plugins/test_changed_oid.py +++ b/tests/standalone_plugins/test_changed_oid.py @@ -16,12 +16,13 @@ # along with this program. If not, see . import os -import unittest import tempfile +import unittest from contextlib import contextmanager from pathlib import Path -from typing import Generator from subprocess import SubprocessError +from typing import Generator + from troubadix.standalone_plugins.changed_oid import check_oid, git, parse_args diff --git a/tests/standalone_plugins/test_deprecate_vts.py b/tests/standalone_plugins/test_deprecate_vts.py index 1e5715c7..c01a79ec 100644 --- a/tests/standalone_plugins/test_deprecate_vts.py +++ b/tests/standalone_plugins/test_deprecate_vts.py @@ -4,17 +4,17 @@ # pylint: disable=protected-access import unittest from pathlib import Path -from tests.plugins import TemporaryDirectory +from tests.plugins import TemporaryDirectory from troubadix.standalone_plugins.deprecate_vts import ( - deprecate, - parse_args, DeprecatedFile, - _get_summary, _finalize_content, - update_summary, - get_files_from_path, + _get_summary, + deprecate, filter_files, + get_files_from_path, + parse_args, + update_summary, ) @@ -92,19 +92,19 @@ def test_mandatory_arg_group_neither(self): '...if(description)\n{\n script_oid("1.3.6.1.4.1.25623.1.0.910673");' '\n script_version("2024-03-12T14:15:13+0000");' '\n script_name("RedHat: Security Advisory for gd (RHSA-2020:5443-01)");' - '\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");' + '\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");' # noqa: E501 '\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");' '\n\n script_xref(name:"RHSA", value:"2020:5443-01");\n script_xref(name:"URL", value:"https://www.redhat.com/archives/rhsa-announce/2020-December/msg00044.html");' - '\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");' - '\n\n exit(0);\n}\n\ninclude("revisions-lib.inc");\ninclude("pkg-lib-rpm.inc");\n\nrelease = rpm_get_ssh_release();\nif(!release)\n exit(0);\n\nres = "";\nreport = "";\n\nif(release == "RHENT_7") {\n\n if(!isnull(res = isrpmvuln(pkg:"gd", rpm:"gd~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(!isnull(res = isrpmvuln(pkg:"gd-debuginfo", rpm:"gd-debuginfo~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(report != "") {\n security_message(data:report);\n } else if(__pkg_match) {\n exit(99);\n }\n exit(0);\n}\n\nexit(0);' + '\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");' # noqa: E501 + '\n\n exit(0);\n}\n\ninclude("revisions-lib.inc");\ninclude("pkg-lib-rpm.inc");\n\nrelease = rpm_get_ssh_release();\nif(!release)\n exit(0);\n\nres = "";\nreport = "";\n\nif(release == "RHENT_7") {\n\n if(!isnull(res = isrpmvuln(pkg:"gd", rpm:"gd~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(!isnull(res = isrpmvuln(pkg:"gd-debuginfo", rpm:"gd-debuginfo~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(report != "") {\n security_message(data:report);\n } else if(__pkg_match) {\n exit(99);\n }\n exit(0);\n}\n\nexit(0);' # noqa: E501 ) NASL_CONTENT_KB = ( '...if(description)\n{\n script_oid("1.3.6.1.4.1.25623.1.0.910673");' '\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");' '\n\n set_kb_item(name:"shttp/" + port + "/detected", value:TRUE);"' - '\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");' - '\n\n exit(0);\n}\n\ninclude("revisions-lib.inc");\ninclude("pkg-lib-rpm.inc");\n\nrelease = rpm_get_ssh_release();\nif(!release)\n exit(0);\n\nres = "";\nreport = "";\n\nif(release == "RHENT_7") {\n\n if(!isnull(res = isrpmvuln(pkg:"gd", rpm:"gd~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(!isnull(res = isrpmvuln(pkg:"gd-debuginfo", rpm:"gd-debuginfo~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(report != "") {\n security_message(data:report);\n } else if(__pkg_match) {\n exit(99);\n }\n exit(0);\n}\n\nexit(0);' + '\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");' # noqa: E501 + '\n\n exit(0);\n}\n\ninclude("revisions-lib.inc");\ninclude("pkg-lib-rpm.inc");\n\nrelease = rpm_get_ssh_release();\nif(!release)\n exit(0);\n\nres = "";\nreport = "";\n\nif(release == "RHENT_7") {\n\n if(!isnull(res = isrpmvuln(pkg:"gd", rpm:"gd~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(!isnull(res = isrpmvuln(pkg:"gd-debuginfo", rpm:"gd-debuginfo~2.0.35~27.el7_9", rls:"RHENT_7"))) {\n report += res;\n }\n\n if(report != "") {\n security_message(data:report);\n } else if(__pkg_match) {\n exit(99);\n }\n exit(0);\n}\n\nexit(0);' # noqa: E501 ) @@ -167,7 +167,7 @@ def test_finalize_content(self): result = _finalize_content(NASL_CONTENT) expected = ( '...if(description)\n{\n script_oid("1.3.6.1.4.1.25623.1.0.910673");\n ' - 'script_version("2024-03-12T14:15:13+0000");\n script_name("RedHat: Security Advisory for gd (RHSA-2020:5443-01)");\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");\n\n script_xref(name:"RHSA", value:"2020:5443-01");\n script_xref(name:"URL", value:"https://www.redhat.com/archives/rhsa-announce/2020-December/msg00044.html");\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");\n\n script_tag(name:"deprecated", value:TRUE);\n\nexit(0);\n}\n\nexit(66);\n' + 'script_version("2024-03-12T14:15:13+0000");\n script_name("RedHat: Security Advisory for gd (RHSA-2020:5443-01)");\n script_family("Red Hat Local Security Checks");\n script_dependencies("gather-package-list.nasl");\n script_mandatory_keys("ssh/login/rhel", "ssh/login/rpms", re:"ssh/login/release=RHENT_7");\n\n script_xref(name:"RHSA", value:"2020:5443-01");\n script_xref(name:"URL", value:"https://www.redhat.com/archives/rhsa-announce/2020-December/msg00044.html");\n\n script_tag(name:"summary", value:"The remote host is missing an update for the \'gd\'\n package(s) announced via the RHSA-2020:5443-01 advisory.");\n\n script_tag(name:"deprecated", value:TRUE);\n\nexit(0);\n}\n\nexit(66);\n' # noqa: E501 ) self.assertEqual(result, expected) diff --git a/tests/standalone_plugins/test_version_updated.py b/tests/standalone_plugins/test_version_updated.py index 7c28aa00..32da3552 100644 --- a/tests/standalone_plugins/test_version_updated.py +++ b/tests/standalone_plugins/test_version_updated.py @@ -27,9 +27,9 @@ from troubadix.standalone_plugins.version_updated import ( check_version_updated, git, + parse_args, ) from troubadix.standalone_plugins.version_updated import main as plugin_main -from troubadix.standalone_plugins.version_updated import parse_args @contextmanager diff --git a/tests/test_results.py b/tests/test_results.py index b0082d4d..1a902e92 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -19,8 +19,8 @@ import unittest from pathlib import Path +from troubadix.plugin import LinterError, LinterWarning from troubadix.results import FileResults -from troubadix.plugin import LinterWarning, LinterError class TestResults(unittest.TestCase):