Skip to content

Commit

Permalink
Change: fix ruff warnings in tests/
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasHargarter committed Aug 5, 2024
1 parent 6061a1a commit 1f3435d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))) {
Expand Down
5 changes: 3 additions & 2 deletions tests/standalone_plugins/test_changed_oid.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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


Expand Down
24 changes: 12 additions & 12 deletions tests/standalone_plugins/test_deprecate_vts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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
)


Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/standalone_plugins/test_version_updated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1f3435d

Please sign in to comment.