From cc0e3341a1192dd26f8355be8a3c093b1a69faf3 Mon Sep 17 00:00:00 2001 From: Nicolas Thumann Date: Tue, 16 Dec 2025 16:33:36 +0100 Subject: [PATCH 1/2] Change: Sync line-length of black with ruff --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fdad7640..0f832a3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ ruff = ">=0.5.6,<0.15.0" autohooks-plugin-ruff = ">=24.1,<26.0" [tool.black] -line-length = 80 +line-length = 100 target-version = ['py310', 'py311', 'py312'] exclude = ''' /( From 312dbdf88f7239b3868076dff12a835fe3270616 Mon Sep 17 00:00:00 2001 From: Nicolas Thumann Date: Tue, 16 Dec 2025 16:34:01 +0100 Subject: [PATCH 2/2] Change: Run black --- tests/helper/test_if_block_parser.py | 20 +- .../test_linguistic_exception_handler.py | 24 +-- tests/helper/test_patterns.py | 8 +- tests/helper/test_remove_comments.py | 20 +- tests/helper/test_text_utils.py | 4 +- tests/plugins/test_badwords.py | 8 +- tests/plugins/test_copyright_text.py | 19 +- tests/plugins/test_copyright_year.py | 47 ++--- tests/plugins/test_creation_date.py | 20 +- tests/plugins/test_cve_format.py | 44 ++--- tests/plugins/test_cvss_format.py | 29 +-- tests/plugins/test_dependencies.py | 6 +- .../plugins/test_dependency_category_order.py | 15 +- tests/plugins/test_deprecated_dependency.py | 19 +- tests/plugins/test_deprecated_functions.py | 19 +- tests/plugins/test_double_end_points.py | 12 +- tests/plugins/test_duplicate_oid.py | 19 +- tests/plugins/test_duplicated_script_tags.py | 30 +-- tests/plugins/test_encoding.py | 4 +- tests/plugins/test_forking_nasl_functions.py | 12 +- tests/plugins/test_get_kb_on_services.py | 8 +- tests/plugins/test_grammar.py | 72 ++----- tests/plugins/test_http_links_in_tags.py | 12 +- tests/plugins/test_if_statement_syntax.py | 32 +--- tests/plugins/test_illegal_characters.py | 12 +- tests/plugins/test_log_messages.py | 20 +- tests/plugins/test_misplaced_compare_in_if.py | 100 +++------- tests/plugins/test_missing_desc_exit.py | 12 +- tests/plugins/test_missing_tag_solution.py | 12 +- tests/plugins/test_newlines.py | 40 +--- .../test_overlong_description_lines.py | 20 +- tests/plugins/test_overlong_script_tags.py | 24 +-- .../plugins/test_prod_svc_detect_in_vulnvt.py | 12 +- tests/plugins/test_reporting_consistency.py | 20 +- .../plugins/test_script_add_preference_id.py | 12 +- .../test_script_add_preference_type.py | 20 +- .../plugins/test_script_calls_empty_values.py | 8 +- .../plugins/test_script_calls_recommended.py | 12 +- tests/plugins/test_script_category.py | 12 +- tests/plugins/test_script_copyright.py | 29 +-- tests/plugins/test_script_family.py | 24 +-- tests/plugins/test_script_tag_form.py | 16 +- tests/plugins/test_script_tag_whitespaces.py | 60 ++---- tests/plugins/test_script_tags_mandatory.py | 16 +- ...ript_version_and_last_modification_tags.py | 54 ++---- tests/plugins/test_script_xref_form.py | 24 +-- tests/plugins/test_script_xref_url.py | 43 ++--- tests/plugins/test_security_messages.py | 33 +--- tests/plugins/test_set_get_kb_calls.py | 8 +- tests/plugins/test_severity_date.py | 16 +- tests/plugins/test_severity_format.py | 32 +--- tests/plugins/test_severity_origin.py | 24 +-- tests/plugins/test_solution_text.py | 28 +-- tests/plugins/test_solution_type.py | 16 +- tests/plugins/test_spaces_before_dots.py | 12 +- tests/plugins/test_tabs.py | 8 +- tests/plugins/test_todo_tbd.py | 24 +-- tests/plugins/test_trailing_spaces_tabs.py | 8 +- tests/plugins/test_using_display.py | 29 +-- tests/plugins/test_valid_oid.py | 181 +++++------------- tests/plugins/test_valid_script_tag_names.py | 16 +- .../test_variable_redefinition_in_foreach.py | 8 +- tests/plugins/test_vt_file_permissions.py | 8 +- tests/plugins/test_vt_placement.py | 3 +- .../markers/test_added_udeb.py | 4 +- .../changed_packages/test_changed_packages.py | 12 +- .../test_changed_creation_date.py | 60 ++---- tests/standalone_plugins/test_changed_oid.py | 8 +- .../standalone_plugins/test_deprecate_vts.py | 3 +- .../test_file_extensions.py | 4 +- .../test_version_updated.py | 24 +-- tests/test_argparser.py | 8 +- tests/test_helper.py | 16 +- tests/test_reporter.py | 8 +- tests/test_results.py | 28 +-- tests/test_runner.py | 145 +++----------- troubadix/argparser.py | 18 +- troubadix/helper/date_format.py | 10 +- troubadix/helper/helper.py | 4 +- troubadix/helper/if_block_parser.py | 51 ++--- .../helper/linguistic_exception_handler.py | 24 +-- troubadix/helper/patterns.py | 26 +-- troubadix/helper/remove_comments.py | 5 +- troubadix/helper/text_utils.py | 4 +- troubadix/plugin.py | 12 +- troubadix/plugins/__init__.py | 26 +-- troubadix/plugins/badwords.py | 12 +- troubadix/plugins/copyright_text.py | 7 +- troubadix/plugins/copyright_year.py | 16 +- troubadix/plugins/creation_date.py | 12 +- troubadix/plugins/cvss_format.py | 4 +- troubadix/plugins/dependencies.py | 7 +- .../plugins/dependency_category_order.py | 27 +-- troubadix/plugins/deprecated_dependency.py | 22 +-- troubadix/plugins/deprecated_functions.py | 3 +- troubadix/plugins/double_end_points.py | 9 +- troubadix/plugins/duplicate_oid.py | 4 +- troubadix/plugins/forking_nasl_functions.py | 5 +- troubadix/plugins/get_kb_on_services.py | 6 +- troubadix/plugins/grammar.py | 22 +-- troubadix/plugins/http_links_in_tags.py | 4 +- troubadix/plugins/illegal_characters.py | 18 +- troubadix/plugins/log_messages.py | 3 +- troubadix/plugins/malformed_dependencies.py | 8 +- troubadix/plugins/missing_desc_exit.py | 4 +- troubadix/plugins/multiple_re_parameters.py | 8 +- troubadix/plugins/newlines.py | 3 +- .../plugins/overlong_description_lines.py | 8 +- .../plugins/prod_svc_detect_in_vulnvt.py | 5 +- troubadix/plugins/script_add_preference_id.py | 13 +- .../plugins/script_add_preference_type.py | 9 +- .../plugins/script_calls_empty_values.py | 6 +- troubadix/plugins/script_calls_recommended.py | 13 +- troubadix/plugins/script_copyright.py | 4 +- troubadix/plugins/script_family.py | 3 +- troubadix/plugins/script_tag_form.py | 4 +- troubadix/plugins/script_tag_whitespaces.py | 12 +- troubadix/plugins/script_tags_mandatory.py | 7 +- ...ript_version_and_last_modification_tags.py | 23 +-- troubadix/plugins/script_xref_form.py | 4 +- troubadix/plugins/script_xref_url.py | 10 +- troubadix/plugins/security_messages.py | 23 +-- troubadix/plugins/severity_date.py | 12 +- troubadix/plugins/severity_format.py | 4 +- troubadix/plugins/severity_origin.py | 4 +- troubadix/plugins/solution_text.py | 16 +- troubadix/plugins/solution_type.py | 3 +- troubadix/plugins/spaces_before_dots.py | 10 +- troubadix/plugins/spaces_in_filename.py | 3 +- troubadix/plugins/spelling.py | 19 +- troubadix/plugins/trailing_spaces_tabs.py | 7 +- troubadix/plugins/using_display.py | 8 +- troubadix/plugins/valid_oid.py | 85 +++----- troubadix/plugins/valid_script_tag_names.py | 7 +- troubadix/plugins/variable_assigned_in_if.py | 9 +- .../variable_redefinition_in_foreach.py | 8 +- troubadix/plugins/vt_placement.py | 10 +- troubadix/reporter.py | 25 +-- troubadix/results.py | 10 +- troubadix/runner.py | 19 +- .../standalone_plugins/allowed_rev_diff.py | 33 +--- .../changed_creation_date.py | 12 +- troubadix/standalone_plugins/changed_cves.py | 16 +- troubadix/standalone_plugins/changed_oid.py | 8 +- .../changed_packages/changed_packages.py | 11 +- .../changed_packages/marker/changed_update.py | 4 +- .../marker/dropped_architecture.py | 4 +- .../changed_packages/package.py | 7 +- .../dependency_graph/checks.py | 20 +- .../dependency_graph/dependency_graph.py | 18 +- troubadix/standalone_plugins/deprecate_vts.py | 12 +- .../standalone_plugins/file_extensions.py | 13 +- .../standalone_plugins/last_modification.py | 12 +- troubadix/standalone_plugins/no_solution.py | 44 ++--- .../standalone_plugins/version_updated.py | 16 +- troubadix/troubadix.py | 5 +- 156 files changed, 731 insertions(+), 2170 deletions(-) diff --git a/tests/helper/test_if_block_parser.py b/tests/helper/test_if_block_parser.py index 115c0c23..2f2e0e18 100644 --- a/tests/helper/test_if_block_parser.py +++ b/tests/helper/test_if_block_parser.py @@ -107,20 +107,14 @@ def test_nested_if_statements(self): self.assertIn('display("nested block")', result.statements[1].outcome) self.assertEqual("inner2", result.statements[2].condition) - self.assertEqual( - 'display("nested inline")', result.statements[2].outcome - ) + self.assertEqual('display("nested inline")', result.statements[2].outcome) def test_complex_condition(self): - content = ( - 'if (a == 1 && b > 2 || c != "string") { display("complex"); }' - ) + content = 'if (a == 1 && b > 2 || c != "string") { display("complex"); }' result = find_if_statements(content) self.assertEqual(1, len(result.statements)) - self.assertEqual( - 'a == 1 && b > 2 || c != "string"', result.statements[0].condition - ) + self.assertEqual('a == 1 && b > 2 || c != "string"', result.statements[0].condition) self.assertEqual('display("complex");', result.statements[0].outcome) def test_if_with_problematic_stuff(self): @@ -151,9 +145,7 @@ def test_useless_semicolon(self): result = find_if_statements(content) self.assertEqual(len(result.statements), 0) self.assertEqual(len(result.errors), 1) - self.assertEqual( - result.errors[0].error_type.name, "TERMINATED_AFTER_CONDITION" - ) + self.assertEqual(result.errors[0].error_type.name, "TERMINATED_AFTER_CONDITION") def test_unclosed_block_brace(self): content = "if(condition) {\ndisplay();\n# Missing closing brace" @@ -226,9 +218,7 @@ def test_mixed_valid_and_invalid_if_statements(self): IfErrorType.TERMINATED_AFTER_CONDITION, result.errors[0].error_type, ) - self.assertEqual( - IfErrorType.UNCLOSED_CONDITION, result.errors[1].error_type - ) + self.assertEqual(IfErrorType.UNCLOSED_CONDITION, result.errors[1].error_type) def test_multiple_nested_inline_if_statements(self): content = """ diff --git a/tests/helper/test_linguistic_exception_handler.py b/tests/helper/test_linguistic_exception_handler.py index 2cedcc57..2f6015cd 100644 --- a/tests/helper/test_linguistic_exception_handler.py +++ b/tests/helper/test_linguistic_exception_handler.py @@ -132,9 +132,7 @@ def test_patterns_in_file_check(self): self.assertEqual(check.execute("test", "hello3hello"), False) def test_patterns_tuple_in_file_check(self): - check = PatternsInFileCheck( - "test", [(r"test\d", re.IGNORECASE), (r"hello\dtest", 0)] - ) + check = PatternsInFileCheck("test", [(r"test\d", re.IGNORECASE), (r"hello\dtest", 0)]) self.assertEqual(check.execute("test", "test1"), True) self.assertEqual(check.execute("test", "TEST2"), True) @@ -158,9 +156,7 @@ def test_pattern_in_file_pattern_check(self): self.assertEqual(check.execute("foo1", "test1"), False) def test_pattern_in_file_pattern_flags_check(self): - check = PatternInFilePatternCheck( - r"test|hello", r"foo|bar", re.IGNORECASE, re.IGNORECASE - ) + check = PatternInFilePatternCheck(r"test|hello", r"foo|bar", re.IGNORECASE, re.IGNORECASE) self.assertEqual(check.execute("test1", "foo1"), True) self.assertEqual(check.execute("test1", "FOO2"), True) @@ -200,15 +196,7 @@ def test_patterns_in_file_pattern_flags_check(self): def test_linguistic_exception_handler(self): checks = [FileCheck("test"), TextCheck("foo")] - self.assertEqual( - handle_linguistic_checks("test1", "foo1", checks), True - ) - self.assertEqual( - handle_linguistic_checks("test1", "bar1", checks), True - ) - self.assertEqual( - handle_linguistic_checks("hello1", "foo1", checks), True - ) - self.assertEqual( - handle_linguistic_checks("hello1", "bar1", checks), False - ) + self.assertEqual(handle_linguistic_checks("test1", "foo1", checks), True) + self.assertEqual(handle_linguistic_checks("test1", "bar1", checks), True) + self.assertEqual(handle_linguistic_checks("hello1", "foo1", checks), True) + self.assertEqual(handle_linguistic_checks("hello1", "bar1", checks), False) diff --git a/tests/helper/test_patterns.py b/tests/helper/test_patterns.py index c929b367..3350dd6a 100644 --- a/tests/helper/test_patterns.py +++ b/tests/helper/test_patterns.py @@ -49,11 +49,7 @@ def test_same_patterns_instance(self): self.assertIs(patterns1, patterns2) def test_same_pattern_instance(self): - pattern1 = get_special_script_tag_pattern( - SpecialScriptTag.ADD_PREFERENCE - ) - pattern2 = get_special_script_tag_pattern( - SpecialScriptTag.ADD_PREFERENCE - ) + pattern1 = get_special_script_tag_pattern(SpecialScriptTag.ADD_PREFERENCE) + pattern2 = get_special_script_tag_pattern(SpecialScriptTag.ADD_PREFERENCE) self.assertIs(pattern1, pattern2) diff --git a/tests/helper/test_remove_comments.py b/tests/helper/test_remove_comments.py index 4c8b8829..1345bd25 100644 --- a/tests/helper/test_remove_comments.py +++ b/tests/helper/test_remove_comments.py @@ -13,9 +13,7 @@ def test_empty_string(self): self.assertEqual(remove_comments(input_content), expected_output) def test_no_comments(self): - input_content = ( - "function detect_archlinux(sock, port, SCRIPT_DESC, is_pfsense) {" - ) + input_content = "function detect_archlinux(sock, port, SCRIPT_DESC, is_pfsense) {" expected_output = input_content self.assertEqual(remove_comments(input_content), expected_output) @@ -25,14 +23,14 @@ def test_full_line_comments(self): self.assertEqual(remove_comments(input_content), expected_output) def test_inline_comments(self): - input_content = ( - "function hello(){ # A function\n return 42; # The answer" - ) + input_content = "function hello(){ # A function\n return 42; # The answer" expected_output = "function hello(){ \n return 42; " self.assertEqual(remove_comments(input_content), expected_output) def test_hash_in_strings(self): - input_content = "message = 'This # is not a comment';\nurl = \"http://example.com/#anchor\";" + input_content = ( + "message = 'This # is not a comment';\nurl = \"http://example.com/#anchor\";" + ) expected_output = input_content self.assertEqual(remove_comments(input_content), expected_output) @@ -41,9 +39,7 @@ def test_mixed_quotes_and_comments(self): "display('Hash: #'); # Real comment\n" 's = "My string with # character"; # Another comment' ) - expected_output = ( - "display('Hash: #'); \ns = \"My string with # character\"; " - ) + expected_output = "display('Hash: #'); \ns = \"My string with # character\"; " self.assertEqual(remove_comments(input_content), expected_output) def test_complex_scenario(self): @@ -69,9 +65,7 @@ def test_complex_scenario(self): self.assertEqual(remove_comments(input_content), expected_output) def test_indented_comments(self): - input_content = ( - "function func() {\n # Indented comment\n return 0;\n}" - ) + input_content = "function func() {\n # Indented comment\n return 0;\n}" expected_output = "function func() {\n\n return 0;\n}" self.assertEqual(remove_comments(input_content), expected_output) diff --git a/tests/helper/test_text_utils.py b/tests/helper/test_text_utils.py index 9107dd1d..6dec704d 100644 --- a/tests/helper/test_text_utils.py +++ b/tests/helper/test_text_utils.py @@ -149,9 +149,7 @@ def test_position_after_string(self): def test_escaped_quote_in_single_quotes(self): text = "x = 'don\\'t';" self.assertTrue(is_position_in_string(text, 8)) # inside the string - self.assertTrue( - is_position_in_string(text, 10) - ) # after the escaped quote + self.assertTrue(is_position_in_string(text, 10)) # after the escaped quote def test_mixed_quotes(self): text = 'a = "it\'s ok"; b = \'say "hi"\';' diff --git a/tests/plugins/test_badwords.py b/tests/plugins/test_badwords.py index ea81d976..aad9a7c1 100644 --- a/tests/plugins/test_badwords.py +++ b/tests/plugins/test_badwords.py @@ -56,9 +56,7 @@ def test_combined(self): path = Path("some/find_service3.nasl") content = " OpenVAS-8 and probably prior\nOpenVAS-9" - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckBadwords(fake_context) results = list(plugin.run()) @@ -72,9 +70,7 @@ def test_exception_ok(self): "https://www.invt.com/software-download\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckBadwords(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_copyright_text.py b/tests/plugins/test_copyright_text.py index e701db7f..ef2a6468 100644 --- a/tests/plugins/test_copyright_text.py +++ b/tests/plugins/test_copyright_text.py @@ -48,9 +48,7 @@ def test_ok(self): "right holder(s).\n" ' script_copyright("Copyright (C) 1234");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightText(fake_context) @@ -75,9 +73,7 @@ def test_missing_statement(self): "# advisory, and are Copyright (C) the respective author(s)\n" ' script_copyright("Copyright (C) 134");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightText(fake_context) @@ -99,9 +95,7 @@ def test_wrong_copyright_text(self): f"{wrong_text}" ' script_copyright("Copyright (C) 1234");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightText(fake_context) @@ -125,9 +119,7 @@ def test_fix_wrong_copyright_text(self): ) path.write_text(content, encoding=CURRENT_ENCODING) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightText(fake_context) @@ -138,7 +130,6 @@ def test_fix_wrong_copyright_text(self): self.assertIsInstance(results[0], LinterFix) self.assertEqual( - "The copyright statement has been updated to " - f"{CORRECT_COPYRIGHT_PHRASE}", + "The copyright statement has been updated to " f"{CORRECT_COPYRIGHT_PHRASE}", results[0].message, ) diff --git a/tests/plugins/test_copyright_year.py b/tests/plugins/test_copyright_year.py index 671203a6..e4399fe8 100644 --- a/tests/plugins/test_copyright_year.py +++ b/tests/plugins/test_copyright_year.py @@ -33,9 +33,7 @@ def test_ok_new_header(self): ' script_copyright("Copyright (C) 2022 Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) @@ -50,9 +48,7 @@ def test_ok_old_header(self): '+0200 (Tue, 14 May 2022)");\n' ' script_copyright("Copyright (C) 2022 Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) @@ -70,9 +66,7 @@ def test_pre2008_ok_new_header(self): '+0200 (Tue, 14 May 2022)");\n' ' script_copyright("Copyright (C) 2020 Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) @@ -86,9 +80,7 @@ def test_pre2008_ok_old_header(self): '+0200 (Tue, 14 May 2022)");\n' ' script_copyright("Copyright (C) 2020 Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) @@ -110,16 +102,12 @@ def test_missing_creation_date(self): ' script_copyright("Copyright (C) 2022 Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) self.assertEqual(len(results), 1) - self.assertEqual( - "Missing creation_date statement in VT", results[0].message - ) + self.assertEqual("Missing creation_date statement in VT", results[0].message) def test_missing_copyright_tag(self): path = Path("some/file.nasl") @@ -129,9 +117,7 @@ def test_missing_copyright_tag(self): '+0200 (Tue, 14 May 2022)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) @@ -147,9 +133,7 @@ def test_regex_fail_copyright_tag(self): ' script_copyright("Copyright (C) Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) @@ -167,9 +151,7 @@ def test_missing_header_copyright(self): ' script_copyright("Copyright (C) 2022 Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) @@ -188,9 +170,7 @@ def test_pre2008_fail(self): '+0200 (Tue, 14 May 2020)");\n' ' script_copyright("Copyright (C) 2021 Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) @@ -200,8 +180,7 @@ def test_pre2008_fail(self): results[0].message, ) self.assertEqual( - "a pre2008 vt has a copyright value in the fileheader" - " newer than the creation_year", + "a pre2008 vt has a copyright value in the fileheader" " newer than the creation_year", results[1].message, ) @@ -214,9 +193,7 @@ def test_fail(self): ' script_copyright("Copyright (C) 1000 Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCopyrightYear(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_creation_date.py b/tests/plugins/test_creation_date.py index 96d1ccf8..69788626 100644 --- a/tests/plugins/test_creation_date.py +++ b/tests/plugins/test_creation_date.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"creation_date", value:"2013-05-14 11:24:55 ' '+0200 (Tue, 14 May 2013)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCreationDate(fake_context) results = list(plugin.run()) @@ -55,9 +53,7 @@ def test_missing_creation_date(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:N/C:P/I:P/A:P");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCreationDate(fake_context) results = list(plugin.run()) @@ -79,9 +75,7 @@ def test_missing_last_modification_date(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:N/C:P/I:P/A:P");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCreationDate(fake_context) results = list(plugin.run()) @@ -96,9 +90,7 @@ def test_creation_date_greater_than_last_modification(self): ' script_tag(name:"last_modification", value:"2025-01-01 00:00:00 ' '+0200 (Wed, 01 Jan 2025)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCreationDate(fake_context) results = list(plugin.run()) @@ -119,9 +111,7 @@ def test_creation_date_equal_last_modification(self): ' script_tag(name:"last_modification", value:"2025-01-01 00:00:00 ' '+0200 (Wed, 01 Jan 2025)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCreationDate(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_cve_format.py b/tests/plugins/test_cve_format.py index ece2f409..c6d0d878 100644 --- a/tests/plugins/test_cve_format.py +++ b/tests/plugins/test_cve_format.py @@ -28,12 +28,9 @@ class CheckCVEFormatTestCase(PluginTestCase): def test_ok(self): path = Path("some/file.nasl") content = ( - ' script_tag(name:"cvss_base", value:"7.5");\n' - ' script_cve_id("CVE-2022-23807");\n' - ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content + ' script_tag(name:"cvss_base", value:"7.5");\n' ' script_cve_id("CVE-2022-23807");\n' ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVEFormat(fake_context) results = list(plugin.run()) @@ -52,9 +49,7 @@ def test_exclude_inc_file(self): def test_detection_script(self): path = Path("some/file.nasl") content = ' script_tag(name:"cvss_base", value:"0.0");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVEFormat(fake_context) results = list(plugin.run()) @@ -64,9 +59,7 @@ def test_detection_script(self): def test_no_cve_reference(self): path = Path("some/file.nasl") content = ' script_tag(name:"cvss_base", value:"7.5");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVEFormat(fake_context) results = list(plugin.run()) @@ -81,12 +74,9 @@ def test_no_cve_reference(self): def test_invalid_cve_format(self): path = Path("some/file.nasl") content = ( - ' script_tag(name:"cvss_base", value:"10.0");\n' - ' script_cve_id("CVE-a123-23807");\n' - ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content + ' script_tag(name:"cvss_base", value:"10.0");\n' ' script_cve_id("CVE-a123-23807");\n' ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVEFormat(fake_context) results = list(plugin.run()) @@ -101,13 +91,10 @@ def test_invalid_cve_format(self): def test_more_then_four_digits(self): path = Path("some/file.nasl") content = ( - ' script_tag(name:"cvss_base", value:"7.5");\n' - ' script_cve_id("CVE-2021-03807");\n' + ' script_tag(name:"cvss_base", value:"7.5");\n' ' script_cve_id("CVE-2021-03807");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVEFormat(fake_context) results = list(plugin.run()) @@ -122,12 +109,9 @@ def test_more_then_four_digits(self): def test_invalid_year(self): path = Path("some/file.nasl") content = ( - ' script_tag(name:"cvss_base", value:"7.5");\n' - ' script_cve_id("CVE-1971-3807");\n' - ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content + ' script_tag(name:"cvss_base", value:"7.5");\n' ' script_cve_id("CVE-1971-3807");\n' ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVEFormat(fake_context) results = list(plugin.run()) @@ -144,9 +128,7 @@ def test_invalid_year(self): ' script_tag(name:"cvss_base", value:"7.5");\n' f' script_cve_id("CVE-{current_year + 1}-3807");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVEFormat(fake_context) results = list(plugin.run()) @@ -164,9 +146,7 @@ def test_duplicate_cves(self): ' script_tag(name:"cvss_base", value:"7.5");\n' ' script_cve_id("CVE-2021-3807","CVE-2021-3807");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVEFormat(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_cvss_format.py b/tests/plugins/test_cvss_format.py index 7c1028f9..7bf4febc 100644 --- a/tests/plugins/test_cvss_format.py +++ b/tests/plugins/test_cvss_format.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVSSFormat(fake_context) results = list(plugin.run()) @@ -56,9 +54,7 @@ def test_invalid_base(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVSSFormat(fake_context) results = list(plugin.run()) @@ -72,13 +68,8 @@ def test_invalid_base(self): def test_missing_base(self): path = Path("some/file.nasl") - content = ( - ' script_tag(name:"cvss_base_vector", ' - 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' - ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + content = ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVSSFormat(fake_context) results = list(plugin.run()) @@ -97,9 +88,7 @@ def test_invalid_vector(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVSSFormat(fake_context) results = list(plugin.run()) @@ -114,9 +103,7 @@ def test_invalid_vector(self): def test_missing_vector(self): path = Path("some/file.nasl") content = ' script_tag(name:"cvss_base", value:"4.0");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVSSFormat(fake_context) results = list(plugin.run()) @@ -135,9 +122,7 @@ def test_missing_cvss_base(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckCVSSFormat(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_dependencies.py b/tests/plugins/test_dependencies.py index eefd6117..ec5bd9e3 100644 --- a/tests/plugins/test_dependencies.py +++ b/tests/plugins/test_dependencies.py @@ -88,8 +88,7 @@ def test_dependency_missing(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - f"The script dependency {dependency} could " - "not be found within the VTs.", + f"The script dependency {dependency} could " "not be found within the VTs.", results[0].message, ) @@ -188,8 +187,7 @@ def test_dependency_missing_newline(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "The script dependency example2.nasl could " - "not be found within the VTs.", + "The script dependency example2.nasl could " "not be found within the VTs.", results[0].message, ) diff --git a/tests/plugins/test_dependency_category_order.py b/tests/plugins/test_dependency_category_order.py index c7f0ef11..3f392eb2 100644 --- a/tests/plugins/test_dependency_category_order.py +++ b/tests/plugins/test_dependency_category_order.py @@ -32,9 +32,7 @@ def setUp(self) -> None: self.dir = Path(self.tempdir) / "foo" self.dir.mkdir(parents=True) self.dep = self.dir / "example.nasl" - self.dep.write_text( - " script_category(ACT_ATTACK);", encoding=CURRENT_ENCODING - ) + self.dep.write_text(" script_category(ACT_ATTACK);", encoding=CURRENT_ENCODING) return super().setUp() @@ -48,9 +46,7 @@ def test_ok(self): ' script_tag(name:"summary", value:"Foo Bar.");\n' " script_category(ACT_ATTACK);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDependencyCategoryOrder(fake_context) results = list(plugin.run()) @@ -64,9 +60,7 @@ def test_no_dependency(self): ' script_tag(name:"summary", value:"Foo Bar.");\n' " script_category(ACT_ATTACK);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDependencyCategoryOrder(fake_context) results = list(plugin.run()) @@ -92,8 +86,7 @@ def test_dependency_missing(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - f"The script dependency {dependency} could " - "not be found within the VTs.", + f"The script dependency {dependency} could " "not be found within the VTs.", results[0].message, ) diff --git a/tests/plugins/test_deprecated_dependency.py b/tests/plugins/test_deprecated_dependency.py index 20880d9d..a9612196 100644 --- a/tests/plugins/test_deprecated_dependency.py +++ b/tests/plugins/test_deprecated_dependency.py @@ -47,9 +47,7 @@ def test_ok(self): ' script_tag(name:"summary", value:"Foo Bar.");\n' " script_category(ACT_ATTACK);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDeprecatedDependency(fake_context) results = list(plugin.run()) @@ -72,9 +70,7 @@ def test_no_dependency(self): ' script_tag(name:"summary", value:"Foo Bar.");\n' " script_category(ACT_ATTACK);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDeprecatedDependency(fake_context) results = list(plugin.run()) @@ -89,9 +85,7 @@ def test_deprecated(self): " script_category(ACT_ATTACK);\n" "exit(66);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDeprecatedDependency(fake_context) results = list(plugin.run()) @@ -106,9 +100,7 @@ def test_deprecated2(self): " script_category(ACT_ATTACK);\n" ' script_tag(name:"deprecated", value:TRUE);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDeprecatedDependency(fake_context) results = list(plugin.run()) @@ -135,8 +127,7 @@ def test_dependency_missing(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - f"The script dependency {dependency} could " - "not be found within the VTs.", + f"The script dependency {dependency} could " "not be found within the VTs.", results[0].message, ) diff --git a/tests/plugins/test_deprecated_functions.py b/tests/plugins/test_deprecated_functions.py index 8ae55c5b..ba48bc46 100644 --- a/tests/plugins/test_deprecated_functions.py +++ b/tests/plugins/test_deprecated_functions.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"summary", value:"Foo Bar.");\n' " script_category(ACT_ATTACK);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDeprecatedFunctions(fake_context) results = list(plugin.run()) @@ -48,9 +46,7 @@ def test_ok_comment(self): " script_category(ACT_ATTACK);\n" "# nb: script_summary() is deprecated\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDeprecatedFunctions(fake_context) results = list(plugin.run()) @@ -62,8 +58,7 @@ def test_deprecated_functions(self): 'script_summary();, use script_tag(name:"' 'summary", value:""); instead': " script_" 'summary("deprecated");', - "script_id();, use script_oid(); with " - "the full OID instead": " script_id(123345);", + "script_id();, use script_oid(); with " "the full OID instead": " script_id(123345);", "security_note();": ' security_note("deprecated");', "security_warning();": ' security_warning("deprecated");', "security_hole();": ' security_hole("deprecated");', @@ -79,9 +74,7 @@ def test_deprecated_functions(self): ' script_tag(name:"summary", value:"Foo Bar.");\n' f" script_category(ACT_ATTACK);\n{cont}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDeprecatedFunctions(fake_context) results = list(plugin.run()) @@ -101,9 +94,7 @@ def test_nok_newline(self): " script_category(ACT_ATTACK);\n" ' script_summary("With\nnewline");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDeprecatedFunctions(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_double_end_points.py b/tests/plugins/test_double_end_points.py index d73268d1..6e9a0a54 100644 --- a/tests/plugins/test_double_end_points.py +++ b/tests/plugins/test_double_end_points.py @@ -30,9 +30,7 @@ def test_ok(self): ' script_tag(name:"cvss_base", value:"4.0");\n' ' script_tag(name:"summary", value:"Foo Bar.");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDoubleEndPoints(fake_context) results = list(plugin.run()) @@ -54,9 +52,7 @@ def test_invalid(self): ' script_tag(name:"cvss_base", value:"4.0");\n' ' script_tag(name:"summary", value:"Foo Bar...");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDoubleEndPoints(fake_context) results = list(plugin.run()) @@ -64,8 +60,6 @@ def test_invalid(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "The script tag 'summary' " - "is ending with two or more points: " - "'Foo Bar...'.", + "The script tag 'summary' " "is ending with two or more points: " "'Foo Bar...'.", results[0].message, ) diff --git a/tests/plugins/test_duplicate_oid.py b/tests/plugins/test_duplicate_oid.py index 767625ad..b347c932 100644 --- a/tests/plugins/test_duplicate_oid.py +++ b/tests/plugins/test_duplicate_oid.py @@ -29,9 +29,7 @@ class CheckDuplicateOIDTestCase(PluginTestCase): def test_ok(self): file1 = here / "test_files" / "nasl" / "21.04" / "fail.nasl" - file2 = ( - here / "test_files" / "nasl" / "21.04" / "fail_name_newline.nasl" - ) + file2 = here / "test_files" / "nasl" / "21.04" / "fail_name_newline.nasl" context = MagicMock() context.nasl_files = [file1, file2] context.root = here @@ -42,9 +40,7 @@ def test_ok(self): self.assertEqual(len(results), 0) def test_ok_no_script_oid(self): - file1 = ( - here / "test_files" / "nasl" / "21.04" / "fail_name_newline.nasl" - ) + file1 = here / "test_files" / "nasl" / "21.04" / "fail_name_newline.nasl" file2 = here / "test_files" / "nasl" / "21.04" / "fail_badwords.nasl" context = MagicMock() context.nasl_files = [file1, file2] @@ -56,8 +52,7 @@ def test_ok_no_script_oid(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "Could not find an OID" - " in 'test_files/nasl/21.04/fail_badwords.nasl'.", + "Could not find an OID" " in 'test_files/nasl/21.04/fail_badwords.nasl'.", results[0].message, ) @@ -82,13 +77,7 @@ def test_duplicate_oid_function(self): ) def test_invalid_oid(self): - file2 = ( - here - / "test_files" - / "nasl" - / "21.04" - / "fail_name_and_copyright_newline.nasl" - ) + file2 = here / "test_files" / "nasl" / "21.04" / "fail_name_and_copyright_newline.nasl" context = MagicMock() context.nasl_files = [file2] context.root = here diff --git a/tests/plugins/test_duplicated_script_tags.py b/tests/plugins/test_duplicated_script_tags.py index 68a35cb4..788fcf5c 100644 --- a/tests/plugins/test_duplicated_script_tags.py +++ b/tests/plugins/test_duplicated_script_tags.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDuplicatedScriptTags(fake_context) results = list(plugin.run()) @@ -56,9 +54,7 @@ def test_duplicated_function(self): ' script_name("Foo Bar");\n' ' script_name("Foo Bar");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDuplicatedScriptTags(fake_context) results = list(plugin.run()) @@ -66,8 +62,7 @@ def test_duplicated_function(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "The VT is using the script tag " - "'script_name' multiple number of times.", + "The VT is using the script tag " "'script_name' multiple number of times.", results[0].message, ) @@ -77,9 +72,7 @@ def test_duplicated_tag(self): ' script_tag(name:"cvss_base", value:"4.0");\n' ' script_tag(name:"cvss_base", value:"5.0");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDuplicatedScriptTags(fake_context) results = list(plugin.run()) @@ -87,8 +80,7 @@ def test_duplicated_tag(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "The VT is using the script tag " - "'cvss_base' multiple number of times.", + "The VT is using the script tag " "'cvss_base' multiple number of times.", results[0].message, ) @@ -98,9 +90,7 @@ def test_excluded_tag(self): ' script_add_preference(name:"Test", type:"checkbox");\n' ' script_add_preference(name:"Test2", type:"checkbox");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDuplicatedScriptTags(fake_context) results = list(plugin.run()) @@ -113,9 +103,7 @@ def test_excluded_dependencies(self): ' script_dependencies("vt1.nasl", "vt2.nasl");\n' ' script_dependencies("vt3.nasl", "vt4.nasl");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDuplicatedScriptTags(fake_context) results = list(plugin.run()) @@ -128,9 +116,7 @@ def test_not_excluded_dependencies(self): ' script_dependencies("vt1.nasl", "vt2.nasl");\n' ' script_dependencies("vt3.nasl", "vt4.nasl");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckDuplicatedScriptTags(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_encoding.py b/tests/plugins/test_encoding.py index db6ecbad..3b9ecbaa 100644 --- a/tests/plugins/test_encoding.py +++ b/tests/plugins/test_encoding.py @@ -55,9 +55,7 @@ def test_ok_iso_8859_1(self): # All valid ISO-8859-1 characters (0-255) # ASCII printable characters (32-126) + Latin-1 supplement (160-255) - latin1_chars = "".join( - [chr(i) for i in list(range(32, 127)) + list(range(160, 256))] - ) + latin1_chars = "".join([chr(i) for i in list(range(32, 127)) + list(range(160, 256))]) path.write_text( latin1_chars, diff --git a/tests/plugins/test_forking_nasl_functions.py b/tests/plugins/test_forking_nasl_functions.py index 9b277518..862e7627 100644 --- a/tests/plugins/test_forking_nasl_functions.py +++ b/tests/plugins/test_forking_nasl_functions.py @@ -34,9 +34,7 @@ def test_ok(self): ' script_tag(name:"solution", value:"meh");\n' 'port = get_app_port_from_cpe_prefix("cpe:/o:foo:bar");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckForkingNaslFunctions(fake_context) results = list(plugin.run()) @@ -64,9 +62,7 @@ def test_not_ok(self): "if( ! infos = get_app_port_from_cpe_prefix( cpe:CPE_PREFIX, " 'service:"www" ) )\nexit( 0 );\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckForkingNaslFunctions(fake_context) results = list(plugin.run()) @@ -95,9 +91,7 @@ def test_not_ok2(self): ")\nexit(0);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckForkingNaslFunctions(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_get_kb_on_services.py b/tests/plugins/test_get_kb_on_services.py index 6546520b..582673d6 100644 --- a/tests/plugins/test_get_kb_on_services.py +++ b/tests/plugins/test_get_kb_on_services.py @@ -30,9 +30,7 @@ def test_ok(self): ' script_oid("1.2.3.4.5.6.78909.8.7.000000");\n' ' script_tag(name:"cvss_base", value:"4.0");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckGetKBOnServices(fake_context) results = list(plugin.run()) @@ -56,9 +54,7 @@ def test_ok_no_script_oid(self): 'port = get_kb_list("Services/udp/upnp");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckGetKBOnServices(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_grammar.py b/tests/plugins/test_grammar.py index 89704e80..c9157e8a 100644 --- a/tests/plugins/test_grammar.py +++ b/tests/plugins/test_grammar.py @@ -38,9 +38,7 @@ def test_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -57,9 +55,7 @@ def test_grammar(self): "# is prone to a security bypass vulnerabilities\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -84,9 +80,7 @@ def test_grammar2(self): "# refer the Reference\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -119,9 +113,7 @@ def test_grammar3(self): 'prone a to denial of service (DoS) vulnerability.");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -147,9 +139,7 @@ def test_grammar4(self): 'open redirect vulnerability.");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -175,9 +165,7 @@ def test_grammar5(self): 'request and checks the responses.");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -202,9 +190,7 @@ def test_grammar6(self): ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -229,9 +215,7 @@ def test_grammar7(self): ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -256,9 +240,7 @@ def test_grammar8(self): ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -283,9 +265,7 @@ def test_grammar9(self): ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -310,9 +290,7 @@ def test_grammar10(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -337,9 +315,7 @@ def test_grammar11(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -363,9 +339,7 @@ def test_grammar12(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -389,9 +363,7 @@ def test_grammar_fp(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -409,9 +381,7 @@ def test_grammar_fp1(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -427,9 +397,7 @@ def test_grammar_fp2(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -445,9 +413,7 @@ def test_grammar_fp3(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) @@ -466,9 +432,7 @@ def test_grammar_fp4(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckGrammar(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_http_links_in_tags.py b/tests/plugins/test_http_links_in_tags.py index 0906d41f..7755c057 100644 --- a/tests/plugins/test_http_links_in_tags.py +++ b/tests/plugins/test_http_links_in_tags.py @@ -34,9 +34,7 @@ def test_ok(self): ' script_tag(name:"solution", value:"meh");\n' 'port = get_app_port_from_cpe_prefix("cpe:/o:foo:bar");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckHttpLinksInTags(fake_context) results = list(plugin.run()) @@ -61,9 +59,7 @@ def test_not_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckHttpLinksInTags(fake_context) results = list(plugin.run()) @@ -89,9 +85,7 @@ def test_not_ok2(self): ' script_xref(name:"URL", ' 'value:"https://nvd.nist.gov/vuln/detail/CVE-1234");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckHttpLinksInTags(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_if_statement_syntax.py b/tests/plugins/test_if_statement_syntax.py index fa705d4a..34391d8b 100644 --- a/tests/plugins/test_if_statement_syntax.py +++ b/tests/plugins/test_if_statement_syntax.py @@ -27,9 +27,7 @@ def test_valid_if_statements(self): } """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckIfStatementSyntax(fake_context) results = list(plugin.run()) @@ -44,9 +42,7 @@ def test_unclosed_parenthesis(self): } """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckIfStatementSyntax(fake_context) results = list(plugin.run()) @@ -63,9 +59,7 @@ def test_unclosed_brace(self): # Missing closing brace """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckIfStatementSyntax(fake_context) results = list(plugin.run()) @@ -80,9 +74,7 @@ def test_missing_statement(self): # No statement follows """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckIfStatementSyntax(fake_context) results = list(plugin.run()) @@ -99,9 +91,7 @@ def test_semicolon_after_condition(self): } """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckIfStatementSyntax(fake_context) results = list(plugin.run()) @@ -116,9 +106,7 @@ def test_missing_semicolon_in_expression(self): # No semicolon at end of expression """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckIfStatementSyntax(fake_context) results = list(plugin.run()) @@ -136,9 +124,7 @@ def test_comment_handling(self): } """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckIfStatementSyntax(fake_context) results = list(plugin.run()) @@ -155,9 +141,7 @@ def test_complex_nested_error(self): } """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckIfStatementSyntax(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_illegal_characters.py b/tests/plugins/test_illegal_characters.py index 103050fc..e45d6754 100644 --- a/tests/plugins/test_illegal_characters.py +++ b/tests/plugins/test_illegal_characters.py @@ -32,9 +32,7 @@ def test_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckIllegalCharacters(fake_context) results = list(plugin.run()) @@ -68,9 +66,7 @@ def test_illegal_chars_in_various_tags(self): ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckIllegalCharacters(fake_context) results = list(plugin.run()) @@ -106,9 +102,7 @@ def test_fix_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckIllegalCharacters(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_log_messages.py b/tests/plugins/test_log_messages.py index 3ad3388a..c33987b2 100644 --- a/tests/plugins/test_log_messages.py +++ b/tests/plugins/test_log_messages.py @@ -33,9 +33,7 @@ def test_ok(self): ' script_tag(name:"solution", value:"meh");\n' ' log_message("hello test");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckLogMessages(fake_context) results = list(plugin.run()) @@ -60,9 +58,7 @@ def test_nok(self): "min_key_size2 + ' bits (key-size:algorithm:serial:issuer):\n' + " "report );\n\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckLogMessages(fake_context) results = list(plugin.run()) @@ -85,9 +81,7 @@ def test_nok2(self): "the following certificate(s) with a ECC key with less than ' + " "min_key_size + ' bits (key-size:algorithm:serial:issuer)');" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckLogMessages(fake_context) results = list(plugin.run()) @@ -108,9 +102,7 @@ def test_nok3(self): ' script_tag(name:"solution", value:"meh");\n' " log_message( );" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckLogMessages(fake_context) results = list(plugin.run()) @@ -135,9 +127,7 @@ def test_nok4(self): ' script_tag(name:"solution", value:"meh");\n' " log_message(\t);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckLogMessages(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_misplaced_compare_in_if.py b/tests/plugins/test_misplaced_compare_in_if.py index ff225da5..139dd70c 100644 --- a/tests/plugins/test_misplaced_compare_in_if.py +++ b/tests/plugins/test_misplaced_compare_in_if.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -49,9 +47,7 @@ def test_ok2(self): ' script_tag(name:"solution", value:"meh");\n' 'if( "text" >< variable ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -67,9 +63,7 @@ def test_ok3(self): ' script_tag(name:"solution", value:"meh");\n' 'if( "text" >< variable )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -85,9 +79,7 @@ def test_ok4(self): ' script_tag(name:"solution", value:"meh");\n' 'if( "text" >!< variable ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -103,9 +95,7 @@ def test_ok5(self): ' script_tag(name:"solution", value:"meh");\n' 'if( "text" >!< variable )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -121,9 +111,7 @@ def test_ok6(self): ' script_tag(name:"solution", value:"meh");\n' 'else if( "text" >< variable ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -139,9 +127,7 @@ def test_ok7(self): ' script_tag(name:"solution", value:"meh");\n' 'else if( "text" >< variable )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -157,9 +143,7 @@ def test_ok8(self): ' script_tag(name:"solution", value:"meh");\n' 'else if( "text" >!< variable ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -175,9 +159,7 @@ def test_ok9(self): ' script_tag(name:"solution", value:"meh");\n' 'else if( "text" >!< variable )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -193,9 +175,7 @@ def test_ok10(self): ' script_tag(name:"solution", value:"meh");\n' '} else if( "text" >< variable ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -211,9 +191,7 @@ def test_ok11(self): ' script_tag(name:"solution", value:"meh");\n' '} else if( "text" >< variable )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -229,9 +207,7 @@ def test_ok12(self): ' script_tag(name:"solution", value:"meh");\n' '} else if( "text" >!< variable ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -247,9 +223,7 @@ def test_ok13(self): ' script_tag(name:"solution", value:"meh");\n' '} else if( "text" >!< variable )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -265,9 +239,7 @@ def test_nok(self): ' script_tag(name:"solution", value:"meh");\n' 'if( variable >< "text" ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -290,9 +262,7 @@ def test_nok2(self): ' script_tag(name:"solution", value:"meh");\n' 'if( variable >< "text" )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -315,9 +285,7 @@ def test_nok3(self): ' script_tag(name:"solution", value:"meh");\n' 'if( variable >!< "text" ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -340,9 +308,7 @@ def test_nok4(self): ' script_tag(name:"solution", value:"meh");\n' 'if( variable >!< "text" )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -365,9 +331,7 @@ def test_nok5(self): ' script_tag(name:"solution", value:"meh");\n' 'else if( variable >< "text" ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -390,9 +354,7 @@ def test_nok6(self): ' script_tag(name:"solution", value:"meh");\n' 'else if( variable >< "text" )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -415,9 +377,7 @@ def test_nok7(self): ' script_tag(name:"solution", value:"meh");\n' 'else if( variable >!< "text" ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -440,9 +400,7 @@ def test_nok8(self): ' script_tag(name:"solution", value:"meh");\n' 'else if( variable >!< "text" )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -465,9 +423,7 @@ def test_nok9(self): ' script_tag(name:"solution", value:"meh");\n' '} else if( variable >< "text" ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -490,9 +446,7 @@ def test_nok10(self): ' script_tag(name:"solution", value:"meh");\n' '} else if( variable >< "text" )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -515,9 +469,7 @@ def test_nok11(self): ' script_tag(name:"solution", value:"meh");\n' '} else if( variable >!< "text" ) {}\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) @@ -540,9 +492,7 @@ def test_nok12(self): ' script_tag(name:"solution", value:"meh");\n' '} else if( variable >!< "text" )\nexit(1);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMisplacedCompareInIf(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_missing_desc_exit.py b/tests/plugins/test_missing_desc_exit.py index 6e87f86c..605c09f3 100644 --- a/tests/plugins/test_missing_desc_exit.py +++ b/tests/plugins/test_missing_desc_exit.py @@ -34,9 +34,7 @@ def test_ok(self): " exit(0);\n" "}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMissingDescExit(fake_context) results = list(plugin.run()) @@ -62,9 +60,7 @@ def test_nok(self): ' script_tag(name:"solution", value:"meh");\n' "}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMissingDescExit(fake_context) results = list(plugin.run()) @@ -84,9 +80,7 @@ def test_nok2(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckMissingDescExit(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_missing_tag_solution.py b/tests/plugins/test_missing_tag_solution.py index 22efe34f..a6e40fe9 100644 --- a/tests/plugins/test_missing_tag_solution.py +++ b/tests/plugins/test_missing_tag_solution.py @@ -32,9 +32,7 @@ def test_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckMissingTagSolution(fake_context) results = list(plugin.run()) @@ -56,9 +54,7 @@ def test_no_solution_type(self): ' script_tag(name:"cvss_base", value:"4.0");\n' ' script_tag(name:"summary", value:"Foo Bar...");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckMissingTagSolution(fake_context) results = list(plugin.run()) @@ -72,9 +68,7 @@ def test_missing_solution(self): ' script_tag(name:"summary", value:"Foo Bar...");' ' script_tag(name:"solution_type", value:"VendorFix");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckMissingTagSolution(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_newlines.py b/tests/plugins/test_newlines.py index cb0957b1..88d47807 100644 --- a/tests/plugins/test_newlines.py +++ b/tests/plugins/test_newlines.py @@ -28,9 +28,7 @@ class CheckNewlinesTestCase(PluginTestCase): def test_ok(self): nasl_file = Path(__file__).parent / "test.nasl" content = nasl_file.read_text(encoding=CURRENT_ENCODING) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckNewlines(fake_context) results = list(plugin.run()) @@ -38,13 +36,9 @@ def test_ok(self): self.assertEqual(len(results), 0) def test_newline_in_name(self): - nasl_file = ( - Path(__file__).parent / "test_files" / "fail_name_newline.nasl" - ) + nasl_file = Path(__file__).parent / "test_files" / "fail_name_newline.nasl" content = nasl_file.read_text(encoding=CURRENT_ENCODING) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckNewlines(fake_context) results = list(plugin.run()) @@ -57,15 +51,9 @@ def test_newline_in_name(self): ) def test_newline_in_name_and_copyright(self): - nasl_file = ( - Path(__file__).parent - / "test_files" - / "fail_name_and_copyright_newline.nasl" - ) + nasl_file = Path(__file__).parent / "test_files" / "fail_name_and_copyright_newline.nasl" content = nasl_file.read_text(encoding=CURRENT_ENCODING) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckNewlines(fake_context) results = list(plugin.run()) @@ -83,19 +71,13 @@ def test_newline_in_name_and_copyright(self): ) def test_whitespaces_in_name_and_copyright(self): - nasl_file = ( - Path(__file__).parent - / "test_files" - / "fail_name_and_copyright_newline.nasl" - ) + nasl_file = Path(__file__).parent / "test_files" / "fail_name_and_copyright_newline.nasl" content = ( ' script_name( "foodetection");\n' ' script_copyright ( "Copyright(c) Greenbone AG" ) ; \n' ' script_copyright ("Copyright(c) Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckNewlines(fake_context) results = list(plugin.run()) @@ -113,17 +95,13 @@ def test_whitespaces_in_name_and_copyright(self): ) def test_new_line(self): - nasl_file = ( - Path(__file__).parent / "test_files" / "fail_bad_new_line.nasl" - ) + nasl_file = Path(__file__).parent / "test_files" / "fail_bad_new_line.nasl" content = ( ' script_name("foo detection");' ' script_copyright("Copyright(c) Greenbone AG");\r\n' ' script_copyright("Copyrigh(c) Greenbone AG");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckNewlines(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_overlong_description_lines.py b/tests/plugins/test_overlong_description_lines.py index 3e23282b..90679335 100644 --- a/tests/plugins/test_overlong_description_lines.py +++ b/tests/plugins/test_overlong_description_lines.py @@ -52,9 +52,7 @@ def test_ok_generic(self): "ignored line that is not part of description" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckOverlongDescriptionLines(fake_context) results = list(plugin.run()) @@ -76,9 +74,7 @@ def test_ok_urls_in_comments(self): " exit(0);\n" "}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckOverlongDescriptionLines(fake_context) results = list(plugin.run()) @@ -99,9 +95,7 @@ def test_line_too_long(self): " exit(0);\n" "}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckOverlongDescriptionLines(fake_context) results = list(plugin.run()) @@ -127,9 +121,7 @@ def test_no_description_start_found(self): " exit(0);\n" "}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckOverlongDescriptionLines(fake_context) results = list(plugin.run()) @@ -151,9 +143,7 @@ def test_no_description_end_found(self): ' script_version("2021-09-02T14:01:33+0000");\n' "}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckOverlongDescriptionLines(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_overlong_script_tags.py b/tests/plugins/test_overlong_script_tags.py index d622dc5c..e8bb7189 100644 --- a/tests/plugins/test_overlong_script_tags.py +++ b/tests/plugins/test_overlong_script_tags.py @@ -34,9 +34,7 @@ def test_ok(self): ' script_tag(name:"vuldetect", value:"Shorter than 1000");\n' ' script_tag(name:"solution", value:"Shorter than 1000");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckOverlongScriptTags(fake_context) results = list(plugin.run()) @@ -55,9 +53,7 @@ def test_exclude_inc_file(self): def test_no_nasl_file(self): path = Path("some/file.inc") content = 'script_tag(name:"summary", value:"Shorter than 1000");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckOverlongScriptTags(fake_context) results = list(plugin.run()) @@ -73,9 +69,7 @@ def test_ignore_file(self): ' script_tag(name:"insight", value:"Shorter than 1000");\n' ' script_tag(name:"vuldetect", value:"Shorter than 1000");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckOverlongScriptTags(fake_context) results = list(plugin.run()) @@ -138,9 +132,7 @@ def test_one_wrong_entry(self): "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" 'oooooooooooooooooooooooooooooooooooooooooooooooooonger");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckOverlongScriptTags(fake_context) results = list(plugin.run()) @@ -255,9 +247,7 @@ def test_multiple_wrong_entries(self): "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" 'oooooooooooooooooooooooooooooooooooooooooooooooooonger");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckOverlongScriptTags(fake_context) results = list(plugin.run()) @@ -562,9 +552,7 @@ def test_all_wrong_entries(self): "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" 'oooooooooooooooooooooooooooooooooooooooooooooooooonger");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckOverlongScriptTags(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_prod_svc_detect_in_vulnvt.py b/tests/plugins/test_prod_svc_detect_in_vulnvt.py index 94ff7f01..623dba22 100644 --- a/tests/plugins/test_prod_svc_detect_in_vulnvt.py +++ b/tests/plugins/test_prod_svc_detect_in_vulnvt.py @@ -34,9 +34,7 @@ def test_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckProdSvcDetectInVulnvt(fake_context) results = list(plugin.run()) @@ -61,9 +59,7 @@ def test_nok(self): ' script_tag(name:"solution", value:"meh");\n' ' script_family("Product detection");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckProdSvcDetectInVulnvt(fake_context) results = list(plugin.run()) @@ -87,9 +83,7 @@ def test_nok2(self): ' script_family("Product detection");\n' " register_product(cpe:cpe);\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckProdSvcDetectInVulnvt(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_reporting_consistency.py b/tests/plugins/test_reporting_consistency.py index 4956ad21..53e00a04 100644 --- a/tests/plugins/test_reporting_consistency.py +++ b/tests/plugins/test_reporting_consistency.py @@ -32,9 +32,7 @@ def test_ok(self): ' script_tag(name:"solution", value:"meh");\n' " log_message('Test');\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckReportingConsistency(fake_context) results = list(plugin.run()) @@ -61,9 +59,7 @@ def test_ok2(self): "csrf token `' + token[1] + '` via a jsonp request to: ' + " " http_report_vuln_url( port:port, url:url, url_only:TRUE ) );\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckReportingConsistency(fake_context) results = list(plugin.run()) @@ -81,9 +77,7 @@ def test_fail(self): "csrf token `' + token[1] + '` via a jsonp request to: ' + " " http_report_vuln_url( port:port, url:url, url_only:TRUE ) );\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckReportingConsistency(fake_context) results = list(plugin.run()) @@ -105,9 +99,7 @@ def test_fail2(self): "csrf token `' + token[1] + '` via a jsonp request to: ' + " " http_report_vuln_url( port:port, url:url, url_only:TRUE ) );\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckReportingConsistency(fake_context) results = list(plugin.run()) @@ -130,9 +122,7 @@ def test_fail3(self): "csrf token `' + token[1] + '` via a jsonp request to: ' + " " http_report_vuln_url( port:port, url:url, url_only:TRUE ) );\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckReportingConsistency(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_add_preference_id.py b/tests/plugins/test_script_add_preference_id.py index 28888c01..aee3feda 100644 --- a/tests/plugins/test_script_add_preference_id.py +++ b/tests/plugins/test_script_add_preference_id.py @@ -39,9 +39,7 @@ def test_unique_ids(self): for content in contents: with self.subTest(content=content): - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptAddPreferenceId(fake_context) results = list(plugin.run()) @@ -103,9 +101,7 @@ def test_duplicate_id(self): for content, expected_id in contents: with self.subTest(content=content): - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptAddPreferenceId(fake_context) results = list(plugin.run()) @@ -131,9 +127,7 @@ def test_multiple_errors(self): """ expected_ids = [2, 2, 1, 3, 8] path = Path("some/file.nasl") - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptAddPreferenceId(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_add_preference_type.py b/tests/plugins/test_script_add_preference_type.py index 7b152961..1f1fbe04 100644 --- a/tests/plugins/test_script_add_preference_type.py +++ b/tests/plugins/test_script_add_preference_type.py @@ -37,9 +37,7 @@ def test_ok(self): 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' f' script_add_preference(type: "{pref_type.value}");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptAddPreferenceType(fake_context) results = list(plugin.run()) @@ -62,9 +60,7 @@ def test_no_add_preference(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptAddPreferenceType(fake_context) results = list(plugin.run()) @@ -80,9 +76,7 @@ def test_invalid(self): ' script_name("Foo Bar");\n' f"{add_pref}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptAddPreferenceType(fake_context) results = list(plugin.run()) @@ -107,9 +101,7 @@ def test_invalid_with_parameters_order(self): ' script_name("Foo Bar");\n' f"{add_pref}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptAddPreferenceType(fake_context) results = list(plugin.run()) @@ -131,9 +123,7 @@ def test_missing_type(self): ' script_name("Foo Bar");\n' f"{add_pref}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptAddPreferenceType(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_calls_empty_values.py b/tests/plugins/test_script_calls_empty_values.py index c658e70c..64eed46b 100644 --- a/tests/plugins/test_script_calls_empty_values.py +++ b/tests/plugins/test_script_calls_empty_values.py @@ -36,9 +36,7 @@ def test_ok(self): ' script_tag(name: "foo"' ", value:'foobar');\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptCallsEmptyValues(fake_context) results = list(plugin.run()) @@ -61,9 +59,7 @@ def test_missing_values(self): ' script_xref(name:"URL", value:"");\n' ' script_tag(name:"", value:"");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptCallsEmptyValues(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_calls_recommended.py b/tests/plugins/test_script_calls_recommended.py index 412e48dc..eeff99f2 100644 --- a/tests/plugins/test_script_calls_recommended.py +++ b/tests/plugins/test_script_calls_recommended.py @@ -35,9 +35,7 @@ def test_ok(self): " script_require_keys();\n" " script_mandatory_keys();\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptCallsRecommended(fake_context) results = list(plugin.run()) @@ -55,9 +53,7 @@ def test_exclude_inc_file(self): def test_missing_calls(self): content = ' script_xref(name: "URL", value:"");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptCallsRecommended(fake_context) results = list(plugin.run()) @@ -72,9 +68,7 @@ def test_dependencies_multiline(self): # tests group2 ' script_mandatory_keys("foo",\n"bar");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptCallsRecommended(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_category.py b/tests/plugins/test_script_category.py index f208ec40..94017146 100644 --- a/tests/plugins/test_script_category.py +++ b/tests/plugins/test_script_category.py @@ -27,9 +27,7 @@ class CheckScriptCategoryTestCase(PluginTestCase): def test_ok(self): path = Path("some/file.nasl") content = " script_category(ACT_GATHER_INFO);\n" - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptCategory(fake_context) results = list(plugin.run()) @@ -48,9 +46,7 @@ def test_exclude_inc_file(self): def test_missing_category(self): path = Path("some/file.nasl") content = "" - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptCategory(fake_context) results = list(plugin.run()) @@ -65,9 +61,7 @@ def test_missing_category(self): def test_invalid_category(self): path = Path("some/file.nasl") content = " script_category(ACT_FOO);\n" - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptCategory(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_copyright.py b/tests/plugins/test_script_copyright.py index 8ef7b817..d427fd99 100644 --- a/tests/plugins/test_script_copyright.py +++ b/tests/plugins/test_script_copyright.py @@ -27,9 +27,7 @@ class CheckScriptCopyrightTestCase(PluginTestCase): def test_copyright_ok(self): path = Path("some/file.nasl") content = ' script_copyright("Copyright (C) 2020 Foo Bar")\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptCopyright(fake_context) results = list(plugin.run()) @@ -48,9 +46,7 @@ def test_exclude_inc_file(self): def test_copyright_error(self): path = Path("some/file.nasl") content = ' script_copyright("Copyright 2020 Foo Bar")\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptCopyright(fake_context) results = list(plugin.run()) @@ -58,19 +54,14 @@ def test_copyright_error(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertIn( - "The VT is using an incorrect syntax for its " - "copyright statement.", + "The VT is using an incorrect syntax for its " "copyright statement.", results[0].message, ) def test_copyright_error2(self): path = Path("some/file.nasl") - content = ( - ' script_copyright("This script is Copyright (C) 2020 Foo Bar")\n' - ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + content = ' script_copyright("This script is Copyright (C) 2020 Foo Bar")\n' + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptCopyright(fake_context) results = list(plugin.run()) @@ -78,17 +69,14 @@ def test_copyright_error2(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertIn( - "The VT is using an incorrect syntax for its " - "copyright statement.", + "The VT is using an incorrect syntax for its " "copyright statement.", results[0].message, ) def test_copyright_error3(self): path = Path("some/file.nasl") content = ' script_copyright("Copyright (c) 2020 Foo Bar")\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckScriptCopyright(fake_context) results = list(plugin.run()) @@ -96,7 +84,6 @@ def test_copyright_error3(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertIn( - "The VT is using an incorrect syntax for its " - "copyright statement.", + "The VT is using an incorrect syntax for its " "copyright statement.", results[0].message, ) diff --git a/tests/plugins/test_script_family.py b/tests/plugins/test_script_family.py index 4d25f1ae..7540c223 100644 --- a/tests/plugins/test_script_family.py +++ b/tests/plugins/test_script_family.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"summary", value:"Foo Bar.");\n' ' script_family("FreeBSD Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptFamily(fake_context) results = list(plugin.run()) @@ -56,18 +54,14 @@ def test_script_family(self): ' script_tag(name:"summary", value:"Foo Bar.");\n' ' script_family("TestTest");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptFamily(fake_context) results = list(plugin.run()) self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) - self.assertEqual( - "Invalid or misspelled script family 'TestTest'", results[0].message - ) + self.assertEqual("Invalid or misspelled script family 'TestTest'", results[0].message) def test_script_family2(self): nasl_file = Path(__file__).parent / "test.nasl" @@ -75,9 +69,7 @@ def test_script_family2(self): ' script_tag(name:"cvss_base_vector", value:"AV:N/A:N");\n' ' script_tag(name:"summary", value:"Foo Bar.");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptFamily(fake_context) results = list(plugin.run()) @@ -94,15 +86,11 @@ def test_script_family3(self): ' script_family("???\\");\n' ' script_family("???\\");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptFamily(fake_context) results = list(plugin.run()) self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) - self.assertEqual( - "More then one script family exist", results[0].message - ) + self.assertEqual("More then one script family exist", results[0].message) diff --git a/tests/plugins/test_script_tag_form.py b/tests/plugins/test_script_tag_form.py index 6a1821b6..dbbae0d8 100644 --- a/tests/plugins/test_script_tag_form.py +++ b/tests/plugins/test_script_tag_form.py @@ -32,9 +32,7 @@ def test_ok(self): ' script_tag(name: "foo"' ", value:'foobar');\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagForm(fake_context) results = list(plugin.run()) @@ -52,9 +50,7 @@ def test_exclude_inc_file(self): def test_wrong_name(self): content = ' script_tag(nammmme: "foo", value:"bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagForm(fake_context) results = list(plugin.run()) @@ -69,9 +65,7 @@ def test_wrong_name(self): def test_wrong_value(self): content = ' script_tag(name: "foo", valueeeee:"bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagForm(fake_context) results = list(plugin.run()) @@ -81,9 +75,7 @@ def test_wrong_value(self): def test_wrong_missing_parameters(self): content = ' script_tag("foo", "bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagForm(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_tag_whitespaces.py b/tests/plugins/test_script_tag_whitespaces.py index ac6edb37..184cd5aa 100644 --- a/tests/plugins/test_script_tag_whitespaces.py +++ b/tests/plugins/test_script_tag_whitespaces.py @@ -37,9 +37,7 @@ def test_ok(self): ' script_xref(name:"foo3", value:"- foo\n - bar");\n' ' script_xref(name:"foo4", value:"foo\n bar");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -57,9 +55,7 @@ def test_exclude_inc_file(self): def test_script_tag_leading_whitespace(self): content = ' script_tag(name:"insight", value:" bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -74,9 +70,7 @@ def test_script_tag_leading_whitespace(self): def test_script_name_leading_whitespace(self): content = ' script_name(" MyProduct Multiple Vulnerabilities");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -91,9 +85,7 @@ def test_script_name_leading_whitespace(self): def test_script_xref_leading_whitespace(self): content = ' script_xref(name:"foo", value:" bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -108,9 +100,7 @@ def test_script_xref_leading_whitespace(self): def test_script_tag_trailing_whitespace(self): content = ' script_tag(name:"insight", value:"bar ");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -120,9 +110,7 @@ def test_script_tag_trailing_whitespace(self): def test_script_name_trailing_whitespace(self): content = ' script_name("MyProduct Multiple Vulnerabilities ");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -132,9 +120,7 @@ def test_script_name_trailing_whitespace(self): def test_script_xref_trailing_whitespace(self): content = ' script_xref(name:"foo", value:"bar ");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -151,9 +137,7 @@ def test_script_xref_trailing_whitespace(self): # dedicated plugin) so no specific test cases have been added here. def test_script_tag_trailing_newline(self): content = ' script_tag(name:"insight", value:"bar\n");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -163,9 +147,7 @@ def test_script_tag_trailing_newline(self): def test_script_tag_trailing_newline_with_space(self): content = ' script_tag(name:"insight", value:"foo bar\n");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -175,9 +157,7 @@ def test_script_tag_trailing_newline_with_space(self): def test_script_tag_trailing_newline_with_newline(self): content = ' script_tag(name:"insight", value:"foo\nbar\n");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -187,9 +167,7 @@ def test_script_tag_trailing_newline_with_newline(self): def test_script_tag_trailing_newline_with_newline_and_spaces(self): content = ' script_tag(name:"insight", value:"foo\n bar\n");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -202,9 +180,7 @@ def test_script_tag_trailing_newline_with_newline_and_spaces(self): # newlines and similar for that specific case def test_script_xref_trailing_newline(self): content = ' script_xref(name:"foo", value:"bar\n");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -214,9 +190,7 @@ def test_script_xref_trailing_newline(self): def test_script_xref_trailing_newline_with_space(self): content = ' script_xref(name:"foo", value:"foo bar\n");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -226,9 +200,7 @@ def test_script_xref_trailing_newline_with_space(self): def test_script_xref_trailing_newline_with_newline(self): content = ' script_xref(name:"foo", value:"foo\nbar\n");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) @@ -238,9 +210,7 @@ def test_script_xref_trailing_newline_with_newline(self): def test_script_xref_trailing_newline_with_newline_and_spaces(self): content = ' script_xref(name:"foo", value:"foo\n bar\n");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagWhitespaces(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_tags_mandatory.py b/tests/plugins/test_script_tags_mandatory.py index be0a2820..2f2afdee 100644 --- a/tests/plugins/test_script_tags_mandatory.py +++ b/tests/plugins/test_script_tags_mandatory.py @@ -36,9 +36,7 @@ def test_ok(self): ' script_tag(name:"cvss_base", value:"10.0");\n' ' script_tag(name:"cvss_base_vector", value:"AV:N/AC:L/Au:N/C:C/I:C/A:C");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagsMandatory(fake_context) results = list(plugin.run()) @@ -56,9 +54,7 @@ def test_exclude_inc_file(self): def test_missing_tags_calls(self): content = ' script_xref(name: "URL", value:"");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagsMandatory(fake_context) results = list(plugin.run()) @@ -74,9 +70,7 @@ def test_missing_tags(self): " script_family(FAMILY);\n" ' script_copyright("COPYRIGHT");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagsMandatory(fake_context) results = list(plugin.run()) @@ -86,9 +80,7 @@ def test_missing_tags(self): def test_missing_calls(self): content = ' script_tag(name:"summary", value:"foo");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptTagsMandatory(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_version_and_last_modification_tags.py b/tests/plugins/test_script_version_and_last_modification_tags.py index e67d305d..639ecefe 100644 --- a/tests/plugins/test_script_version_and_last_modification_tags.py +++ b/tests/plugins/test_script_version_and_last_modification_tags.py @@ -33,9 +33,7 @@ def test_ok(self): ' script_tag(name: "last_modification", value: "2021-07-19 ' '12:32:02 +0000 (Mon, 19 Jul 2021)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -58,9 +56,7 @@ def test_nok(self): ' script_tag(name: "last_modification", value: "2021_07-19 ' '12:32:02 +0000 (Mon, 19 Jul 2021)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -72,8 +68,7 @@ def test_nok(self): results[0].message, ) self.assertEqual( - "VT is is using a wrong syntax for script_tag(name:" - '"last_modification".', + "VT is is using a wrong syntax for script_tag(name:" '"last_modification".', results[1].message, ) @@ -84,9 +79,7 @@ def test_old_nok(self): ' script_tag(name: "last_modification", value: "$Date: 2021-07-19 ' '12:32:02 +0000 (Mon, 19 Jul 2021) $");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -98,8 +91,7 @@ def test_old_nok(self): results[0].message, ) self.assertEqual( - "VT is is using a wrong syntax for script_tag(name:" - '"last_modification".', + "VT is is using a wrong syntax for script_tag(name:" '"last_modification".', results[1].message, ) @@ -111,9 +103,7 @@ def test_missing_script_version(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -132,17 +122,13 @@ def test_version_wrong_format(self): ' script_tag(name: "last_modification", value: "2021-07-19 ' '12:32:02 +0000 (Mon, 19 Jul 2021)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) self.assertEqual(1, len(results)) - self.assertEqual( - results[0].message, "False or incorrectly formatted version." - ) + self.assertEqual(results[0].message, "False or incorrectly formatted version.") def test_fix_last_modification_date(self): with self.create_directory() as testdir: @@ -178,9 +164,7 @@ def test_modification_date_wrong_format(self): ' script_tag(name: "last_modification", value: "2021-07-19 ' '12:32:02 +0000 (Mon, 19 Jul 2021x");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -198,9 +182,7 @@ def test_modification_date_differing_dates(self): ' script_tag(name: "last_modification", value: "3021-07-19 ' '12:32:02 +0000 (Mon, 19 Jul 2021)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -218,9 +200,7 @@ def test_modification_date_wrong_day(self): ' script_tag(name: "last_modification", value: "2021-07-19 ' '12:32:02 +0000 (Tue, 19 Jul 2021)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -238,9 +218,7 @@ def test_modification_date_malformed_hour(self): ' script_tag(name:"last_modification", value:"2021-07-19 ' '112:32:02 +0000 (Mon, 19 Jul 2021");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -258,9 +236,7 @@ def test_modification_date_malformed_second(self): ' script_tag(name:"last_modification", value:"2021-07-19 ' '12:32:02s +0000 (Mon, 19 Jul 2021");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) @@ -278,9 +254,7 @@ def test_modification_date_malformed_day(self): ' script_tag(name:"last_modification", value:"2021-07-19D ' '12:32:02 +0000 (Mon, 19 Jul 2021");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckScriptVersionAndLastModificationTags(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_xref_form.py b/tests/plugins/test_script_xref_form.py index 93452f5a..2257deb7 100644 --- a/tests/plugins/test_script_xref_form.py +++ b/tests/plugins/test_script_xref_form.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name: "foo"' ", value:'foobar');\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefForm(fake_context) results = list(plugin.run()) @@ -51,9 +49,7 @@ def test_exclude_inc_file(self): def test_wrong_name(self): content = ' script_xref(nammmme: "foo", value:"bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefForm(fake_context) results = list(plugin.run()) @@ -68,9 +64,7 @@ def test_wrong_name(self): def test_wrong_value(self): content = ' script_xref(name: "foo", valueeeee:"bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefForm(fake_context) results = list(plugin.run()) @@ -80,9 +74,7 @@ def test_wrong_value(self): def test_wrong_missing_parameters(self): content = ' script_xref("foo", "bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefForm(fake_context) results = list(plugin.run()) @@ -92,9 +84,7 @@ def test_wrong_missing_parameters(self): def test_wrong_missing_name_parameter(self): content = ' script_xref("foo", value:"bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefForm(fake_context) results = list(plugin.run()) @@ -104,9 +94,7 @@ def test_wrong_missing_name_parameter(self): def test_wrong_missing_value_parameter(self): content = ' script_xref(name:"foo", "bar");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefForm(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_script_xref_url.py b/tests/plugins/test_script_xref_url.py index a1af757b..26553b6c 100644 --- a/tests/plugins/test_script_xref_url.py +++ b/tests/plugins/test_script_xref_url.py @@ -60,9 +60,7 @@ def test_ok(self): ' script_xref(name:"URL", value:"https://confluence.atlassian.com/security/security-bulletin-may-21-2024-1387867145.html");\n' # pylint: enable=line-too-long ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefUrl(fake_context) results = list(plugin.run()) @@ -80,9 +78,7 @@ def test_exclude_inc_file(self): def test_generic_invalid_url(self): content = ' script_xref(name:"URL", value:"www.example.com");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefUrl(fake_context) results = list(plugin.run()) @@ -90,16 +86,13 @@ def test_generic_invalid_url(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - 'script_xref(name:"URL", value:"www.example.com");: Invalid URL' - " value", + 'script_xref(name:"URL", value:"www.example.com");: Invalid URL' " value", results[0].message, ) def test_invalid_url_trailing_angle_bracket(self): content = ' script_xref(name:"URL", value:"https://docs.docker.com/engine/release-notes/24.0/#2407>");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefUrl(fake_context) results = list(plugin.run()) @@ -115,9 +108,7 @@ def test_invalid_url_trailing_angle_bracket(self): def test_invalid_url_trailing_comma(self): content = ' script_xref(name:"URL", value:"https://dev.mysql.com/doc/refman/5.7/en/mysql-stmt-fetch.html,");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefUrl(fake_context) results = list(plugin.run()) @@ -133,9 +124,7 @@ def test_invalid_url_trailing_comma(self): def test_invalid_url_trailing_punctuation_mark(self): content = ' script_xref(name:"URL", value:"http://isec.pl/vulnerabilities/isec-0017-binfmt_elf.txt:");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefUrl(fake_context) results = list(plugin.run()) @@ -150,12 +139,8 @@ def test_invalid_url_trailing_punctuation_mark(self): ) def test_invalid_url_trailing_square_bracket(self): - content = ( - ' script_xref(name:"URL", value:"https://example.com/foo/bar]");\n' - ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + content = ' script_xref(name:"URL", value:"https://example.com/foo/bar]");\n' + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefUrl(fake_context) results = list(plugin.run()) @@ -169,12 +154,8 @@ def test_invalid_url_trailing_square_bracket(self): ) def test_invalid_url_trailing_round_bracket(self): - content = ( - ' script_xref(name:"URL", value:"https://example.com/foo/bar)");\n' - ) - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + content = ' script_xref(name:"URL", value:"https://example.com/foo/bar)");\n' + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefUrl(fake_context) results = list(plugin.run()) @@ -189,9 +170,7 @@ def test_invalid_url_trailing_round_bracket(self): def test_invalid_url_wrong_ending(self): content = ' script_xref(name:"URL", value:"https://confluence.atlassian.com/security/security-bulletin-may-21-2024-1387867145.htmll");\n' - fake_context = self.create_file_plugin_context( - nasl_file=self.path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=self.path, file_content=content) plugin = CheckScriptXrefUrl(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_security_messages.py b/tests/plugins/test_security_messages.py index a40c7ae0..319c4eef 100644 --- a/tests/plugins/test_security_messages.py +++ b/tests/plugins/test_security_messages.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSecurityMessages(fake_context) results = list(plugin.run()) @@ -60,9 +58,7 @@ def test_ok2(self): "csrf token `' + token[1] + '` via a jsonp request to: ' + " " http_report_vuln_url( port:port, url:url, url_only:TRUE ) );\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSecurityMessages(fake_context) results = list(plugin.run()) @@ -80,9 +76,7 @@ def test_nok(self): "csrf token `' + token[1] + '` via a jsonp request to: ' + " " http_report_vuln_url( port:port, url:url, url_only:TRUE ) );\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSecurityMessages(fake_context) results = list(plugin.run()) @@ -90,8 +84,7 @@ def test_nok(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "VT is using a security_message or implementing" - " function in a VT without severity", + "VT is using a security_message or implementing" " function in a VT without severity", results[0].message, ) @@ -105,9 +98,7 @@ def test_nok2(self): "csrf token `' + token[1] + '` via a jsonp request to: ' + " " http_report_vuln_url( port:port, url:url, url_only:TRUE ) );\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSecurityMessages(fake_context) results = list(plugin.run()) @@ -115,8 +106,7 @@ def test_nok2(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "VT is using a security_message or implementing " - "function in a VT without severity", + "VT is using a security_message or implementing " "function in a VT without severity", results[0].message, ) @@ -131,9 +121,7 @@ def test_nok3(self): "csrf token `' + token[1] + '` via a jsonp request to: ' + " " http_report_vuln_url( port:port, url:url, url_only:TRUE ) );\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSecurityMessages(fake_context) results = list(plugin.run()) @@ -141,8 +129,7 @@ def test_nok3(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "VT is using a security_message or implementing" - " function in a VT without severity", + "VT is using a security_message or implementing" " function in a VT without severity", results[0].message, ) @@ -155,9 +142,7 @@ def test_deprecated(self): ' script_tag(name:"solution", value:"meh");\n' ' script_tag(name:"deprecated", value:TRUE);\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSecurityMessages(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_set_get_kb_calls.py b/tests/plugins/test_set_get_kb_calls.py index f8039f72..fcc456d6 100644 --- a/tests/plugins/test_set_get_kb_calls.py +++ b/tests/plugins/test_set_get_kb_calls.py @@ -31,9 +31,7 @@ def test_ok(self): ' get_kb_item("kb/key");\n' ' get_kb_list("kb/key");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckWrongSetGetKBCalls(fake_context) results = list(plugin.run()) @@ -49,9 +47,7 @@ def test_nok(self): ' replace_kb_item(name:"kbkey", name:"kbkey");\n' ' get_kb_item(name:"kbkey");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckWrongSetGetKBCalls(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_severity_date.py b/tests/plugins/test_severity_date.py index 9bd26204..2ab03d6e 100644 --- a/tests/plugins/test_severity_date.py +++ b/tests/plugins/test_severity_date.py @@ -17,9 +17,7 @@ def test_severity_date_ok(self): ' script_tag(name:"severity_date", value:"2013-05-14 11:24:55 ' '+0200 (Tue, 14 May 2013)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityDate(fake_context) results = list(plugin.run()) @@ -37,9 +35,7 @@ def test_exclude_inc_file(self): def test_missing_severity_date(self): path = Path("some/file.nasl") content = "" - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityDate(fake_context) results = list(plugin.run()) @@ -54,9 +50,7 @@ def test_severity_date_greater_than_last_modification(self): ' script_tag(name:"last_modification", value:"2025-01-01 00:00:00 ' '+0200 (Wed, 01 Jan 2025)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityDate(fake_context) results = list(plugin.run()) @@ -77,9 +71,7 @@ def test_severity_date_equal_last_modification(self): ' script_tag(name:"last_modification", value:"2025-01-01 00:00:00 ' '+0200 (Wed, 01 Jan 2025)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityDate(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_severity_format.py b/tests/plugins/test_severity_format.py index 9a9afd80..36d82ac7 100644 --- a/tests/plugins/test_severity_format.py +++ b/tests/plugins/test_severity_format.py @@ -17,9 +17,7 @@ def test_cvss_3_0_vector_ok(self): ' script_tag(name:"severity_vector", ' 'value:"CVSS:3.0/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:H");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityFormat(fake_context) results = list(plugin.run()) @@ -32,9 +30,7 @@ def test_invalid_cvss_3_0_vector(self): ' script_tag(name:"severity_vector", ' 'value:"CVSS:3.0/AV:N/AC:N/PR:L/UI:R/S:H/C:H/I:H/A:H");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityFormat(fake_context) results = list(plugin.run()) @@ -52,9 +48,7 @@ def test_cvss_3_1_vector_ok(self): ' script_tag(name:"severity_vector", ' 'value:"CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:H");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityFormat(fake_context) results = list(plugin.run()) @@ -67,9 +61,7 @@ def test_invalid_cvss_3_1_vector(self): ' script_tag(name:"severity_vector", ' 'value:"CVSS:3.1/AV:N/AC:N/PR:L/UI:R/S:H/C:H/I:H/A:H");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityFormat(fake_context) results = list(plugin.run()) @@ -88,9 +80,7 @@ def test_cvss_4_0_vector_ok(self): 'value:"CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:A' '/VC:H/VI:H/VA:H/SC:L/SI:L/SA:N");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityFormat(fake_context) results = list(plugin.run()) @@ -104,9 +94,7 @@ def test_invalid_cvss_4_0_vector(self): 'value:"CVSS:4.0/AV:N/AC:N/AT:N/PR:L/UI:N' '/VC:H/VI:H/VA:H/SC:L/SI:L/SA:N");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityFormat(fake_context) results = list(plugin.run()) @@ -121,9 +109,7 @@ def test_invalid_cvss_4_0_vector(self): def test_missing_severity_vector(self): path = Path("some/file.nasl") content = "" - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityFormat(fake_context) results = list(plugin.run()) @@ -133,9 +119,7 @@ def test_missing_severity_vector(self): def test_empty_severity_vector(self): path = Path("some/file.nasl") content = ' script_tag(name:"severity_vector", value:"");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityFormat(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_severity_origin.py b/tests/plugins/test_severity_origin.py index 016974c1..bedd6d9f 100644 --- a/tests/plugins/test_severity_origin.py +++ b/tests/plugins/test_severity_origin.py @@ -14,9 +14,7 @@ class CheckSeverityOriginTestCase(PluginTestCase): def test_severity_origin_nvd(self): path = Path("some/file.nasl") content = ' script_tag(name:"severity_origin", value:"NVD");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityOrigin(fake_context) results = list(plugin.run()) @@ -26,9 +24,7 @@ def test_severity_origin_nvd(self): def test_severity_origin_vendor(self): path = Path("some/file.nasl") content = ' script_tag(name:"severity_origin", value:"Vendor");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityOrigin(fake_context) results = list(plugin.run()) @@ -38,9 +34,7 @@ def test_severity_origin_vendor(self): def test_severity_origin_third_party(self): path = Path("some/file.nasl") content = ' script_tag(name:"severity_origin", value:"Third Party");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityOrigin(fake_context) results = list(plugin.run()) @@ -50,9 +44,7 @@ def test_severity_origin_third_party(self): def test_severity_origin_greenbone(self): path = Path("some/file.nasl") content = ' script_tag(name:"severity_origin", value:"Greenbone");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityOrigin(fake_context) results = list(plugin.run()) @@ -62,9 +54,7 @@ def test_severity_origin_greenbone(self): def test_severity_origin_other(self): path = Path("some/file.nasl") content = ' script_tag(name:"severity_origin", value:"Other");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityOrigin(fake_context) results = list(plugin.run()) @@ -79,9 +69,7 @@ def test_severity_origin_other(self): def test_severity_origin_empty(self): path = Path("some/file.nasl") content = ' script_tag(name:"severity_origin", value:"");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSeverityOrigin(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_solution_text.py b/tests/plugins/test_solution_text.py index 8026a71f..5ff119cc 100644 --- a/tests/plugins/test_solution_text.py +++ b/tests/plugins/test_solution_text.py @@ -53,9 +53,7 @@ def test_ok(self): "regarding this issue will be updated once solution details " 'are available.");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSolutionText(fake_context) results = list(plugin.run()) @@ -70,9 +68,7 @@ def test_ok2(self): 'value:"No solution was made available by the vendor.\n\n Note: ' '.");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSolutionText(fake_context) results = list(plugin.run()) @@ -87,9 +83,7 @@ def test_ok3(self): 'value:"No solution was made available by the vendor.\n\n Vendor ' 'statement: .");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSolutionText(fake_context) results = list(plugin.run()) @@ -99,9 +93,7 @@ def test_ok3(self): def test_nok(self): nasl_file = Path(__file__).parent / "test.nasl" content = ' script_tag(name:"solution_type", value:"NoneAvailable");\n' - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSolutionText(fake_context) results = list(plugin.run()) @@ -121,9 +113,7 @@ def test_nok(self): def test_nok2(self): nasl_file = Path(__file__).parent / "test.nasl" content = ' script_tag(name:"solution_type", value:"WillNotFix");\n' - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSolutionText(fake_context) results = list(plugin.run()) @@ -143,9 +133,7 @@ def test_nok3(self): 'value:"No solution was made available by the vendor.\n\n Notice: ' '.");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSolutionText(fake_context) results = list(plugin.run()) @@ -165,9 +153,7 @@ def test_nok4(self): 'value:"No solution was made available by the vendor.\n\n Vendor ' 'statment: .");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSolutionText(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_solution_type.py b/tests/plugins/test_solution_type.py index 3978b33e..61b1ddef 100644 --- a/tests/plugins/test_solution_type.py +++ b/tests/plugins/test_solution_type.py @@ -27,9 +27,7 @@ class CheckSolutionTypeTestCase(PluginTestCase): def test_ok(self): path = Path("some/file.nasl") content = ' script_tag(name:"cvss_base", value:"0.0");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSolutionType(fake_context) results = list(plugin.run()) @@ -51,9 +49,7 @@ def test_severity_present_ok(self): ' script_tag(name:"cvss_base", value:"1.0");\n' ' script_tag(name:"solution_type", value:"Workaround");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSolutionType(fake_context) results = list(plugin.run()) @@ -63,9 +59,7 @@ def test_severity_present_ok(self): def test_no_solution_type(self): path = Path("some/file.nasl") content = ' script_tag(name:"cvss_base", value:"1.0");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSolutionType(fake_context) results = list(plugin.run()) @@ -84,9 +78,7 @@ def test_wrong_solution_type(self): ' script_tag(name:"cvss_base", value:"1.0");\n' ' script_tag(name:"solution_type", value:"Wrong solution");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSolutionType(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_spaces_before_dots.py b/tests/plugins/test_spaces_before_dots.py index 8a31faec..4c4e8264 100644 --- a/tests/plugins/test_spaces_before_dots.py +++ b/tests/plugins/test_spaces_before_dots.py @@ -18,9 +18,7 @@ def test_ok(self): script_tag(name:"solution", value:"Foo .NET."); script_tag(name:"insight", value:"Foo Bar ..."); """ - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSpacesBeforeDots(fake_context) results = list(plugin.run()) self.assertEqual(len(results), 0) @@ -37,9 +35,7 @@ def test_fail(self): 'script_tag(name:"affected", value:"Foo\n.\nBar.");' 'script_tag(name:"solution", value:"Foo Bar\n.");' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckSpacesBeforeDots(fake_context) results = list(plugin.run()) self.assertEqual(len(results), 7) @@ -86,9 +82,7 @@ def test_fix(self): ) path.write_text(content, encoding=CURRENT_ENCODING) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckSpacesBeforeDots(fake_context) diff --git a/tests/plugins/test_tabs.py b/tests/plugins/test_tabs.py index dff91bf8..ca05a1e4 100644 --- a/tests/plugins/test_tabs.py +++ b/tests/plugins/test_tabs.py @@ -27,9 +27,7 @@ class CheckTabsTestCase(PluginTestCase): def test_ok(self): path = Path("tests/file.nasl") content = "What ever." - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckTabs(fake_context) results = list(plugin.run()) @@ -41,9 +39,7 @@ def test_with_tabs(self): content = "\t\t\t\t\t\t\n1234456789" - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckTabs(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_todo_tbd.py b/tests/plugins/test_todo_tbd.py index 7b327673..1178fa8a 100644 --- a/tests/plugins/test_todo_tbd.py +++ b/tests/plugins/test_todo_tbd.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"solution", value:"TODO");\n' ' script_tag(name:"impact", value:"@todo");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckTodoTbd(fake_context) results = list(plugin.run()) @@ -48,9 +46,7 @@ def test_ignore(self): ' script_tag(name:"solution", value:"A value");\n' ' script_tag(name:"impact", value:"A value");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckTodoTbd(fake_context) results = list(plugin.run()) @@ -65,9 +61,7 @@ def test_tbd(self): ' script_tag(name:"solution", value:"A value");\n' ' script_tag(name:"impact", value:"A value");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckTodoTbd(fake_context) results = list(plugin.run()) @@ -102,9 +96,7 @@ def test_todo(self): ' script_tag(name:"solution", value:"A value");\n' ' script_tag(name:"impact", value:"A value");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckTodoTbd(fake_context) results = list(plugin.run()) @@ -133,9 +125,7 @@ def test_at_todo(self): ' script_tag(name:"solution", value:"A value");\n' ' script_tag(name:"impact", value:"A value");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckTodoTbd(fake_context) results = list(plugin.run()) @@ -164,9 +154,7 @@ def test_mixed(self): ' script_tag(name:"solution", value:"A value");\n' ' script_tag(name:"impact", value:"A value");##@todo\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, lines=content.splitlines() - ) + fake_context = self.create_file_plugin_context(nasl_file=path, lines=content.splitlines()) plugin = CheckTodoTbd(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_trailing_spaces_tabs.py b/tests/plugins/test_trailing_spaces_tabs.py index 85b86524..89988ea1 100644 --- a/tests/plugins/test_trailing_spaces_tabs.py +++ b/tests/plugins/test_trailing_spaces_tabs.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"solution_type", value:"VendorFix");\n' ' script_tag(name:"solution", value:"meh");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckTrailingSpacesTabs(fake_context) results = list(plugin.run()) @@ -49,9 +47,7 @@ def test_nok(self): ' script_tag(name:"solution", value:"meh");\n' " \t " ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckTrailingSpacesTabs(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_using_display.py b/tests/plugins/test_using_display.py index 3d015b2a..1a530edc 100644 --- a/tests/plugins/test_using_display.py +++ b/tests/plugins/test_using_display.py @@ -31,9 +31,7 @@ def test_ok(self): ' script_tag(name:"cvss_base_vector", ' 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckUsingDisplay(fake_context) results = list(plugin.run()) @@ -48,9 +46,7 @@ def test_using_display(self): 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' ' display("FOO");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckUsingDisplay(fake_context) results = list(plugin.run()) @@ -70,9 +66,7 @@ def test_using_if_display(self): 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' 'if (0) display("FOO");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckUsingDisplay(fake_context) results = list(plugin.run()) @@ -93,9 +87,7 @@ def test_using_comment_display(self): 'value:"AV:N/AC:L/Au:S/C:N/I:P/A:N");\n' '# display("FOO");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckUsingDisplay(fake_context) results = list(plugin.run()) @@ -106,13 +98,8 @@ def test_using_comment_display(self): def test_using_debug_if_display(self): """Test that display() inside a debug if statement is allowed""" path = Path("some/file.nasl") - content = ( - ' script_tag(name:"cvss_base", value:"4.0");\n' - 'if (debug) display("FOO");\n' - ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + content = ' script_tag(name:"cvss_base", value:"4.0");\n' 'if (debug) display("FOO");\n' + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckUsingDisplay(fake_context) results = list(plugin.run()) @@ -123,9 +110,7 @@ def test_using_debug_if_display(self): def test_display_in_string_ignored(self): path = Path("some/file.nasl") content = "str = 'display(\"FOO\")';\n" - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckUsingDisplay(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_valid_oid.py b/tests/plugins/test_valid_oid.py index 226286f0..3c73be0b 100644 --- a/tests/plugins/test_valid_oid.py +++ b/tests/plugins/test_valid_oid.py @@ -30,9 +30,7 @@ def test_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.0.100376");\n' ' script_family("Huawei EulerOS Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -51,9 +49,7 @@ def test_exclude_inc_file(self): def test_empty_tag(self): path = Path("some/file.nasl") content = " script_oid();\n" - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -69,9 +65,7 @@ def test_empty_tag(self): def test_invalid_oid(self): path = Path("some/file.nasl") content = ' script_oid("1.3.6.1.4.1.25623.2.0.100376");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -80,19 +74,14 @@ def test_invalid_oid(self): self.assertIsInstance(results[0], LinterError) self.assertEqual( - ( - "script_oid() is using an invalid " - "OID '1.3.6.1.4.1.25623.2.0.100376'" - ), + ("script_oid() is using an invalid " "OID '1.3.6.1.4.1.25623.2.0.100376'"), results[0].message, ) def test_missing__script_family(self): path = Path("some/file.nasl") content = ' script_oid("1.3.6.1.4.1.25623.1.1.100376");\n' - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -108,9 +97,7 @@ def test_euler_family_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.2.2025.5555");\n' ' script_family("Huawei EulerOS Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -124,9 +111,7 @@ def test_euler_family(self): ' script_family("Huawei EulerOS Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -149,9 +134,7 @@ def test_suse_family_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.4.2025.55555.5");\n' ' script_family("SuSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -164,9 +147,7 @@ def test_suse_family(self): ' script_oid("1.3.6.1.4.1.25623.1.1.4.2025.555755.5");\n' ' script_family("SuSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -189,9 +170,7 @@ def test_debian_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.1.2256");\n' ' script_family("Debian Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -204,9 +183,7 @@ def test_debian(self): ' script_oid("1.3.6.1.4.1.25623.1.1.1.2256");\n' ' script_family("Suse Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -228,9 +205,7 @@ def test_unused_oid(self): ' script_oid("1.3.6.1.4.1.25623.1.1.3.2256");\n' ' script_family("Suse Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -252,9 +227,7 @@ def test_suse_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.4.2012.2256.1");\n' ' script_family("SuSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -267,9 +240,7 @@ def test_suse(self): ' script_oid("1.3.6.1.4.1.25623.1.1.4.2256");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -291,9 +262,7 @@ def test_amazon_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.5.2012.2256");\n' ' script_family("Amazon Linux Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -306,9 +275,7 @@ def test_amazon_with_optional_identifier(self): ' script_oid("1.3.6.1.4.1.25623.1.1.5.1.2012.2256");\n' ' script_family("Amazon Linux Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -321,9 +288,7 @@ def test_amazon(self): ' script_oid("1.3.6.1.4.1.25623.1.1.5.2256");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -345,9 +310,7 @@ def test_gentoo_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.6.2256");\n' ' script_family("Gentoo Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -360,9 +323,7 @@ def test_gentoo(self): ' script_oid("1.3.6.1.4.1.25623.1.1.6.2256");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -384,9 +345,7 @@ def test_freebsd_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.7.2256");\n' ' script_family("FreeBSD Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -399,9 +358,7 @@ def test_freebsd(self): ' script_oid("1.3.6.1.4.1.25623.1.1.7.2256");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -423,9 +380,7 @@ def test_oracle_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.8.2256");\n' ' script_family("Oracle Linux Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -438,9 +393,7 @@ def test_oracle(self): ' script_oid("1.3.6.1.4.1.25623.1.1.8.2256");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -462,9 +415,7 @@ def test_fedora_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.9.2256");\n' ' script_family("Fedora Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -477,9 +428,7 @@ def test_fedora(self): ' script_oid("1.3.6.1.4.1.25623.1.1.9.2256");\n' ' script_family("Debian Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -501,9 +450,7 @@ def test_mageia_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.10.2012.2256");\n' ' script_family("Mageia Linux Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -516,9 +463,7 @@ def test_mageia(self): ' script_oid("1.3.6.1.4.1.25623.1.1.10.2256");\n' ' script_family("Debian Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -540,9 +485,7 @@ def test_redhat_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.11.2256");\n' ' script_family("Red Hat Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -555,9 +498,7 @@ def test_redhat(self): ' script_oid("1.3.6.1.4.1.25623.1.1.11.2256");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -579,9 +520,7 @@ def test_ubuntu_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.12.2012.2256.1");\n' ' script_family("Ubuntu Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -594,9 +533,7 @@ def test_ubuntu(self): ' script_oid("1.3.6.1.4.1.25623.1.1.12.2256");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -618,9 +555,7 @@ def test_slackware_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.13.2022.123.01");\n' ' script_family("Slackware Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -633,9 +568,7 @@ def test_slackware(self): ' script_oid("1.3.6.1.4.1.25623.1.1.13.2022.123.01");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -657,9 +590,7 @@ def test_rocky_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.14.2022.123");\n' ' script_family("Rocky Linux Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -672,9 +603,7 @@ def test_rocky(self): ' script_oid("1.3.6.1.4.1.25623.1.1.14.2022.123");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -696,9 +625,7 @@ def test_opensuse_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.18.2022.123");\n' ' script_family("openSUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -711,9 +638,7 @@ def test_opensuse_not_ok(self): ' script_oid("1.3.6.1.4.1.25623.1.1.18.2022.123");\n' ' script_family("HCE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -735,9 +660,7 @@ def test_unknown(self): ' script_oid("1.3.6.1.4.1.25623.1.1.99.2256");\n' ' script_family("SUSE Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -760,9 +683,7 @@ def test_script_name__product_unknown(self): ' script_family("Huawei EulerOS Local Security Checks");\n' ' script_name("AdaptBB Detection (HTTP)");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -784,9 +705,7 @@ def test_script_name__product_firefox_ok(self): ' script_name("Mozilla Firefox Security Advisory");\n' ' script_family("General");' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -800,9 +719,7 @@ def test_script_name__product_firefox(self): ' script_name("AdaptBB Detection (HTTP)");\n' ' script_family("General");' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -824,9 +741,7 @@ def test_script_family__product_microsoft_ok(self): "\n" ' script_family("Windows Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -840,9 +755,7 @@ def test_script_family__product_microsoft_not_ok(self): "\n" ' script_family("Windows : Microsoft Bulletin ");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -862,9 +775,7 @@ def test_oid_microsoft_ok(self): "\n" ' script_family("Windows Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) @@ -878,9 +789,7 @@ def test_oid_microsoft_not_ok(self): "\n" ' script_family("Windows Local Security Checks");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=path, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=path, file_content=content) plugin = CheckValidOID(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_valid_script_tag_names.py b/tests/plugins/test_valid_script_tag_names.py index eb9a1340..e72c75ae 100644 --- a/tests/plugins/test_valid_script_tag_names.py +++ b/tests/plugins/test_valid_script_tag_names.py @@ -32,9 +32,7 @@ def test_ok_nonewline(self): ' script_tag(name:"solution", value:"meh");\n' ' script_tag(name:"vuldetect", value:"Without newline");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckValidScriptTagNames(fake_context) results = list(plugin.run()) @@ -50,9 +48,7 @@ def test_ok_newline(self): ' script_tag(name:"solution", value:"meh");\n' ' script_tag(name:"vuldetect", value:"With\nnewline");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckValidScriptTagNames(fake_context) results = list(plugin.run()) @@ -68,9 +64,7 @@ def test_nok_nonewline(self): ' script_tag(name:"solution", value:"meh");\n' ' script_tag(name:"vulndetect", value:"Without newline");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckValidScriptTagNames(fake_context) results = list(plugin.run()) @@ -91,9 +85,7 @@ def test_nok_newline(self): ' script_tag(name:"solution", value:"meh");\n' ' script_tag(name:"vulndetect", value:"With\nnewline");\n' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckValidScriptTagNames(fake_context) results = list(plugin.run()) diff --git a/tests/plugins/test_variable_redefinition_in_foreach.py b/tests/plugins/test_variable_redefinition_in_foreach.py index e08940b3..53882889 100644 --- a/tests/plugins/test_variable_redefinition_in_foreach.py +++ b/tests/plugins/test_variable_redefinition_in_foreach.py @@ -19,9 +19,7 @@ def test_ok(self): 'url1 = "foo";\n' 'foreach url(make_list(url1, "bar")) {\n display(url);\n}' ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckVariableRedefinitionInForeach(fake_context) results = list(plugin.run()) @@ -34,9 +32,7 @@ def test_fail(self): "foreach url(url) {\n display(url);\n}\n" "foreach url(make_list(url1, url)) {\n display(url);\n}\n" ) - fake_context = self.create_file_plugin_context( - nasl_file=nasl_file, file_content=content - ) + fake_context = self.create_file_plugin_context(nasl_file=nasl_file, file_content=content) plugin = CheckVariableRedefinitionInForeach(fake_context) results = list(plugin.run()) self.assertEqual(len(results), 2) diff --git a/tests/plugins/test_vt_file_permissions.py b/tests/plugins/test_vt_file_permissions.py index 2f9303d7..dc6ea16f 100644 --- a/tests/plugins/test_vt_file_permissions.py +++ b/tests/plugins/test_vt_file_permissions.py @@ -26,9 +26,7 @@ class CheckVTFilePermissionsTestCase(PluginTestCase): def test_ok(self): fake_context = self.create_file_plugin_context( - nasl_file=Path(__file__).parent - / "test_files" - / "ok_permissions.nasl" + nasl_file=Path(__file__).parent / "test_files" / "ok_permissions.nasl" ) plugin = CheckVTFilePermissions(fake_context) @@ -39,9 +37,7 @@ def test_ok(self): def test_nok(self): fake_context = self.create_file_plugin_context( - nasl_file=Path(__file__).parent - / "test_files" - / "fail_permissions.nasl" + nasl_file=Path(__file__).parent / "test_files" / "fail_permissions.nasl" ) plugin = CheckVTFilePermissions(fake_context) diff --git a/tests/plugins/test_vt_placement.py b/tests/plugins/test_vt_placement.py index b7041503..e98415d0 100644 --- a/tests/plugins/test_vt_placement.py +++ b/tests/plugins/test_vt_placement.py @@ -127,7 +127,6 @@ def test_wrong_placement(self): self.assertEqual(len(results), 1) self.assertIsInstance(results[0], LinterError) self.assertEqual( - "VT should be " - f"placed in the root directory ({tempdir}).", + "VT should be " f"placed in the root directory ({tempdir}).", results[0].message, ) diff --git a/tests/standalone_plugins/changed_packages/markers/test_added_udeb.py b/tests/standalone_plugins/changed_packages/markers/test_added_udeb.py index 7a109bb5..64c52716 100644 --- a/tests/standalone_plugins/changed_packages/markers/test_added_udeb.py +++ b/tests/standalone_plugins/changed_packages/markers/test_added_udeb.py @@ -40,9 +40,7 @@ def test_mark(self): "DEB11", {Reasons.ADDED_UDEB: Direction.ACTIVE}, ), - Package( - "bar", "4.5-6", "DEB11", {Reasons.ADDED_UDEB: Direction.ACTIVE} - ), + Package("bar", "4.5-6", "DEB11", {Reasons.ADDED_UDEB: Direction.ACTIVE}), Package( "baz", "2:1.3.3.7", diff --git a/tests/standalone_plugins/changed_packages/test_changed_packages.py b/tests/standalone_plugins/changed_packages/test_changed_packages.py index 0434d381..a9de569a 100644 --- a/tests/standalone_plugins/changed_packages/test_changed_packages.py +++ b/tests/standalone_plugins/changed_packages/test_changed_packages.py @@ -79,9 +79,7 @@ def test_get_package_duplicate(self): def test_filter_reasons(self): packages = [ - Package( - "foo", "1.2.3", "DEB11", {Reasons.ADDED_EPOCH: Direction.ACTIVE} - ), + Package("foo", "1.2.3", "DEB11", {Reasons.ADDED_EPOCH: Direction.ACTIVE}), Package( "bar", "1.2.3", @@ -91,9 +89,7 @@ def test_filter_reasons(self): Reasons.ADDED_RELEASE: Direction.PASSIVE, }, ), - Package( - "baz", "1.2.3", "DEB11", {Reasons.ADDED_UDEB: Direction.ACTIVE} - ), + Package("baz", "1.2.3", "DEB11", {Reasons.ADDED_UDEB: Direction.ACTIVE}), ] expected_packages = [ @@ -106,9 +102,7 @@ def test_filter_reasons(self): Reasons.ADDED_RELEASE: Direction.PASSIVE, }, ), - Package( - "baz", "1.2.3", "DEB11", {Reasons.ADDED_UDEB: Direction.ACTIVE} - ), + Package("baz", "1.2.3", "DEB11", {Reasons.ADDED_UDEB: Direction.ACTIVE}), ] result = filter_reasons(packages, [Reasons.ADDED_EPOCH]) diff --git a/tests/standalone_plugins/test_changed_creation_date.py b/tests/standalone_plugins/test_changed_creation_date.py index 79ff5748..2e94a17b 100644 --- a/tests/standalone_plugins/test_changed_creation_date.py +++ b/tests/standalone_plugins/test_changed_creation_date.py @@ -35,9 +35,7 @@ def test_check_creation_date_ok(self, mock_git, mock_exists): ) mock_exists.return_value = True - self.assertFalse( - check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES) - ) + self.assertFalse(check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES)) @patch("troubadix.standalone_plugins.changed_creation_date.Path.exists") @patch("troubadix.standalone_plugins.changed_creation_date.git") @@ -51,15 +49,11 @@ def test_check_creation_date_fail(self, mock_git, mock_exists): ) mock_exists.return_value = True - self.assertTrue( - check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES) - ) + self.assertTrue(check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES)) @patch("troubadix.standalone_plugins.changed_creation_date.Path.exists") @patch("troubadix.standalone_plugins.changed_creation_date.git") - def test_creation_date_not_modified_lines_added( - self, mock_git, mock_exists - ): + def test_creation_date_not_modified_lines_added(self, mock_git, mock_exists): mock_git.return_value = ( '-script_tag(name:"creation_date",' @@ -70,24 +64,16 @@ def test_creation_date_not_modified_lines_added( ) mock_exists.return_value = True - self.assertFalse( - check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES) - ) + self.assertFalse(check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES)) @patch("troubadix.standalone_plugins.changed_creation_date.Path.exists") @patch("troubadix.standalone_plugins.changed_creation_date.git") - def test_creation_date_not_modified_lines_removed( - self, mock_git, mock_exists - ): + def test_creation_date_not_modified_lines_removed(self, mock_git, mock_exists): - mock_git.return_value = ( - '-script_tag(name:"This got removed", value:"Nothing");' - ) + mock_git.return_value = '-script_tag(name:"This got removed", value:"Nothing");' mock_exists.return_value = True - self.assertFalse( - check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES) - ) + self.assertFalse(check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES)) @patch("troubadix.standalone_plugins.changed_creation_date.Path.exists") @patch("troubadix.standalone_plugins.changed_creation_date.git") @@ -100,9 +86,7 @@ def test_creation_date_added_not_removed(self, mock_git, mock_exists): ) mock_exists.return_value = True - self.assertFalse( - check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES) - ) + self.assertFalse(check_changed_creation_date(TEST_COMMIT_RANGE, TEST_FILES)) def test_git_fail(self): with self.assertRaises(SubprocessError): @@ -112,22 +96,16 @@ def test_git_ok(self): git("--version") @patch("troubadix.standalone_plugins.changed_creation_date.git") - @patch( - "troubadix.standalone_plugins.changed_creation_date.ArgumentParser.parse_args" - ) + @patch("troubadix.standalone_plugins.changed_creation_date.ArgumentParser.parse_args") def test_args_ok(self, mock_parse_args, mock_git): - mock_parse_args.return_value = Namespace( - commit_range="main..test", files=[] - ) + mock_parse_args.return_value = Namespace(commit_range="main..test", files=[]) mock_git.return_value = "test1.nasl\ntest2.nasl\ntest3.txt" parsed_args = parse_arguments() self.assertEqual(parsed_args.commit_range, "main..test") - self.assertEqual( - parsed_args.files, [Path("test1.nasl"), Path("test2.nasl")] - ) + self.assertEqual(parsed_args.files, [Path("test1.nasl"), Path("test2.nasl")]) def test_main_no_git_repository(self): cwd = Path.cwd() @@ -139,14 +117,10 @@ def test_main_no_git_repository(self): chdir(cwd) @patch("troubadix.standalone_plugins.changed_creation_date.parse_arguments") - @patch( - "troubadix.standalone_plugins.changed_creation_date.check_changed_creation_date" - ) + @patch("troubadix.standalone_plugins.changed_creation_date.check_changed_creation_date") @patch("troubadix.standalone_plugins.changed_creation_date.os.chdir") @patch("troubadix.standalone_plugins.changed_creation_date.git") - def test_main_check_creation_date_ok( - self, mock_git, _, mock_check_creation_date, __ - ): + def test_main_check_creation_date_ok(self, mock_git, _, mock_check_creation_date, __): mock_git.return_value = "test_directory" mock_check_creation_date.return_value = 0 @@ -154,14 +128,10 @@ def test_main_check_creation_date_ok( self.assertEqual(main(), 0) @patch("troubadix.standalone_plugins.changed_creation_date.parse_arguments") - @patch( - "troubadix.standalone_plugins.changed_creation_date.check_changed_creation_date" - ) + @patch("troubadix.standalone_plugins.changed_creation_date.check_changed_creation_date") @patch("troubadix.standalone_plugins.changed_creation_date.os.chdir") @patch("troubadix.standalone_plugins.changed_creation_date.git") - def test_main_check_creation_date_fail( - self, mock_git, _, mock_check_creation_date, __ - ): + def test_main_check_creation_date_fail(self, mock_git, _, mock_check_creation_date, __): mock_git.return_value = "test_directory" mock_check_creation_date.return_value = 2 diff --git a/tests/standalone_plugins/test_changed_oid.py b/tests/standalone_plugins/test_changed_oid.py index 12624e8c..381d8642 100644 --- a/tests/standalone_plugins/test_changed_oid.py +++ b/tests/standalone_plugins/test_changed_oid.py @@ -30,9 +30,7 @@ def testgit(tmpdir: Path, ok: bool = False) -> None: git("commit", "-m", "test") git("checkout", "-b", "test") if ok: - test_file.write_text( - 'script_oid("1.3.6.1.4.1.25623.1.0.100313");\ntest' - ) + test_file.write_text('script_oid("1.3.6.1.4.1.25623.1.0.100313");\ntest') else: test_file.write_text('script_oid("2.3.6.1.4.1.25623.1.0.100313");') git("add", "-u") @@ -62,9 +60,7 @@ def test_git_ok(self): def test_args_ok(self): with temporary_git_directory() as tmpdir: testgit(tmpdir) - self.assertEqual( - parse_args(["-c", "main..test"]).commit_range, "main..test" - ) + self.assertEqual(parse_args(["-c", "main..test"]).commit_range, "main..test") self.assertEqual( parse_args(["-c", "main..test", "-f", "test.nasl"]).files, [Path("test.nasl")], diff --git a/tests/standalone_plugins/test_deprecate_vts.py b/tests/standalone_plugins/test_deprecate_vts.py index 0f65a642..f34b0699 100644 --- a/tests/standalone_plugins/test_deprecate_vts.py +++ b/tests/standalone_plugins/test_deprecate_vts.py @@ -222,8 +222,7 @@ def test_deprecate_kb_item(self): ] deprecate(out_dir, to_deprecate, "NOTUS") self.assertLogs( - "Unable to deprecate testfile1.nasl. There are still KB keys " - "remaining." + "Unable to deprecate testfile1.nasl. There are still KB keys " "remaining." ) def test_get_summary(self): diff --git a/tests/standalone_plugins/test_file_extensions.py b/tests/standalone_plugins/test_file_extensions.py index 26419284..cb1bab7c 100644 --- a/tests/standalone_plugins/test_file_extensions.py +++ b/tests/standalone_plugins/test_file_extensions.py @@ -110,9 +110,7 @@ def test_parse_args_ok(self): args = parse_args() self.assertTrue(args) self.assertEqual(args.dir, Path(tmpdir)) - self.assertEqual( - args.ignore_file, Path(tmpdir, "file_extensions.ignore") - ) + self.assertEqual(args.ignore_file, Path(tmpdir, "file_extensions.ignore")) def test_parse_args_no_dir(self): test_args = ["prog", "not_real_dir"] diff --git a/tests/standalone_plugins/test_version_updated.py b/tests/standalone_plugins/test_version_updated.py index 32da3552..b787ce4a 100644 --- a/tests/standalone_plugins/test_version_updated.py +++ b/tests/standalone_plugins/test_version_updated.py @@ -115,44 +115,28 @@ def test_change_nothing(self): setupgit(tmpdir) change_nothing(tmpdir) parsed_args = parse_args(["-c", "HEAD~1"]) - self.assertFalse( - check_version_updated( - parsed_args.files, parsed_args.commit_range - ) - ) + self.assertFalse(check_version_updated(parsed_args.files, parsed_args.commit_range)) def test_change_version(self): with tempgitdir() as tmpdir: setupgit(tmpdir) change_version(tmpdir) parsed_args = parse_args(["-c", "HEAD~1"]) - self.assertFalse( - check_version_updated( - parsed_args.files, parsed_args.commit_range - ) - ) + self.assertFalse(check_version_updated(parsed_args.files, parsed_args.commit_range)) def test_change_last_modification(self): with tempgitdir() as tmpdir: setupgit(tmpdir) change_last_modification(tmpdir) parsed_args = parse_args(["-c", "HEAD~1"]) - self.assertFalse( - check_version_updated( - parsed_args.files, parsed_args.commit_range - ) - ) + self.assertFalse(check_version_updated(parsed_args.files, parsed_args.commit_range)) def test_change_both(self): with tempgitdir() as tmpdir: setupgit(tmpdir) change_version_and_last_modification(tmpdir) parsed_args = parse_args(["-c", "HEAD~1"]) - self.assertTrue( - check_version_updated( - parsed_args.files, parsed_args.commit_range - ) - ) + self.assertTrue(check_version_updated(parsed_args.files, parsed_args.commit_range)) def test_git_fail(self): with self.assertRaises(SubprocessError): diff --git a/tests/test_argparser.py b/tests/test_argparser.py index 079e763a..92caa5b4 100644 --- a/tests/test_argparser.py +++ b/tests/test_argparser.py @@ -68,9 +68,7 @@ def test_parse_exclude_tests(self): self.assertIsNone(parsed_args.included_plugins) def test_parse_include_patterns(self): - parsed_args = parse_args( - self.terminal, ["-f", "--include-patterns", "troubadix/*"] - ) + parsed_args = parse_args(self.terminal, ["-f", "--include-patterns", "troubadix/*"]) self.assertTrue(parsed_args.full) self.assertEqual(parsed_args.include_patterns, ["troubadix/*"]) @@ -92,9 +90,7 @@ def test_parse_files_non_recursive_fail(self): ) def test_parse_exclude_patterns(self): - parsed_args = parse_args( - self.terminal, ["-f", "--exclude-patterns", "troubadix/*"] - ) + parsed_args = parse_args(self.terminal, ["-f", "--exclude-patterns", "troubadix/*"]) self.assertTrue(parsed_args.full) self.assertEqual(parsed_args.exclude_patterns, ["troubadix/*"]) diff --git a/tests/test_helper.py b/tests/test_helper.py index 88afb364..fb79751b 100644 --- a/tests/test_helper.py +++ b/tests/test_helper.py @@ -73,24 +73,16 @@ def test_get_root(self): class GetPathFromRootTestCase(unittest.TestCase): def test_get_path_from_root_relative(self): - self.assertEqual( - get_path_from_root(Path("nasl/foo"), Path("nasl/foo")), Path(".") - ) - self.assertEqual( - get_path_from_root(Path("nasl/foo"), Path("nasl")), Path("foo") - ) + self.assertEqual(get_path_from_root(Path("nasl/foo"), Path("nasl/foo")), Path(".")) + self.assertEqual(get_path_from_root(Path("nasl/foo"), Path("nasl")), Path("foo")) self.assertEqual( get_path_from_root(Path("nasl/foo/bar"), Path("nasl")), Path("foo/bar"), ) def test_get_path_from_root_absolute(self): - self.assertEqual( - get_path_from_root(Path("/nasl/foo"), Path("/nasl/foo")), Path(".") - ) - self.assertEqual( - get_path_from_root(Path("/nasl/foo"), Path("/nasl")), Path("foo") - ) + self.assertEqual(get_path_from_root(Path("/nasl/foo"), Path("/nasl/foo")), Path(".")) + self.assertEqual(get_path_from_root(Path("/nasl/foo"), Path("/nasl")), Path("foo")) self.assertEqual( get_path_from_root(Path("/nasl/foo/bar"), Path("/nasl")), Path("foo/bar"), diff --git a/tests/test_reporter.py b/tests/test_reporter.py index bad36101..58435c02 100644 --- a/tests/test_reporter.py +++ b/tests/test_reporter.py @@ -59,9 +59,7 @@ def test_report_statistic(self): self.assertIn(f"{'sum':48} {0:8} {0:8}", output) def test_report_statistic_with_fix_and_ignore_warnings(self): - reporter = Reporter( - root=self.root, term=self._term, fix=True, ignore_warnings=True - ) + reporter = Reporter(root=self.root, term=self._term, fix=True, ignore_warnings=True) with redirect_stdout(io.StringIO()) as f: reporter.report_statistic() @@ -87,9 +85,7 @@ def test_report_statistic_with_fix(self): self.assertIn(f"{'sum':48} {0:8} {0:8} {0:8}", output) def test_report_statistic_with_ignore_warnings(self): - reporter = Reporter( - root=self.root, term=self._term, ignore_warnings=True - ) + reporter = Reporter(root=self.root, term=self._term, ignore_warnings=True) with redirect_stdout(io.StringIO()) as f: reporter.report_statistic() diff --git a/tests/test_results.py b/tests/test_results.py index 1a902e92..207a093c 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -34,45 +34,29 @@ def test_has_results(self): fresults = FileResults(file_path=Path("some/file.nasl")) fresults.add_plugin_results( plugin_name="test", - results=[ - LinterError("test", file=Path("some/file.nasl"), plugin="test") - ], + results=[LinterError("test", file=Path("some/file.nasl"), plugin="test")], ) self.assertTrue(fresults) def test_has_results_ok_no_warning(self): - fresults = FileResults( - file_path=Path("some/file.nasl"), ignore_warnings=True - ) + fresults = FileResults(file_path=Path("some/file.nasl"), ignore_warnings=True) fresults.add_plugin_results( plugin_name="test", - results=[ - LinterWarning( - "test", file=Path("some/file.nasl"), plugin="test" - ) - ], + results=[LinterWarning("test", file=Path("some/file.nasl"), plugin="test")], ) self.assertFalse(fresults) def test_has_results_no_warning(self): - fresults = FileResults( - file_path=Path("some/file.nasl"), ignore_warnings=True - ) + fresults = FileResults(file_path=Path("some/file.nasl"), ignore_warnings=True) fresults.add_plugin_results( plugin_name="test", - results=[ - LinterWarning( - "test", file=Path("some/file.nasl"), plugin="test" - ) - ], + results=[LinterWarning("test", file=Path("some/file.nasl"), plugin="test")], ) fresults.add_plugin_results( plugin_name="test", - results=[ - LinterError("test", file=Path("some/file.nasl"), plugin="test") - ], + results=[LinterError("test", file=Path("some/file.nasl"), plugin="test")], ) self.assertTrue(fresults) diff --git a/tests/test_runner.py b/tests/test_runner.py index 5a242536..fa87147a 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -97,13 +97,7 @@ def test_runner_with_included_plugins(self): def test_runner_run_ok(self): nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "test_valid_oid.nasl" + _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "test_valid_oid.nasl" ) included_plugins = [ CheckMissingDescExit.name, @@ -122,34 +116,20 @@ def test_runner_run_ok(self): self.assertEqual(self._reporter._result_counts.warning_count, 0) self.assertEqual(self._reporter._result_counts.fix_count, 0) self.assertEqual( - self._reporter._result_counts.result_counts[ - CheckMissingDescExit.name - ]["error"], + self._reporter._result_counts.result_counts[CheckMissingDescExit.name]["error"], 0, ) self.assertEqual( - self._reporter._result_counts.result_counts[ - CheckMissingDescExit.name - ]["warning"], + self._reporter._result_counts.result_counts[CheckMissingDescExit.name]["warning"], 0, ) self.assertEqual( - self._reporter._result_counts.result_counts[ - CheckMissingDescExit.name - ]["fix"], + self._reporter._result_counts.result_counts[CheckMissingDescExit.name]["fix"], 0, ) def test_runner_run_error(self): - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "fail.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "fail.nasl" included_plugins = [CheckCVSSFormat.name, CheckCopyrightText.name] runner = Runner( n_jobs=1, @@ -167,34 +147,20 @@ def test_runner_run_error(self): self.assertEqual(self._reporter._result_counts.warning_count, 0) self.assertEqual(self._reporter._result_counts.fix_count, 0) self.assertEqual( - self._reporter._result_counts.result_counts[CheckCVSSFormat.name][ - "error" - ], + self._reporter._result_counts.result_counts[CheckCVSSFormat.name]["error"], 2, ) self.assertEqual( - self._reporter._result_counts.result_counts[CheckCVSSFormat.name][ - "warning" - ], + self._reporter._result_counts.result_counts[CheckCVSSFormat.name]["warning"], 0, ) self.assertEqual( - self._reporter._result_counts.result_counts[CheckCVSSFormat.name][ - "fix" - ], + self._reporter._result_counts.result_counts[CheckCVSSFormat.name]["fix"], 0, ) def test_runner_run_fail_with_verbose_level_2(self): - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "fail.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "fail.nasl" content = nasl_file.read_text(encoding=CURRENT_ENCODING) reporter = Reporter(term=self._term, root=self.root, verbose=2) @@ -218,8 +184,7 @@ def test_runner_run_fail_with_verbose_level_2(self): output, ) self.assertIn( - "Results for plugin " - "check_script_version_and_last_modification_tags", + "Results for plugin " "check_script_version_and_last_modification_tags", output, ) # CI terminal formats for 80 chars per line @@ -232,15 +197,7 @@ def test_runner_run_ok_with_verbose_level_3(self): included_plugins = [ "CheckMissingDescExit", ] - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "test.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "test.nasl" content = nasl_file.read_text(encoding=CURRENT_ENCODING) reporter = Reporter(term=self._term, root=self.root, verbose=3) @@ -259,24 +216,14 @@ def test_runner_run_ok_with_verbose_level_3(self): self.assertEqual(content, new_content) output = f.getvalue() - self.assertIn( - f"Checking {get_path_from_root(nasl_file, self.root)}", output - ) + self.assertIn(f"Checking {get_path_from_root(nasl_file, self.root)}", output) self.assertIn("No results for plugin check_missing_desc_exit", output) def test_runner_run_ok_with_verbose_level_2(self): included_plugins = [ "CheckMissingDescExit", ] - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "test.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "test.nasl" content = nasl_file.read_text(encoding=CURRENT_ENCODING) reporter = Reporter(term=self._term, root=self.root, verbose=2) @@ -299,23 +246,13 @@ def test_runner_run_ok_with_verbose_level_2(self): "Checking " f"{get_path_from_root(nasl_file, self.root)}", output, ) - self.assertNotIn( - "No results for plugin check_missing_desc_exit", output - ) + self.assertNotIn("No results for plugin check_missing_desc_exit", output) def test_runner_run_ok_with_verbose_level_1(self): included_plugins = [ "CheckMissingDescExit", ] - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "test.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "test.nasl" content = nasl_file.read_text(encoding=CURRENT_ENCODING) reporter = Reporter(term=self._term, root=self.root, verbose=1) @@ -334,9 +271,7 @@ def test_runner_run_ok_with_verbose_level_1(self): self.assertEqual(content, new_content) output = f.getvalue() - self.assertNotIn( - "No results for plugin check_missing_desc_exit", output - ) + self.assertNotIn("No results for plugin check_missing_desc_exit", output) self.assertNotIn("Results for plugin check_missing_desc_exit", output) # revert changes for the next time @@ -368,20 +303,10 @@ def test_runner_log_file(self): CheckDuplicateOID.name, CheckMissingDescExit.name, ] - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "test.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "test.nasl" gen_log_file = _here / "gen_log.txt" - reporter = Reporter( - term=self._term, root=self.root, verbose=3, log_file=gen_log_file - ) + reporter = Reporter(term=self._term, root=self.root, verbose=3, log_file=gen_log_file) runner = Runner( reporter=reporter, @@ -415,20 +340,10 @@ def test_runner_log_file_fail(self): included_plugins = [ "CheckMissingDescExit", ] - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "test.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "test.nasl" gen_log_file = _here / "gen_log.txt" - reporter = Reporter( - term=self._term, root=self.root, log_file=gen_log_file - ) + reporter = Reporter(term=self._term, root=self.root, log_file=gen_log_file) runner = Runner( n_jobs=1, @@ -513,15 +428,7 @@ def test_runner_log_file_statistic(self): CheckDuplicateOID.name, CheckMissingDescExit.name, ] - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "test.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "test.nasl" gen_log_file = _here / "gen_log.txt" reporter = Reporter( @@ -558,15 +465,7 @@ def test_runner_fail_log_file_statistic(self): CheckDuplicateOID.name, CheckMissingDescExit.name, ] - nasl_file = ( - _here - / "plugins" - / "test_files" - / "nasl" - / "21.04" - / "runner" - / "test.nasl" - ) + nasl_file = _here / "plugins" / "test_files" / "nasl" / "21.04" / "runner" / "test.nasl" gen_log_file = _here / "gen_log.txt" reporter = Reporter( diff --git a/troubadix/argparser.py b/troubadix/argparser.py index e7bc7f52..604b562b 100644 --- a/troubadix/argparser.py +++ b/troubadix/argparser.py @@ -98,9 +98,7 @@ def parse_args( "-f", "--full", action="store_true", - help=( - "Checking the complete VT directory and not only the added/changed scripts" - ), + help=("Checking the complete VT directory and not only the added/changed scripts"), ) parser.add_argument( @@ -167,9 +165,7 @@ def parse_args( parser.add_argument( "--non-recursive", action="store_true", - help=( - 'Don\'t run the script recursive. Only usable with "-f"/"--full" or "-d"/"--dirs"' - ), + help=('Don\'t run the script recursive. Only usable with "-f"/"--full" or "-d"/"--dirs"'), ) parser.add_argument( @@ -233,9 +229,7 @@ def parse_args( dest="n_jobs", default=max(1, cpu_count() // 2), type=check_cpu_count, - help=( - "Define number of jobs, that should run simultaneously. Default: %(default)s" - ), + help=("Define number of jobs, that should run simultaneously. Default: %(default)s"), ) parser.add_argument( @@ -262,11 +256,7 @@ def parse_args( ) sys.exit(1) - if ( - not parsed_args.full - and not parsed_args.dirs - and parsed_args.non_recursive - ): + if not parsed_args.full and not parsed_args.dirs and parsed_args.non_recursive: terminal.warning( "'Argument '--non-recursive' is only usable with '-f'/'--full' or '-d'/'--dirs'" ) diff --git a/troubadix/helper/date_format.py b/troubadix/helper/date_format.py index 9aac6a26..48bc4d24 100644 --- a/troubadix/helper/date_format.py +++ b/troubadix/helper/date_format.py @@ -11,9 +11,7 @@ def parse_date(date: str) -> datetime: return datetime.strptime(date[:25], "%Y-%m-%d %H:%M:%S %z") -def check_date( - date: str, date_name: str, file: str, plugin: str -) -> Iterator[LinterResult]: +def check_date(date: str, date_name: str, file: str, plugin: str) -> Iterator[LinterResult]: """ Checks if a given date string is correctly formatted. Example: "2017-11-29 13:56:41 +0100 (Wed, 29 Nov 2017)" @@ -58,8 +56,7 @@ def check_date( elif week_day_str != week_day_parsed: formatted_date = week_day_parsed yield LinterError( - f"Wrong day of week. Please change it from '{week_day_str}" - f"' to '{formatted_date}'.", + f"Wrong day of week. Please change it from '{week_day_str}" f"' to '{formatted_date}'.", file=file, plugin=plugin, ) @@ -79,8 +76,7 @@ def compare_date_with_last_modification_date( try: if parse_date(date) > parse_date(last_mod_date): yield LinterError( - f"The {date_name} must not be greater than " - "last_modification date.", + f"The {date_name} must not be greater than " "last_modification date.", file=file, plugin=plugin, ) diff --git a/troubadix/helper/helper.py b/troubadix/helper/helper.py index 890ad454..7445dc98 100644 --- a/troubadix/helper/helper.py +++ b/troubadix/helper/helper.py @@ -35,9 +35,7 @@ } -def is_ignore_file( - file_name: Union[Path, str], ignore_files: Union[List[Path], List[str]] -) -> bool: +def is_ignore_file(file_name: Union[Path, str], ignore_files: Union[List[Path], List[str]]) -> bool: for ignore_file in ignore_files: if str(ignore_file) in str(file_name): return True diff --git a/troubadix/helper/if_block_parser.py b/troubadix/helper/if_block_parser.py index 3998d9b0..7b02cc33 100644 --- a/troubadix/helper/if_block_parser.py +++ b/troubadix/helper/if_block_parser.py @@ -31,9 +31,7 @@ class IfStatement: class IfErrorType(Enum): UNCLOSED_CONDITION = "Unclosed parenthesis in if condition at line {line}" UNCLOSED_BODY = "Unclosed brace in if body at line {line}" - MISSING_OUTCOME = ( - "Missing statement or body after if condition at line {line}" - ) + MISSING_OUTCOME = "Missing statement or body after if condition at line {line}" TERMINATED_AFTER_CONDITION = ( "Semicolon after if condition at line {line} causes if to terminate early. " "Following block will always execute." @@ -85,18 +83,12 @@ def find_if_statements(self) -> IfParseResult: opening_brace, CONDITION_BRACES ) if condition_error: - errors.append( - IfParseError(line=line, error_type=condition_error) - ) + errors.append(IfParseError(line=line, error_type=condition_error)) continue - condition = self.file_content[ - opening_brace + 1 : condition_end - ].strip() + condition = self.file_content[opening_brace + 1 : condition_end].strip() # Step 3: Find the start of the outcome (first non-whitespace after condition) - outcome_start, outcome_error = self._find_outcome_start( - condition_end - ) + outcome_start, outcome_error = self._find_outcome_start(condition_end) if outcome_error: errors.append(IfParseError(line=line, error_type=outcome_error)) continue @@ -104,26 +96,18 @@ def find_if_statements(self) -> IfParseResult: # Step 4: Determine if this is a body or single-expression statement if self.file_content[outcome_start] == "{": # Body: find closing brace for body '}' - body_end, body_error = self._find_closing_brace( - outcome_start, BODY_BRACES - ) + body_end, body_error = self._find_closing_brace(outcome_start, BODY_BRACES) if body_error: - errors.append( - IfParseError(line=line, error_type=body_error) - ) + errors.append(IfParseError(line=line, error_type=body_error)) continue if_end = body_end + 1 outcome_start = outcome_start + 1 # exclude opening brace outcome_end = body_end else: # Single statement: find end of statement ';' - statement_end, statement_error = self._find_statement_end( - outcome_start - ) + statement_end, statement_error = self._find_statement_end(outcome_start) if statement_error: - errors.append( - IfParseError(line=line, error_type=statement_error) - ) + errors.append(IfParseError(line=line, error_type=statement_error)) continue if_end = statement_end + 1 outcome_end = statement_end @@ -194,15 +178,12 @@ def _find_condition_starts(self) -> list[tuple[int, int]]: continue # check for if with word boundary, valid: ["if", " if"], not valid: "xif" - if ( - i == 0 or not self.file_content[i - 1].isalnum() - ) and self.file_content.startswith("if", i): + if (i == 0 or not self.file_content[i - 1].isalnum()) and self.file_content.startswith( + "if", i + ): # skip whitespace j = i + 2 - while ( - j < len(self.file_content) - and self.file_content[j].isspace() - ): + while j < len(self.file_content) and self.file_content[j].isspace(): j += 1 # check for condition start if j < len(self.file_content) and self.file_content[j] == "(": @@ -210,9 +191,7 @@ def _find_condition_starts(self) -> list[tuple[int, int]]: return starts - def _find_outcome_start( - self, condition_end: int - ) -> tuple[int | None, IfErrorType | None]: + def _find_outcome_start(self, condition_end: int) -> tuple[int | None, IfErrorType | None]: """ Find the start of the outcome/then part after the condition (next non-whitespace character). """ @@ -228,9 +207,7 @@ def _find_outcome_start( return pos, None - def _find_statement_end( - self, statement_start: int - ) -> tuple[int | None, IfErrorType | None]: + def _find_statement_end(self, statement_start: int) -> tuple[int | None, IfErrorType | None]: """Find the end of a single statement (semicolon outside of strings).""" string_state = StringState() diff --git a/troubadix/helper/linguistic_exception_handler.py b/troubadix/helper/linguistic_exception_handler.py index 7cedff98..2ff41421 100644 --- a/troubadix/helper/linguistic_exception_handler.py +++ b/troubadix/helper/linguistic_exception_handler.py @@ -90,16 +90,12 @@ def __init__( # but that throws an exception because Tuple[...] # is only valid for type hinting :/ if isinstance(patterns[0], Tuple): - self.patterns = [ - re.compile(pattern, flags=flags) for pattern, flags in patterns - ] + self.patterns = [re.compile(pattern, flags=flags) for pattern, flags in patterns] else: self.patterns = [re.compile(pattern) for pattern in patterns] def execute(self, file_path: str, correction: str): - return any( - bool(pattern.search(correction)) for pattern in self.patterns - ) + return any(bool(pattern.search(correction)) for pattern in self.patterns) class CompositeCheck(LinguisticCheck): @@ -112,9 +108,7 @@ def __init__(self, *checks: Iterable[LinguisticCheck]) -> None: self.checks = checks def execute(self, file_path: str, correction: str): - return all( - check.execute(file_path, correction) for check in self.checks - ) + return all(check.execute(file_path, correction) for check in self.checks) class TextInFileCheck(CompositeCheck): @@ -131,9 +125,7 @@ class PatternInFileCheck(CompositeCheck): and the file contains the specified file path """ - def __init__( - self, file: str, pattern: str, flags: re.RegexFlag = 0 - ) -> None: + def __init__(self, file: str, pattern: str, flags: re.RegexFlag = 0) -> None: super().__init__(FileCheck(file), PatternCheck(pattern, flags)) @@ -155,9 +147,7 @@ class PatternInFilesCheck(CompositeCheck): and the file matches any of the specified file paths """ - def __init__( - self, files: List[str], pattern: str, flags: re.RegexFlag = 0 - ) -> None: + def __init__(self, files: List[str], pattern: str, flags: re.RegexFlag = 0) -> None: super().__init__(FilesCheck(files), PatternCheck(pattern, flags)) @@ -196,9 +186,7 @@ def __init__( ) -def handle_linguistic_checks( - file: str, correction: str, checks: Iterable[LinguisticCheck] -) -> bool: +def handle_linguistic_checks(file: str, correction: str, checks: Iterable[LinguisticCheck]) -> bool: """Determinates if any of the provided checks pass for the provided file and correction diff --git a/troubadix/helper/patterns.py b/troubadix/helper/patterns.py index 3f06e80d..bc515125 100644 --- a/troubadix/helper/patterns.py +++ b/troubadix/helper/patterns.py @@ -42,9 +42,7 @@ ) -def _get_tag_pattern( - name: str, *, value: str = r".+?", flags: re.RegexFlag = 0 -) -> re.Pattern: +def _get_tag_pattern(name: str, *, value: str = r".+?", flags: re.RegexFlag = 0) -> re.Pattern: """ The returned pattern catches all `script_tags(name="{name}", value="{value}");` @@ -89,8 +87,7 @@ class ScriptTag(Enum): __DATE_VALUE = r"[A-Za-z0-9\:\-\+\,\s\(\)]{44}" __CVSS_V2_BASE_VECTOR = r"AV:[LAN]/AC:[HML]/Au:[NSM]/C:[NPC]/I:[NPC]/A:[NPC]" __CVSS_V3_BASE_VECTOR = ( - r"CVSS:3.[01]/AV:[NALP]/AC:[LH]/PR:[NLH]/UI:[NR]/S:[UC]" - r"/C:[HLN]/I:[HLN]/A:[HLN]" + r"CVSS:3.[01]/AV:[NALP]/AC:[LH]/PR:[NLH]/UI:[NR]/S:[UC]" r"/C:[HLN]/I:[HLN]/A:[HLN]" ) __CVSS_V4_BASE_VECTOR = ( r"CVSS:4.0/AV:[NALP]/AC:[LH]/AT:[NP]/PR:[NLH]/UI:[NPA]" @@ -102,9 +99,7 @@ class ScriptTag(Enum): ScriptTag.CVSS_BASE: r"(10\.0|[0-9]\.[0-9])", ScriptTag.CVSS_BASE_VECTOR: __CVSS_V2_BASE_VECTOR, ScriptTag.SEVERITY_VECTOR: ( - rf"({__CVSS_V2_BASE_VECTOR})|" - rf"({__CVSS_V3_BASE_VECTOR})|" - rf"({__CVSS_V4_BASE_VECTOR})" + rf"({__CVSS_V2_BASE_VECTOR})|" rf"({__CVSS_V3_BASE_VECTOR})|" rf"({__CVSS_V4_BASE_VECTOR})" ), ScriptTag.SEVERITY_ORIGIN: r"(NVD|Vendor|Third Party|Greenbone)", ScriptTag.SEVERITY_DATE: __DATE_VALUE, @@ -127,9 +122,7 @@ def init_script_tag_patterns() -> None: value = r".+?" flags = re.MULTILINE | re.DOTALL - __script_tag_pattern[tag] = _get_tag_pattern( - name=tag.value, value=value, flags=flags - ) + __script_tag_pattern[tag] = _get_tag_pattern(name=tag.value, value=value, flags=flags) def get_script_tag_patterns() -> Dict[ScriptTag, re.Pattern]: @@ -162,9 +155,7 @@ def get_script_tag_pattern(script_tag: ScriptTag) -> re.Pattern: ) -def get_xref_pattern( - name: str, *, value: str = r".+?", flags: re.RegexFlag = 0 -) -> re.Pattern: +def get_xref_pattern(name: str, *, value: str = r".+?", flags: re.RegexFlag = 0) -> re.Pattern: """ The returned pattern catches all `script_xref(name="{name}", value="{value}");` @@ -186,8 +177,7 @@ def get_xref_pattern( _SPECIAL_TAG_PATTERN = ( - r'script_(?P{name})\s*\((?P[\'"])?(?P{value})' - r"(?P=quote99)?\s*\)\s*;" + r'script_(?P{name})\s*\((?P[\'"])?(?P{value})' r"(?P=quote99)?\s*\)\s*;" ) @@ -228,9 +218,7 @@ def _get_special_script_tag_pattern( Returns `re.Pattern` object """ - return re.compile( - _SPECIAL_TAG_PATTERN.format(name=name, value=value), flags=flags - ) + return re.compile(_SPECIAL_TAG_PATTERN.format(name=name, value=value), flags=flags) __PORT_VALUE = r"\"(?P[\w\s])+\", (?P\d{1,5})" diff --git a/troubadix/helper/remove_comments.py b/troubadix/helper/remove_comments.py index 3de7d3e0..7a13f595 100644 --- a/troubadix/helper/remove_comments.py +++ b/troubadix/helper/remove_comments.py @@ -20,10 +20,7 @@ def remove_comments(file_content: str) -> str: """ string_state = StringState() return "\n".join( - [ - _remove_comments_in_line(line, string_state) - for line in file_content.splitlines() - ] + [_remove_comments_in_line(line, string_state) for line in file_content.splitlines()] ) diff --git a/troubadix/helper/text_utils.py b/troubadix/helper/text_utils.py index 040180d5..f8654238 100644 --- a/troubadix/helper/text_utils.py +++ b/troubadix/helper/text_utils.py @@ -55,9 +55,7 @@ def index_to_linecol(text: str, index: int) -> tuple[int, int]: (line, column) tuple (both start at 1) """ if index < 0 or index >= len(text): - raise ValueError( - f"Index {index} out of bounds for text of length {len(text)}" - ) + raise ValueError(f"Index {index} out of bounds for text of length {len(text)}") lines = text.splitlines(keepends=True) line_num = 0 diff --git a/troubadix/plugin.py b/troubadix/plugin.py index ed624a57..3a9386c4 100644 --- a/troubadix/plugin.py +++ b/troubadix/plugin.py @@ -62,9 +62,7 @@ def __init__( @property def file_content(self) -> str: if not self._file_content: - self._file_content = self.nasl_file.read_text( - encoding=CURRENT_ENCODING - ) + self._file_content = self.nasl_file.read_text(encoding=CURRENT_ENCODING) return self._file_content @property @@ -111,14 +109,10 @@ class FileContentPlugin(FilePlugin): """A plugin that does checks on the whole file content""" def run(self) -> Iterator[LinterResult]: - return self.check_content( - self.context.nasl_file, self.context.file_content - ) + return self.check_content(self.context.nasl_file, self.context.file_content) @abstractmethod - def check_content( - self, nasl_file: Path, file_content: str - ) -> Iterator[LinterResult]: + def check_content(self, nasl_file: Path, file_content: str) -> Iterator[LinterResult]: pass diff --git a/troubadix/plugins/__init__.py b/troubadix/plugins/__init__.py index dc5001c6..44330a01 100644 --- a/troubadix/plugins/__init__.py +++ b/troubadix/plugins/__init__.py @@ -191,24 +191,18 @@ def __init__( self._check_unknown_plugins(excluded_plugins) file_plugins = self._exclude_plugins(excluded_plugins, file_plugins) - files_plugins = self._exclude_plugins( - excluded_plugins, files_plugins - ) + files_plugins = self._exclude_plugins(excluded_plugins, files_plugins) if included_plugins: self._check_unknown_plugins(included_plugins) file_plugins = self._include_plugins(included_plugins, file_plugins) - files_plugins = self._include_plugins( - included_plugins, files_plugins - ) + files_plugins = self._include_plugins(included_plugins, files_plugins) super().__init__(file_plugins=file_plugins, files_plugins=files_plugins) @staticmethod - def _exclude_plugins( - excluded: Iterable[str], plugins: Iterable[Plugin] - ) -> List[Plugin]: + def _exclude_plugins(excluded: Iterable[str], plugins: Iterable[Plugin]) -> List[Plugin]: return [ plugin for plugin in plugins @@ -216,13 +210,9 @@ def _exclude_plugins( ] @staticmethod - def _include_plugins( - included: Iterable[str], plugins: Iterable[Plugin] - ) -> List[Plugin]: + def _include_plugins(included: Iterable[str], plugins: Iterable[Plugin]) -> List[Plugin]: return [ - plugin - for plugin in plugins - if plugin.__name__ in included or plugin.name in included + plugin for plugin in plugins if plugin.__name__ in included or plugin.name in included ] @staticmethod @@ -240,11 +230,7 @@ def _check_unknown_plugins(selected_plugins: list[str]): def build_message(plugin: str): match = difflib.get_close_matches(plugin, all_plugin_names, n=1) - return ( - f"'{plugin}' (Did you mean '{match[0]}'?)" - if match - else f"'{plugin}'" - ) + return f"'{plugin}' (Did you mean '{match[0]}'?)" if match else f"'{plugin}'" messages = [build_message(plugin) for plugin in sorted(unknown_plugins)] raise ValueError(f"Unknown plugins: {', '.join(messages)}") diff --git a/troubadix/plugins/badwords.py b/troubadix/plugins/badwords.py index fee21f71..08c4282e 100644 --- a/troubadix/plugins/badwords.py +++ b/troubadix/plugins/badwords.py @@ -140,20 +140,14 @@ def check_lines( if any(badword in line for badword in DEFAULT_BADWORDS): if ( not any(exception in line for exception in EXCEPTIONS) + and not any(line.startswith(start) for start in STARTS_WITH_EXCEPTIONS) and not any( - line.startswith(start) - for start in STARTS_WITH_EXCEPTIONS - ) - and not any( - nasl_file.name == filename and value in line - for filename, value in COMBINED + nasl_file.name == filename and value in line for filename, value in COMBINED ) ): report = f"Badword in line {i:5}: {line}" if "NVT" in line: - report += ( - '\nNote/Hint: Please use the term "VT" instead.' - ) + report += '\nNote/Hint: Please use the term "VT" instead.' yield LinterError( report, plugin=self.name, diff --git a/troubadix/plugins/copyright_text.py b/troubadix/plugins/copyright_text.py index 23344f58..83929514 100644 --- a/troubadix/plugins/copyright_text.py +++ b/troubadix/plugins/copyright_text.py @@ -98,13 +98,10 @@ def fix(self) -> Iterator[LinterResult]: return nasl_file = self.context.nasl_file - nasl_file.write_text( - data=self.new_file_content, encoding=CURRENT_ENCODING - ) + nasl_file.write_text(data=self.new_file_content, encoding=CURRENT_ENCODING) yield LinterFix( - f"The copyright statement has been updated to " - f"{CORRECT_COPYRIGHT_PHRASE}", + f"The copyright statement has been updated to " f"{CORRECT_COPYRIGHT_PHRASE}", file=nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/copyright_year.py b/troubadix/plugins/copyright_year.py index c5a4328a..9563efb7 100644 --- a/troubadix/plugins/copyright_year.py +++ b/troubadix/plugins/copyright_year.py @@ -59,12 +59,8 @@ class CheckCopyrightYear(FileContentPlugin): name = "check_copyright_year" - def check_content( - self, nasl_file: Path, file_content: str - ) -> Iterator[LinterResult]: - if nasl_file.suffix == ".inc" or is_ignore_file( - nasl_file, _IGNORE_FILES - ): + def check_content(self, nasl_file: Path, file_content: str) -> Iterator[LinterResult]: + if nasl_file.suffix == ".inc" or is_ignore_file(nasl_file, _IGNORE_FILES): return # extract creation year from script tag creation_date_pattern = get_script_tag_pattern(ScriptTag.CREATION_DATE) @@ -79,9 +75,7 @@ def check_content( creation_year = int(creation_date_match.group("value")[:4]) # extract year in value of script_copyright tag - script_copyright_pattern = get_special_script_tag_pattern( - SpecialScriptTag.COPYRIGHT - ) + script_copyright_pattern = get_special_script_tag_pattern(SpecialScriptTag.COPYRIGHT) script_copyright_match = script_copyright_pattern.search(file_content) if not script_copyright_match: yield LinterError( @@ -91,9 +85,7 @@ def check_content( ) return copyright_tag_value = script_copyright_match.group("value") - copyright_tag_match = SPDX_OR_COPYRIGHT_PATTERN.search( - copyright_tag_value - ) + copyright_tag_match = SPDX_OR_COPYRIGHT_PATTERN.search(copyright_tag_value) if not copyright_tag_match: yield LinterError( "Unable to extract year from script_copyright tag in VT", diff --git a/troubadix/plugins/creation_date.py b/troubadix/plugins/creation_date.py index 7a9db790..ad8aba21 100644 --- a/troubadix/plugins/creation_date.py +++ b/troubadix/plugins/creation_date.py @@ -41,13 +41,9 @@ def check_content( return creation_date_pattern = get_script_tag_pattern(ScriptTag.CREATION_DATE) - last_modification_pattern = get_script_tag_pattern( - ScriptTag.LAST_MODIFICATION - ) + last_modification_pattern = get_script_tag_pattern(ScriptTag.LAST_MODIFICATION) - if not ( - match_creation_date := creation_date_pattern.search(file_content) - ): + if not (match_creation_date := creation_date_pattern.search(file_content)): yield LinterError( "No creation_date has been found.", file=nasl_file, @@ -62,9 +58,7 @@ def check_content( self.name, ) - if match_last_mod_date := last_modification_pattern.search( - file_content - ): + if match_last_mod_date := last_modification_pattern.search(file_content): yield from compare_date_with_last_modification_date( match_creation_date.group("value"), "creation_date", diff --git a/troubadix/plugins/cvss_format.py b/troubadix/plugins/cvss_format.py index 5e21a94d..9a8a0cfc 100644 --- a/troubadix/plugins/cvss_format.py +++ b/troubadix/plugins/cvss_format.py @@ -37,9 +37,7 @@ def check_content( return cvss_base_pattern = get_script_tag_pattern(ScriptTag.CVSS_BASE) - cvss_base_vector_pattern = get_script_tag_pattern( - ScriptTag.CVSS_BASE_VECTOR - ) + cvss_base_vector_pattern = get_script_tag_pattern(ScriptTag.CVSS_BASE_VECTOR) if not cvss_base_pattern.search(file_content): yield LinterError( diff --git a/troubadix/plugins/dependencies.py b/troubadix/plugins/dependencies.py index 0a34ce5f..3bb64526 100644 --- a/troubadix/plugins/dependencies.py +++ b/troubadix/plugins/dependencies.py @@ -75,12 +75,9 @@ def run( for match in matches: if match: for dep in split_dependencies(match.group("value")): - if not any( - (root / vers / dep).exists() for vers in FEED_VERSIONS - ): + if not any((root / vers / dep).exists() for vers in FEED_VERSIONS): yield LinterError( - f"The script dependency {dep} could not " - "be found within the VTs.", + f"The script dependency {dep} could not " "be found within the VTs.", file=self.context.nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/dependency_category_order.py b/troubadix/plugins/dependency_category_order.py index 3f78a6be..1cd561c4 100644 --- a/troubadix/plugins/dependency_category_order.py +++ b/troubadix/plugins/dependency_category_order.py @@ -61,17 +61,13 @@ def check_category( match = pattern.search(content) if not match: - raise CategoryError( - f"{script}: Script category is missing or unsupported." - ) + raise CategoryError(f"{script}: Script category is missing or unsupported.") category_value = match.group("value") try: return VTCategory[category_value] except ValueError: - raise CategoryError( - f"{script}: Script category {category_value} is unsupported." - ) from None + raise CategoryError(f"{script}: Script category {category_value} is unsupported.") from None class CheckDependencyCategoryOrder(FileContentPlugin): @@ -98,9 +94,7 @@ def check_content( ): return - category_pattern = get_special_script_tag_pattern( - SpecialScriptTag.CATEGORY - ) + category_pattern = get_special_script_tag_pattern(SpecialScriptTag.CATEGORY) try: category = check_category( @@ -116,9 +110,7 @@ def check_content( ) return - dependencies_pattern = get_special_script_tag_pattern( - SpecialScriptTag.DEPENDENCIES - ) + dependencies_pattern = get_special_script_tag_pattern(SpecialScriptTag.DEPENDENCIES) matches = dependencies_pattern.finditer(file_content) if not matches: @@ -130,9 +122,7 @@ def check_content( if match: # Remove single and/or double quotes, spaces # and create a list by using the comma as a separator - dependencies = re.sub( - r'[\'"\s]', "", match.group("value") - ).split(",") + dependencies = re.sub(r'[\'"\s]', "", match.group("value")).split(",") for dep in dependencies: dependency_path = None @@ -142,15 +132,12 @@ def check_content( if not dependency_path: yield LinterError( - f"The script dependency {dep} could not " - "be found within the VTs.", + f"The script dependency {dep} could not " "be found within the VTs.", file=nasl_file, plugin=self.name, ) else: - dependency_content = dependency_path.read_text( - encoding=CURRENT_ENCODING - ) + dependency_content = dependency_path.read_text(encoding=CURRENT_ENCODING) try: dependency_category = check_category( diff --git a/troubadix/plugins/deprecated_dependency.py b/troubadix/plugins/deprecated_dependency.py index 26ee7ce4..0260eb59 100644 --- a/troubadix/plugins/deprecated_dependency.py +++ b/troubadix/plugins/deprecated_dependency.py @@ -47,9 +47,7 @@ def run(self) -> Iterator[LinterResult]: ): return - dependencies_pattern = get_special_script_tag_pattern( - SpecialScriptTag.DEPENDENCIES - ) + dependencies_pattern = get_special_script_tag_pattern(SpecialScriptTag.DEPENDENCIES) matches = dependencies_pattern.finditer(file_content) if not matches: return @@ -70,9 +68,7 @@ def run(self) -> Iterator[LinterResult]: if match: # Remove single and/or double quotes, spaces # and create a list by using the comma as a separator - dependencies = re.sub( - r'[\'"\s]', "", match.group("value") - ).split(",") + dependencies = re.sub(r'[\'"\s]', "", match.group("value")).split(",") for dep in dependencies: dependency_path = None @@ -82,23 +78,17 @@ def run(self) -> Iterator[LinterResult]: if not dependency_path: yield LinterError( - f"The script dependency {dep} could not " - "be found within the VTs.", + f"The script dependency {dep} could not " "be found within the VTs.", file=self.context.nasl_file, plugin=self.name, ) else: - dependency_content = dependency_path.read_text( - encoding=CURRENT_ENCODING - ) + dependency_content = dependency_path.read_text(encoding=CURRENT_ENCODING) - dependency_deprecated = deprecated_pattern.search( - dependency_content - ) + dependency_deprecated = deprecated_pattern.search(dependency_content) if dependency_deprecated: yield LinterError( - f"VT depends on {dep}, which is marked " - "as deprecated.", + f"VT depends on {dep}, which is marked " "as deprecated.", file=self.context.nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/deprecated_functions.py b/troubadix/plugins/deprecated_functions.py index 9a082139..b631db55 100644 --- a/troubadix/plugins/deprecated_functions.py +++ b/troubadix/plugins/deprecated_functions.py @@ -58,8 +58,7 @@ def run(self) -> Iterator[LinterResult]: for description, pattern in deprecated_functions.items(): if re.search(pattern, self.context.file_content, re.MULTILINE): yield LinterError( - "Found a deprecated function call / description item: " - f"{description}", + "Found a deprecated function call / description item: " f"{description}", file=self.context.nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/double_end_points.py b/troubadix/plugins/double_end_points.py index 7f8f18f9..890591d1 100644 --- a/troubadix/plugins/double_end_points.py +++ b/troubadix/plugins/double_end_points.py @@ -42,9 +42,7 @@ def run( if self.context.nasl_file.suffix == ".inc": return - tag_matches = get_common_tag_patterns().finditer( - self.context.file_content - ) + tag_matches = get_common_tag_patterns().finditer(self.context.file_content) if tag_matches is not None: for tag_match in tag_matches: @@ -56,10 +54,7 @@ def run( ) if doubled_end_points_match: # Valid string used in a few VTs. - if ( - 'and much more...");' - in doubled_end_points_match.group(0) - ): + if 'and much more...");' in doubled_end_points_match.group(0): continue yield LinterError( diff --git a/troubadix/plugins/duplicate_oid.py b/troubadix/plugins/duplicate_oid.py index bc05911a..7bcb86f0 100644 --- a/troubadix/plugins/duplicate_oid.py +++ b/troubadix/plugins/duplicate_oid.py @@ -50,9 +50,7 @@ def run(self) -> Iterator[LinterResult]: oid = None - match = get_special_script_tag_pattern(SpecialScriptTag.OID).search( - content - ) + match = get_special_script_tag_pattern(SpecialScriptTag.OID).search(content) if match: oid = match.group("oid") diff --git a/troubadix/plugins/forking_nasl_functions.py b/troubadix/plugins/forking_nasl_functions.py index b62bc6eb..c67df871 100644 --- a/troubadix/plugins/forking_nasl_functions.py +++ b/troubadix/plugins/forking_nasl_functions.py @@ -92,10 +92,7 @@ def check_content( return # This one is using if/else calls similar to the examples above. - if ( - "2011/zohocorp/gb_manageengine_adselfservice_plus_xss_vuln.nasl" - in str(nasl_file) - ): + if "2011/zohocorp/gb_manageengine_adselfservice_plus_xss_vuln.nasl" in str(nasl_file): return # Another example using if/else calls diff --git a/troubadix/plugins/get_kb_on_services.py b/troubadix/plugins/get_kb_on_services.py index 3b8ccc74..5be49183 100644 --- a/troubadix/plugins/get_kb_on_services.py +++ b/troubadix/plugins/get_kb_on_services.py @@ -54,8 +54,7 @@ def check_content( return kb_matches = re.finditer( - r'(get_kb_(?Pitem|list)\s*\(\s*(?P[\'"])(?P' - r"Services/[^)]+)\))", + r'(get_kb_(?Pitem|list)\s*\(\s*(?P[\'"])(?P' r"Services/[^)]+)\))", file_content, ) if kb_matches: @@ -71,8 +70,7 @@ def check_content( # access "Services/unknown" directly. # The same is valid for unknown_services.nasl as well. if "unknown_services.nasl" in str(nasl_file) or re.search( - r"find_service([0-9]+|_(" - r"3digits|spontaneous|nmap|nmap_wrapped))?\.nasl", + r"find_service([0-9]+|_(" r"3digits|spontaneous|nmap|nmap_wrapped))?\.nasl", str(nasl_file), ): continue diff --git a/troubadix/plugins/grammar.py b/troubadix/plugins/grammar.py index 24d3632a..2a124977 100644 --- a/troubadix/plugins/grammar.py +++ b/troubadix/plugins/grammar.py @@ -48,12 +48,8 @@ # catch this wrongly... # - Cases like "this filesystem" vs. "these filesystems" are also handled / # excluded here - PatternCheck( - r'this\s+(filesystem|allow\s+list)([\s.",]+|$)', re.IGNORECASE - ), - PatternCheck( - r'these\s+(filesystem|allow\s+list)s([\s.",]+|$)', re.IGNORECASE - ), + PatternCheck(r'this\s+(filesystem|allow\s+list)([\s.",]+|$)', re.IGNORECASE), + PatternCheck(r'these\s+(filesystem|allow\s+list)s([\s.",]+|$)', re.IGNORECASE), # Like seen in e.g. 2008/freebsd/freebsd_mod_php4-twig.nasl PatternCheck(r'(\s+|")[Aa]\s+multiple\s+of'), # WITH can be used like e.g. the following which is valid: @@ -61,9 +57,7 @@ # see e.g. gb_sles_2021_3215_1.nasl or gb_sles_2021_2320_1.nasl PatternCheck(r"with\s+WITH"), # Valid sentences - PatternCheck( - r"these\s+error\s+(messages|reports|conditions)", re.IGNORECASE - ), + PatternCheck(r"these\s+error\s+(messages|reports|conditions)", re.IGNORECASE), PatternCheck( r"these\s+file\s+(permissions|overwrites|names|includes|systems|formats)", re.IGNORECASE, @@ -71,8 +65,7 @@ # nb: Valid sentence TextInFileCheck( "2012/gb_VMSA-2010-0007.nasl", - "e. VMware VMnc Codec heap overflow vulnerabilities\n\n" - " Vulnerabilities in the", + "e. VMware VMnc Codec heap overflow vulnerabilities\n\n" " Vulnerabilities in the", ), TextInFileCheck("gb_opensuse_2018_1900_1.nasl", "(Note that"), # e.g.: @@ -142,8 +135,7 @@ def get_grammer_pattern() -> re.Pattern: r"links\s+mentioned\s+in(\s+the)?\s+reference|" r"\s+an?(\s+remote)?(\s+(un)?authenticated)?\s+attackers|" # e.g. "this flaws" - r"this\s+(vulnerabilities|(flaw|error|problem|issue|feature|file|" - r"request)s)|" + r"this\s+(vulnerabilities|(flaw|error|problem|issue|feature|file|" r"request)s)|" # e.g. "these flaw " r"these\s+(vulnerability|(flaw|error|problem|issue|feature|file|" r"request)\s+)|" @@ -234,9 +226,7 @@ def run(self) -> Iterator[LinterResult]: # more strict with e.g. leading or trailing newlines. full_line = match.group(0) - if handle_linguistic_checks( - str(self.context.nasl_file), full_line, exceptions - ): + if handle_linguistic_checks(str(self.context.nasl_file), full_line, exceptions): continue stripped_line = full_line.strip() diff --git a/troubadix/plugins/http_links_in_tags.py b/troubadix/plugins/http_links_in_tags.py index f76ef3b5..f90fefa7 100644 --- a/troubadix/plugins/http_links_in_tags.py +++ b/troubadix/plugins/http_links_in_tags.py @@ -180,6 +180,4 @@ def check_to_continue(http_link_match_group: AnyStr) -> bool: "http://target", ] - return any( - exclusion in http_link_match_group for exclusion in exclusions - ) + return any(exclusion in http_link_match_group for exclusion in exclusions) diff --git a/troubadix/plugins/illegal_characters.py b/troubadix/plugins/illegal_characters.py index 1c99ad35..15ff4376 100644 --- a/troubadix/plugins/illegal_characters.py +++ b/troubadix/plugins/illegal_characters.py @@ -55,9 +55,7 @@ def check_forbidden(match: re.match) -> List[str]: return [char for char in FORBIDDEN_CHARS if char in match.group("value")] -def fix_forbidden( - match: re.Match, found_forbidden_characters: List[str] -) -> str: +def fix_forbidden(match: re.Match, found_forbidden_characters: List[str]) -> str: """Returns the fixed version of the tag with the forbidden characters replaced @@ -100,13 +98,9 @@ def run(self) -> Iterator[LinterResult]: if match and match.group(0) is not None: found_forbidden_characters = check_forbidden(match) if found_forbidden_characters: - self.new_file_content = ( - self.context.file_content.replace( - match.group(0), - fix_forbidden( - match, found_forbidden_characters - ), - ) + self.new_file_content = self.context.file_content.replace( + match.group(0), + fix_forbidden(match, found_forbidden_characters), ) for forbidden_char in found_forbidden_characters: @@ -122,9 +116,7 @@ def fix(self) -> Iterator[LinterResult]: if not self.new_file_content: return - self.context.nasl_file.write_text( - self.new_file_content, encoding=CURRENT_ENCODING - ) + self.context.nasl_file.write_text(self.new_file_content, encoding=CURRENT_ENCODING) yield LinterFix( "Replaced Illegal Characters.", diff --git a/troubadix/plugins/log_messages.py b/troubadix/plugins/log_messages.py index dbbac70d..161f0bde 100644 --- a/troubadix/plugins/log_messages.py +++ b/troubadix/plugins/log_messages.py @@ -75,8 +75,7 @@ def check_content( # log_match = re.search(r'.*(log_message[\s]*\([^)]+\)[\s]*;)', # file_content, re.MULTILINE) log_match = re.search( - r"log_message\s*\([\w:#\.&\-!,<>\[\](" - r")\s\"+\'/\\\n]+\)\s*(;|;\s*(\n|#))", + r"log_message\s*\([\w:#\.&\-!,<>\[\](" r")\s\"+\'/\\\n]+\)\s*(;|;\s*(\n|#))", file_content, re.MULTILINE, ) diff --git a/troubadix/plugins/malformed_dependencies.py b/troubadix/plugins/malformed_dependencies.py index de978f51..5f403b0f 100644 --- a/troubadix/plugins/malformed_dependencies.py +++ b/troubadix/plugins/malformed_dependencies.py @@ -23,9 +23,7 @@ from troubadix.helper.patterns import _get_special_script_tag_pattern from troubadix.plugin import FilePlugin, LinterError, LinterResult -DEPENDENCY_ENTRY_PATTERN = re.compile( - r'(?P[\'"])(?P[^\'"]*)(?P=quote)' -) +DEPENDENCY_ENTRY_PATTERN = re.compile(r'(?P[\'"])(?P[^\'"]*)(?P=quote)') WHITESPACE_PATTERN = re.compile(r"\s") @@ -55,9 +53,7 @@ def run( if not match: continue - tag_value = ( - f'"{match.group("value")}"' if match.group("value") else "" - ) + tag_value = f'"{match.group("value")}"' if match.group("value") else "" dependency_entries = DEPENDENCY_ENTRY_PATTERN.finditer(tag_value) diff --git a/troubadix/plugins/missing_desc_exit.py b/troubadix/plugins/missing_desc_exit.py index 265fcb10..fa2ab2c4 100644 --- a/troubadix/plugins/missing_desc_exit.py +++ b/troubadix/plugins/missing_desc_exit.py @@ -61,9 +61,7 @@ def check_content( re.MULTILINE | re.DOTALL, ) if match and match.group(1): - submatch = re.search( - r"^\s*exit\s*\(\s*0\s*\)\s*;", match.group(1), re.MULTILINE - ) + submatch = re.search(r"^\s*exit\s*\(\s*0\s*\)\s*;", match.group(1), re.MULTILINE) if not submatch: yield LinterError( "No mandatory exit(0); found in the description block.", diff --git a/troubadix/plugins/multiple_re_parameters.py b/troubadix/plugins/multiple_re_parameters.py index 66727aaf..13a7c734 100644 --- a/troubadix/plugins/multiple_re_parameters.py +++ b/troubadix/plugins/multiple_re_parameters.py @@ -13,9 +13,7 @@ RE_PATTERN = re.compile(r"re\s*:") -MANDATORY_KEYS_PATTERN = get_special_script_tag_pattern( - SpecialScriptTag.MANDATORY_KEYS -) +MANDATORY_KEYS_PATTERN = get_special_script_tag_pattern(SpecialScriptTag.MANDATORY_KEYS) class CheckMultipleReParameters(LineContentPlugin): @@ -25,9 +23,7 @@ class CheckMultipleReParameters(LineContentPlugin): name = "check_multiple_re_parameters" - def check_lines( - self, nasl_file: Path, lines: Iterable[str] - ) -> Iterator[LinterResult]: + def check_lines(self, nasl_file: Path, lines: Iterable[str]) -> Iterator[LinterResult]: if self.context.nasl_file.suffix == ".inc": return diff --git a/troubadix/plugins/newlines.py b/troubadix/plugins/newlines.py index 72968489..9503c7ef 100644 --- a/troubadix/plugins/newlines.py +++ b/troubadix/plugins/newlines.py @@ -58,8 +58,7 @@ def run(self) -> Iterator[LinterResult]: break newline_match = re.search( - rf'(script_{tag}\((?P[\'"])[^\'"\n;]*)[\n]+\s*' - r'([^\'"\n;]*(?P=quote)\);)', + rf'(script_{tag}\((?P[\'"])[^\'"\n;]*)[\n]+\s*' r'([^\'"\n;]*(?P=quote)\);)', file_content, ) if newline_match: diff --git a/troubadix/plugins/overlong_description_lines.py b/troubadix/plugins/overlong_description_lines.py index 5f0418c7..5fe6a57d 100644 --- a/troubadix/plugins/overlong_description_lines.py +++ b/troubadix/plugins/overlong_description_lines.py @@ -56,9 +56,7 @@ class CheckOverlongDescriptionLines(FileContentPlugin): name = "check_overlong_description_lines" - def check_content( - self, nasl_file: Path, file_content: str - ) -> Iterator[LinterResult]: + def check_content(self, nasl_file: Path, file_content: str) -> Iterator[LinterResult]: if nasl_file.suffix == ".inc": return @@ -87,9 +85,7 @@ def check_content( continue yield LinterWarning( - f"Line {i} is too long" - f" with {len(line)} characters. " - f"Max 100", + f"Line {i} is too long" f" with {len(line)} characters. " f"Max 100", plugin=self.name, file=nasl_file, line=i, diff --git a/troubadix/plugins/prod_svc_detect_in_vulnvt.py b/troubadix/plugins/prod_svc_detect_in_vulnvt.py index cabc1f4f..135b9f1b 100644 --- a/troubadix/plugins/prod_svc_detect_in_vulnvt.py +++ b/troubadix/plugins/prod_svc_detect_in_vulnvt.py @@ -97,10 +97,7 @@ def run(self) -> Iterator[LinterResult]: ) if matches: for match in matches: - if all( - det not in match.group("body") - for det in ["detected_by", "detected_at"] - ): + if all(det not in match.group("body") for det in ["detected_by", "detected_at"]): yield LinterError( "VT has a severity but is using the function '" f"{match.group('function')}' which is not allowed for " diff --git a/troubadix/plugins/script_add_preference_id.py b/troubadix/plugins/script_add_preference_id.py index 691bc9ff..f89c10b8 100644 --- a/troubadix/plugins/script_add_preference_id.py +++ b/troubadix/plugins/script_add_preference_id.py @@ -26,20 +26,13 @@ def iter_script_add_preference_values( class CheckScriptAddPreferenceId(FileContentPlugin): name = "check_script_add_preference_id" - def check_content( - self, nasl_file: Path, file_content: str - ) -> Iterator[LinterResult]: - if ( - nasl_file.suffix == ".inc" - or "script_add_preference" not in file_content - ): + def check_content(self, nasl_file: Path, file_content: str) -> Iterator[LinterResult]: + if nasl_file.suffix == ".inc" or "script_add_preference" not in file_content: return seen_ids: set[int] = set() - for index, value in enumerate( - iter_script_add_preference_values(file_content), 1 - ): + for index, value in enumerate(iter_script_add_preference_values(file_content), 1): id_match = ID_PATTERN.search(value) pref_id = int(id_match.group("id")) if id_match else index diff --git a/troubadix/plugins/script_add_preference_type.py b/troubadix/plugins/script_add_preference_type.py index 4d00295a..6063a36d 100644 --- a/troubadix/plugins/script_add_preference_type.py +++ b/troubadix/plugins/script_add_preference_type.py @@ -28,9 +28,7 @@ ) from troubadix.plugin import FileContentPlugin, LinterError, LinterResult -TYPE_PATTERN = re.compile( - r'type\s*:\s*(?P[\'"])(?P[^\'"]+)(?P=quote)' -) +TYPE_PATTERN = re.compile(r'type\s*:\s*(?P[\'"])(?P[^\'"]+)(?P=quote)') class ValidType(Enum): @@ -99,10 +97,7 @@ def check_content( # nb: This exists since years and it is currently # unclear if we can change it so # we're excluding it here for now. - if ( - "ssh_authorization_init.nasl" in nasl_file.name - and pref_type == "sshlogin" - ): + if "ssh_authorization_init.nasl" in nasl_file.name and pref_type == "sshlogin": continue yield LinterError( diff --git a/troubadix/plugins/script_calls_empty_values.py b/troubadix/plugins/script_calls_empty_values.py index 862f3a9a..776f3cd2 100644 --- a/troubadix/plugins/script_calls_empty_values.py +++ b/troubadix/plugins/script_calls_empty_values.py @@ -64,9 +64,9 @@ def check_content( ) for call in SPECIAL_SCRIPT_TAG_LIST: - matches = _get_special_script_tag_pattern( - name=call.value, value="" - ).finditer(file_content) + matches = _get_special_script_tag_pattern(name=call.value, value="").finditer( + file_content + ) for match in matches: yield LinterError( f"{match.group(0)} does not contain a value", diff --git a/troubadix/plugins/script_calls_recommended.py b/troubadix/plugins/script_calls_recommended.py index 6ee6074c..820377f3 100644 --- a/troubadix/plugins/script_calls_recommended.py +++ b/troubadix/plugins/script_calls_recommended.py @@ -57,9 +57,7 @@ def check_content( if _get_special_script_tag_pattern( name=r"category", value=r"ACT_(SETTINGS|SCANNER|INIT)" - ).search(file_content) or _get_tag_pattern( - name=r"deprecated", value=r"TRUE" - ).search( + ).search(file_content) or _get_tag_pattern(name=r"deprecated", value=r"TRUE").search( file_content ): return @@ -84,12 +82,11 @@ def check_content( plugin=self.name, ) for call in recommended_single_call: - if not _get_special_script_tag_pattern( - name=call, value=".*", flags=re.DOTALL - ).search(file_content): + if not _get_special_script_tag_pattern(name=call, value=".*", flags=re.DOTALL).search( + file_content + ): yield LinterWarning( - "VT does not contain the following recommended call: " - f"'script_{call}'", + "VT does not contain the following recommended call: " f"'script_{call}'", file=nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/script_copyright.py b/troubadix/plugins/script_copyright.py index 745b14a4..976cedb0 100644 --- a/troubadix/plugins/script_copyright.py +++ b/troubadix/plugins/script_copyright.py @@ -50,9 +50,7 @@ def check_content( ): return - if not re.search( - r'script_copyright\("Copyright \(C\) [0-9]{4}', file_content - ): + if not re.search(r'script_copyright\("Copyright \(C\) [0-9]{4}', file_content): yield LinterError( "The VT is using an incorrect syntax for its " "copyright statement. Please start (EXACTLY) with: " diff --git a/troubadix/plugins/script_family.py b/troubadix/plugins/script_family.py index ac6d1b99..2f9e9ac3 100644 --- a/troubadix/plugins/script_family.py +++ b/troubadix/plugins/script_family.py @@ -130,8 +130,7 @@ def check_content( if matches[0].group("value") not in VALID_FAMILIES: yield LinterError( - "Invalid or misspelled script family " - f"'{matches[0].group('value')}'", + "Invalid or misspelled script family " f"'{matches[0].group('value')}'", file=nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/script_tag_form.py b/troubadix/plugins/script_tag_form.py index bfe749a6..19bd844f 100644 --- a/troubadix/plugins/script_tag_form.py +++ b/troubadix/plugins/script_tag_form.py @@ -40,9 +40,7 @@ def check_content( matches = re.finditer(r"script_tag\(.*\);", file_content) for match in matches: if match: - if not _get_tag_pattern(name=r".*", value=r".*").match( - match.group(0) - ): + if not _get_tag_pattern(name=r".*", value=r".*").match(match.group(0)): yield LinterError( f"{match.group(0)}: does not conform to" ' script_tag(name:"", value:);', diff --git a/troubadix/plugins/script_tag_whitespaces.py b/troubadix/plugins/script_tag_whitespaces.py index 8447f4f4..10cdde90 100644 --- a/troubadix/plugins/script_tag_whitespaces.py +++ b/troubadix/plugins/script_tag_whitespaces.py @@ -44,18 +44,14 @@ def check_content( if nasl_file.suffix == ".inc": return - tag_matches = _get_tag_pattern(name=r".+?", flags=re.S).finditer( - file_content - ) + tag_matches = _get_tag_pattern(name=r".+?", flags=re.S).finditer(file_content) - name_matches = _get_special_script_tag_pattern( - name=SpecialScriptTag.NAME.value - ).finditer(file_content) - - xref_matches = get_xref_pattern(name=r".+?", flags=re.S).finditer( + name_matches = _get_special_script_tag_pattern(name=SpecialScriptTag.NAME.value).finditer( file_content ) + xref_matches = get_xref_pattern(name=r".+?", flags=re.S).finditer(file_content) + matches = chain(tag_matches, name_matches, xref_matches) for match in matches: diff --git a/troubadix/plugins/script_tags_mandatory.py b/troubadix/plugins/script_tags_mandatory.py index 1c4ad6d9..85bc056d 100644 --- a/troubadix/plugins/script_tags_mandatory.py +++ b/troubadix/plugins/script_tags_mandatory.py @@ -69,16 +69,13 @@ def check_content( for tag in MANDATORY_TAGS: if not get_script_tag_pattern(tag).search(file_content): yield LinterError( - "VT does not contain the following mandatory tag: " - f"'script_{tag.value}'", + "VT does not contain the following mandatory tag: " f"'script_{tag.value}'", file=nasl_file, plugin=self.name, ) for special_tag in MANDATORY_SPECIAL_TAGS: - if not get_special_script_tag_pattern(special_tag).search( - file_content - ): + if not get_special_script_tag_pattern(special_tag).search(file_content): yield LinterError( "VT does not contain the following mandatory tag: " f"'script_{special_tag.value}'", diff --git a/troubadix/plugins/script_version_and_last_modification_tags.py b/troubadix/plugins/script_version_and_last_modification_tags.py index 966d653c..a3d93f0c 100644 --- a/troubadix/plugins/script_version_and_last_modification_tags.py +++ b/troubadix/plugins/script_version_and_last_modification_tags.py @@ -84,9 +84,7 @@ def check_content( self.old_script_version_value = match_script_version_any.group("value") # script_version("2019-03-21T12:19:01+0000");") - version_pattern = get_special_script_tag_pattern( - SpecialScriptTag.VERSION - ) + version_pattern = get_special_script_tag_pattern(SpecialScriptTag.VERSION) version_match = version_pattern.search(file_content) if not version_match: @@ -122,22 +120,17 @@ def check_content( return self.old_last_modification = match_last_modification_any_value.group(0) - self.old_last_modification_value = ( - match_last_modification_any_value.group("value") - ) + self.old_last_modification_value = match_last_modification_any_value.group("value") # script_tag(name:"last_modification", # value:"2019-03-21 12:19:01 +0000 (Thu, 21 Mar 2019)"); - last_modification_pattern = get_script_tag_pattern( - ScriptTag.LAST_MODIFICATION - ) + last_modification_pattern = get_script_tag_pattern(ScriptTag.LAST_MODIFICATION) match_last_modified = last_modification_pattern.search(file_content) if not match_last_modified: self.fix_last_modification_and_version = True yield LinterError( - "VT is is using a wrong syntax for script_tag(" - 'name:"last_modification".', + "VT is is using a wrong syntax for script_tag(" 'name:"last_modification".', file=nasl_file, plugin=self.name, ) @@ -198,18 +191,14 @@ def fix(self) -> Iterator[LinterResult]: # get that last modification date formatted correctly: # "2021-03-24 10:08:26 +0000 (Wed, 24 Mar 2021)" - correctly_formatted_last_modification = ( - f"{now:%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)}" - ) + correctly_formatted_last_modification = f"{now:%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)}" file_content = file_content.replace( self.old_last_modification, tag_template.format(date=correctly_formatted_last_modification), ) - self.context.nasl_file.write_text( - file_content, encoding=CURRENT_ENCODING - ) + self.context.nasl_file.write_text(file_content, encoding=CURRENT_ENCODING) yield LinterFix( f"Replaced last_modification {self.old_last_modification_value} " diff --git a/troubadix/plugins/script_xref_form.py b/troubadix/plugins/script_xref_form.py index e1bdcd52..cd5af604 100644 --- a/troubadix/plugins/script_xref_form.py +++ b/troubadix/plugins/script_xref_form.py @@ -41,9 +41,7 @@ def check_content( if matches: for match in matches: if match: - if not get_xref_pattern(name=r".*", value=r".*").match( - match.group(0) - ): + if not get_xref_pattern(name=r".*", value=r".*").match(match.group(0)): yield LinterError( f"{match.group(0)}: does not conform to" ' script_xref(name:"", value:);', diff --git a/troubadix/plugins/script_xref_url.py b/troubadix/plugins/script_xref_url.py index d508c693..535e29a4 100644 --- a/troubadix/plugins/script_xref_url.py +++ b/troubadix/plugins/script_xref_url.py @@ -30,10 +30,8 @@ + "fbd2dac042934e49288b476d5f6a649e5da2@", "https://m0ze.ru/vulnerability/[2021-05-26]-[WordPress]-[C" + "WE-79]-WP-Reset-WordPress-Plugin-v1.86.txt", - "http://yehg.net/lab/pr0js/advisories/joomla/core/[joomla_" - + "1.0.x~15]_cross_site_scripting", - "http://yehg.net/lab/pr0js/advisories/eclipse/[eclipse_hel" - + "p_server]_cross_site_scripting", + "http://yehg.net/lab/pr0js/advisories/joomla/core/[joomla_" + "1.0.x~15]_cross_site_scripting", + "http://yehg.net/lab/pr0js/advisories/eclipse/[eclipse_hel" + "p_server]_cross_site_scripting", "http://core.yehg.net/lab/pr0js/advisories/dll_hijacking/[" + "flash_player]_10.1.x_insecure_dll_hijacking_(dwmapi.dll)", "https://lists.apache.org/thread.html/773c93c2d8a6a52bbe9" @@ -62,9 +60,7 @@ def check_content( if nasl_file.suffix == ".inc": return - matches = get_xref_pattern(name="URL", value=r".+?").finditer( - file_content - ) + matches = get_xref_pattern(name="URL", value=r".+?").finditer(file_content) for match in matches: if match: url_value = match.group("value") diff --git a/troubadix/plugins/security_messages.py b/troubadix/plugins/security_messages.py index 3ef0b731..d5ef3aba 100644 --- a/troubadix/plugins/security_messages.py +++ b/troubadix/plugins/security_messages.py @@ -36,8 +36,7 @@ def _file_contains_security_message(file_content: str) -> bool: file_content (str): The content of the VT """ return any( - security_message in file_content - for security_message in SECURITY_MESSAGE_IMPLEMENTATIONS + security_message in file_content for security_message in SECURITY_MESSAGE_IMPLEMENTATIONS ) @@ -54,9 +53,7 @@ def _check_security_message_present( nasl_file (Path): The VTs path file_content (str): The content of the VT """ - deprecated_pattern = get_script_tag_pattern( - script_tag=ScriptTag.DEPRECATED - ) + deprecated_pattern = get_script_tag_pattern(script_tag=ScriptTag.DEPRECATED) if deprecated_pattern.search(file_content): return @@ -90,9 +87,7 @@ def _check_security_message_absent( plugin=self.name, ) - def _determinate_security_message_by_severity( - self, file_content: str - ) -> bool: + def _determinate_security_message_by_severity(self, file_content: str) -> bool: """Determinates wether a VT requires a security_message or implementing function call @@ -122,15 +117,9 @@ def check_content( if nasl_file.suffix == ".inc": return - security_message_required = ( - self._determinate_security_message_by_severity(file_content) - ) + security_message_required = self._determinate_security_message_by_severity(file_content) if security_message_required: - yield from self._check_security_message_present( - nasl_file, file_content - ) + yield from self._check_security_message_present(nasl_file, file_content) else: - yield from self._check_security_message_absent( - nasl_file, file_content - ) + yield from self._check_security_message_absent(nasl_file, file_content) diff --git a/troubadix/plugins/severity_date.py b/troubadix/plugins/severity_date.py index b88f2cf1..9fa695fb 100644 --- a/troubadix/plugins/severity_date.py +++ b/troubadix/plugins/severity_date.py @@ -25,13 +25,9 @@ def check_content( return severity_date_pattern = get_script_tag_pattern(ScriptTag.SEVERITY_DATE) - last_modification_pattern = get_script_tag_pattern( - ScriptTag.LAST_MODIFICATION - ) + last_modification_pattern = get_script_tag_pattern(ScriptTag.LAST_MODIFICATION) - if not ( - match_severity_date := severity_date_pattern.search(file_content) - ): + if not (match_severity_date := severity_date_pattern.search(file_content)): return yield from check_date( @@ -41,9 +37,7 @@ def check_content( self.name, ) - if match_last_mod_date := last_modification_pattern.search( - file_content - ): + if match_last_mod_date := last_modification_pattern.search(file_content): yield from compare_date_with_last_modification_date( match_severity_date.group("value"), "severity_date", diff --git a/troubadix/plugins/severity_format.py b/troubadix/plugins/severity_format.py index 22a00463..ead34ddb 100644 --- a/troubadix/plugins/severity_format.py +++ b/troubadix/plugins/severity_format.py @@ -20,9 +20,7 @@ def check_content( if nasl_file.suffix == ".inc" or "severity_vector" not in file_content: return - severity_vector_pattern = get_script_tag_pattern( - ScriptTag.SEVERITY_VECTOR - ) + severity_vector_pattern = get_script_tag_pattern(ScriptTag.SEVERITY_VECTOR) severity_vector_match = severity_vector_pattern.search(file_content) if not severity_vector_match: diff --git a/troubadix/plugins/severity_origin.py b/troubadix/plugins/severity_origin.py index 2e25ff57..cecaf853 100644 --- a/troubadix/plugins/severity_origin.py +++ b/troubadix/plugins/severity_origin.py @@ -20,9 +20,7 @@ def check_content( if nasl_file.suffix == ".inc" or "severity_origin" not in file_content: return - severity_origin_pattern = get_script_tag_pattern( - ScriptTag.SEVERITY_ORIGIN - ) + severity_origin_pattern = get_script_tag_pattern(ScriptTag.SEVERITY_ORIGIN) severity_origin_match = severity_origin_pattern.search(file_content) if not severity_origin_match: diff --git a/troubadix/plugins/solution_text.py b/troubadix/plugins/solution_text.py index 9378b6ee..6adf9a98 100644 --- a/troubadix/plugins/solution_text.py +++ b/troubadix/plugins/solution_text.py @@ -98,11 +98,9 @@ def run(self) -> Iterator[LinterResult]: ) file_content = self.context.file_content - if _get_tag_pattern( - name=ScriptTag.SOLUTION_TYPE.value, value="NoneAvailable" - ).search(file_content) and not re.search( - correct_none_available_pattern, file_content - ): + if _get_tag_pattern(name=ScriptTag.SOLUTION_TYPE.value, value="NoneAvailable").search( + file_content + ) and not re.search(correct_none_available_pattern, file_content): yield LinterError( "The VT with solution type 'NoneAvailable' is using an " "incorrect syntax in the solution text. Please use " @@ -110,11 +108,9 @@ def run(self) -> Iterator[LinterResult]: file=self.context.nasl_file, plugin=self.name, ) - elif _get_tag_pattern( - name=ScriptTag.SOLUTION_TYPE.value, value="WillNotFix" - ).search(file_content) and not re.search( - correct_will_not_fix_pattern, file_content - ): + elif _get_tag_pattern(name=ScriptTag.SOLUTION_TYPE.value, value="WillNotFix").search( + file_content + ) and not re.search(correct_will_not_fix_pattern, file_content): yield LinterError( "The VT with solution type 'WillNotFix' is using an incorrect " "syntax in the solution text. Please use one of these " diff --git a/troubadix/plugins/solution_type.py b/troubadix/plugins/solution_type.py index 64034132..65a9d8f5 100644 --- a/troubadix/plugins/solution_type.py +++ b/troubadix/plugins/solution_type.py @@ -53,8 +53,7 @@ def check_content( has_severity = True cvss_detect = re.search( - r"script_tag\s*\(name\s*:\s*\"cvss_base\"," - r"\s*value:\s*\"(\d{1,2}\.\d)\"\)", + r"script_tag\s*\(name\s*:\s*\"cvss_base\"," r"\s*value:\s*\"(\d{1,2}\.\d)\"\)", file_content, ) if cvss_detect is not None and cvss_detect.group(1) == "0.0": diff --git a/troubadix/plugins/spaces_before_dots.py b/troubadix/plugins/spaces_before_dots.py index 8fc95301..a6d9ab85 100644 --- a/troubadix/plugins/spaces_before_dots.py +++ b/troubadix/plugins/spaces_before_dots.py @@ -71,9 +71,7 @@ class CheckSpacesBeforeDots(FileContentPlugin): name = "check_spaces_before_dots" - def check_content( - self, nasl_file: Path, file_content: str - ) -> Iterator[LinterResult]: + def check_content(self, nasl_file: Path, file_content: str) -> Iterator[LinterResult]: """ This plugin checks for excess whitespace before a dot in script_tags that have full sentence values @@ -114,11 +112,7 @@ def fix(self) -> Iterator[LinterResult]: for pos, match_str in self.matches: # Replace the match by removing the excess whitespace before the dot fixed_str = re.sub(r"\s+\.", ".", match_str) - file_content = ( - file_content[:pos] - + fixed_str - + file_content[pos + len(match_str) :] - ) + file_content = file_content[:pos] + fixed_str + file_content[pos + len(match_str) :] with open(self.context.nasl_file, "w", encoding=CURRENT_ENCODING) as f: f.write(file_content) diff --git a/troubadix/plugins/spaces_in_filename.py b/troubadix/plugins/spaces_in_filename.py index 90dbc38b..47e500b2 100644 --- a/troubadix/plugins/spaces_in_filename.py +++ b/troubadix/plugins/spaces_in_filename.py @@ -13,8 +13,7 @@ class CheckSpacesInFilename(FilePlugin): def run(self) -> Iterator[LinterResult]: if re.search(r"\s", self.context.nasl_file.name): yield LinterError( - f"The VT {self.context.nasl_file}" - " contains whitespace in the filename", + f"The VT {self.context.nasl_file}" " contains whitespace in the filename", file=self.context.nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/spelling.py b/troubadix/plugins/spelling.py index 116739d0..7eb14cfb 100644 --- a/troubadix/plugins/spelling.py +++ b/troubadix/plugins/spelling.py @@ -48,9 +48,7 @@ # Same for a few other files: PatternInFileCheck("smtp_AV_42zip_DoS.nasl", r"BA\s+==>\s+BY, BE"), PatternInFileCheck("bad_ssh_host_keys.inc", r"ba\s+==>\s+by, be"), - PatternsInFileCheck( - "wmi_misc.inc", [r"BA\s+==>\s+BY, BE", r"OD\s+==>\s+OF"] - ), + PatternsInFileCheck("wmi_misc.inc", [r"BA\s+==>\s+BY, BE", r"OD\s+==>\s+OF"]), PatternInFilesCheck( ["ssl_funcs.inc", "gb_ssl_tls_cert_details.nasl"], r"fpr\s+==>\s+for, far, fps", @@ -104,9 +102,7 @@ r"n[iI]n\s+==>\s+inn", ), # False positive in this VT in German example responses. - PatternInFileCheck( - "gb_exchange_server_CVE-2021-26855_active.nasl", r"ist\s+==>\s+is" - ), + PatternInFileCheck("gb_exchange_server_CVE-2021-26855_active.nasl", r"ist\s+==>\s+is"), # Mostly a false positive in LSCs because of things like # "ALSA: hda" or a codec called "Conexant". There are too # many hits to maintain them in codespell.exclude so exclude @@ -152,9 +148,7 @@ r"nam\s+==>\s+name", text_pattern_flags=re.IGNORECASE, ), - PatternInFileCheck( - "/netop_infopublic.nasl", r"nam\s+==>\s+name", flags=re.IGNORECASE - ), + PatternInFileCheck("/netop_infopublic.nasl", r"nam\s+==>\s+name", flags=re.IGNORECASE), # Product names used in a few VTs (no re.IGNORECASE is expected) PatternsCheck([r"renderD\s+==>\s+rendered", r"VertX\s+==>\s+vertex"]), PatternInFileCheck("_vertx_", r"vertx\s+==>\s+vertex"), @@ -206,8 +200,7 @@ def run(self) -> Iterator[LinterResult]: batch_size = 10_000 for i in range(0, len(self.context.nasl_files), batch_size): files_parameters = [ - str(nasl_file) - for nasl_file in self.context.nasl_files[i : i + batch_size] + str(nasl_file) for nasl_file in self.context.nasl_files[i : i + batch_size] ] codespell_arguments = [ "--hard-encoding-detection", @@ -235,9 +228,7 @@ def run(self) -> Iterator[LinterResult]: codespell_entries = [ line for line in codespell_output.splitlines() - if not handle_linguistic_checks( - *self._parse_codespell_line(line), exceptions - ) + if not handle_linguistic_checks(*self._parse_codespell_line(line), exceptions) ] for codespell_entry in codespell_entries: diff --git a/troubadix/plugins/trailing_spaces_tabs.py b/troubadix/plugins/trailing_spaces_tabs.py index 7628f438..c79535b1 100644 --- a/troubadix/plugins/trailing_spaces_tabs.py +++ b/troubadix/plugins/trailing_spaces_tabs.py @@ -39,15 +39,12 @@ def run(self) -> Iterator[LinterResult]: to find special tags """ - for line_number, line in enumerate( - self.context.file_content.splitlines(), start=1 - ): + for line_number, line in enumerate(self.context.file_content.splitlines(), start=1): if not PATTERN.search(line): continue yield LinterError( - "The VT has one or more trailing spaces " - f"and/or tabs in line {line_number}!", + "The VT has one or more trailing spaces " f"and/or tabs in line {line_number}!", file=self.context.nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/using_display.py b/troubadix/plugins/using_display.py index a035e20f..7460eda7 100644 --- a/troubadix/plugins/using_display.py +++ b/troubadix/plugins/using_display.py @@ -63,9 +63,7 @@ def check_content( # Case 1: Not in any if statement - ERROR if not containing_if: - line_start = ( - comment_free_content.rfind("\n", 0, display_pos) + 1 - ) + line_start = comment_free_content.rfind("\n", 0, display_pos) + 1 line_end = comment_free_content.find("\n", display_pos) if line_end == -1: line_end = len(comment_free_content) @@ -95,9 +93,7 @@ def check_content( yield LinterWarning( "VT is using a display() inside an if statement" f" but without debug check at line {line}\n" - + comment_free_content[ - containing_if.if_start : containing_if.if_end - ], + + comment_free_content[containing_if.if_start : containing_if.if_end], file=nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/valid_oid.py b/troubadix/plugins/valid_oid.py index b8540eaa..fbd153ae 100644 --- a/troubadix/plugins/valid_oid.py +++ b/troubadix/plugins/valid_oid.py @@ -95,13 +95,8 @@ def check_content( # Vendor-specific OIDs if "1.3.6.1.4.1.25623.1.1." in oid: family = family_match.group("value") - vendor_number_match = re.search( - r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.([0-9]+)\.", oid - ) - if ( - vendor_number_match is None - or vendor_number_match.group(1) is None - ): + vendor_number_match = re.search(r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.([0-9]+)\.", oid) + if vendor_number_match is None or vendor_number_match.group(1) is None: yield LinterError( f"script_oid() {invalid_oid} '{str(oid)}' (last digits)", file=nasl_file, @@ -114,8 +109,7 @@ def check_content( if vendor_number == "1": if family != f"Debian {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Debian " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Debian " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -124,8 +118,7 @@ def check_content( elif vendor_number == "2": if family != f"Huawei EulerOS {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} EulerOS " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} EulerOS " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -133,8 +126,7 @@ def check_content( # Fixed OID-scheme for (Huawei) Euler OS OIDs euler_sa_match = re.search( - r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.2\.20[0-4][0-9]\.[0-9]{" - r"4}$", + r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.2\.20[0-4][0-9]\.[0-9]{" r"4}$", oid, ) if euler_sa_match is None: @@ -150,8 +142,7 @@ def check_content( elif vendor_number == "4": if family != f"SuSE {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} SUSE SLES " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} SUSE SLES " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -159,8 +150,7 @@ def check_content( # Fixed OID-scheme for SUSE SLES OS OIDs sles_sa_match = re.search( - r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.4\.20[0-4][0-9]\.[0-9]{" - r"4,5}\.[0-9]$", + r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.4\.20[0-4][0-9]\.[0-9]{" r"4,5}\.[0-9]$", oid, ) if sles_sa_match is None: @@ -176,8 +166,7 @@ def check_content( elif vendor_number == "5": if family != f"Amazon Linux {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Amazon Linux " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Amazon Linux " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -200,8 +189,7 @@ def check_content( elif vendor_number == "6": if family != f"Gentoo {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Gentoo " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Gentoo " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -210,8 +198,7 @@ def check_content( elif vendor_number == "7": if family != "FreeBSD Local Security Checks": yield LinterError( - f"script_oid() {is_using_reserved} FreeBSD " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} FreeBSD " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -220,8 +207,7 @@ def check_content( elif vendor_number == "8": if family != f"Oracle Linux {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Oracle Linux " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Oracle Linux " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -230,8 +216,7 @@ def check_content( elif vendor_number == "9": if family != f"Fedora {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Fedora " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Fedora " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -240,16 +225,14 @@ def check_content( elif vendor_number == "10": if family != f"Mageia Linux {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Mageia Linux " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Mageia Linux " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) return mageia_sa_match = re.search( - r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.10\.20[0-4][0-9]\.[" - r"0-9]{4}$", + r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.10\.20[0-4][0-9]\.[" r"0-9]{4}$", oid, ) if mageia_sa_match is None: @@ -265,8 +248,7 @@ def check_content( elif vendor_number == "11": if family != f"Red Hat {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Red Hat " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Red Hat " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -275,8 +257,7 @@ def check_content( elif vendor_number == "12": if family != f"Ubuntu {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Ubuntu " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Ubuntu " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -285,14 +266,12 @@ def check_content( elif vendor_number == "13": if family != f"Slackware {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Slackware " - f"'{str(oid)}'" + f"script_oid() {is_using_reserved} Slackware " f"'{str(oid)}'" ) return slackware_sa_match = re.search( - r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.13\.20[0-4][0-9]\.[0-9]" - r"{3,4}\.[0-9]{2}$", + r"^1\.3\.6\.1\.4\.1\.25623\.1\.1\.13\.20[0-4][0-9]\.[0-9]" r"{3,4}\.[0-9]{2}$", oid, ) if slackware_sa_match is None: @@ -306,8 +285,7 @@ def check_content( elif vendor_number == "14": if family != f"Rocky Linux {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} Rocky Linux " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} Rocky Linux " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -316,8 +294,7 @@ def check_content( elif vendor_number == "15": if family != f"AlmaLinux {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} AlmaLinux " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} AlmaLinux " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -325,8 +302,7 @@ def check_content( elif vendor_number == "18": if family != f"openSUSE {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} openSUSE " - f"'{str(oid)}'", + f"script_oid() {is_using_reserved} openSUSE " f"'{str(oid)}'", file=nasl_file, plugin=self.name, ) @@ -361,16 +337,14 @@ def check_content( if "1.3.6.1.4.1.25623.1.2.1." in oid: if not name.startswith(f"Mozilla Firefox {security_template}"): yield LinterError( - f"script_oid() {is_using_reserved} 'Firefox' (" - f"{str(oid)})", + f"script_oid() {is_using_reserved} 'Firefox' (" f"{str(oid)})", file=nasl_file, plugin=self.name, ) return firefox_sa_match = re.search( - r"^1\.3\.6\.1\.4\.1\.25623\.1\.2\.1\.20[1-4][0-9]\.[0-9]{" - r"2,3}$", + r"^1\.3\.6\.1\.4\.1\.25623\.1\.2\.1\.20[1-4][0-9]\.[0-9]{" r"2,3}$", oid, ) if not firefox_sa_match: @@ -389,8 +363,7 @@ def check_content( if "1.3.6.1.4.1.25623.1.3." in oid: if family_match.group("value") != f"Windows {family_template}": yield LinterError( - f"script_oid() {is_using_reserved} 'Windows' (" - f"{str(oid)})", + f"script_oid() {is_using_reserved} 'Windows' (" f"{str(oid)})", file=nasl_file, plugin=self.name, ) @@ -411,9 +384,7 @@ def check_content( return return - oid_digit_match = re.search( - r"^1\.3\.6\.1\.4\.1\.25623\.1\.0\.([0-9]+)", oid - ) + oid_digit_match = re.search(r"^1\.3\.6\.1\.4\.1\.25623\.1\.0\.([0-9]+)", oid) if oid_digit_match is None or oid_digit_match.group(1) is None: yield LinterError( f"script_oid() {invalid_oid} '{str(oid)}' (last digits)", @@ -424,8 +395,7 @@ def check_content( exceptions = [ "ossim_server_detect.nasl", - "gsf/2018/vmware/gb_vmware_fusion_vmxnet3_" - + "stack_memory_usage_vuln_macosx.nasl", + "gsf/2018/vmware/gb_vmware_fusion_vmxnet3_" + "stack_memory_usage_vuln_macosx.nasl", "2008/asterisk_sdp_header_overflow.nasl", "2008/cisco_ios_ftp_server_auth_bypass.nasl", "2008/qk_smtp_server_dos.nasl", @@ -465,8 +435,7 @@ def check_content( return yield LinterError( - f"script_oid() {invalid_oid} " - f"'{str(oid)}' (unassigned OID range)", + f"script_oid() {invalid_oid} " f"'{str(oid)}' (unassigned OID range)", file=nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/valid_script_tag_names.py b/troubadix/plugins/valid_script_tag_names.py index 45ddc21f..fc8e5cde 100644 --- a/troubadix/plugins/valid_script_tag_names.py +++ b/troubadix/plugins/valid_script_tag_names.py @@ -88,16 +88,13 @@ def check_content( "solution_method", ] - matches = _get_tag_pattern(name=r".+?", flags=re.S).finditer( - file_content - ) + matches = _get_tag_pattern(name=r".+?", flags=re.S).finditer(file_content) if matches: for match in matches: if match.group("name") not in allowed_script_tag_names: yield LinterError( - f"The script_tag name '{match.group('name')}' " - "is not allowed.", + f"The script_tag name '{match.group('name')}' " "is not allowed.", file=nasl_file, plugin=self.name, ) diff --git a/troubadix/plugins/variable_assigned_in_if.py b/troubadix/plugins/variable_assigned_in_if.py index 9fa7ca12..7e985ccc 100644 --- a/troubadix/plugins/variable_assigned_in_if.py +++ b/troubadix/plugins/variable_assigned_in_if.py @@ -57,9 +57,7 @@ def check_content( # # if((foo =~ "bar || bar =~ "foo") || foobar = "foo") # bar = "foo"; (no ending {) - matches = re.finditer( - r"^\s*(if|}?\s*else if)\s*\(([^)]+)", file_content, re.MULTILINE - ) + matches = re.finditer(r"^\s*(if|}?\s*else if)\s*\(([^)]+)", file_content, re.MULTILINE) if matches is None: return @@ -76,10 +74,7 @@ def check_content( r'[a-zA-Z_][a-zA-Z0-9_]*\s*=\s*("|\'|TRUE|0|1)', match.group(0), ) - if ( - var_assign_match is not None - and var_assign_match.group(1) is not None - ): + if var_assign_match is not None and var_assign_match.group(1) is not None: # nb: Can't be fixed because it would mean a change # of a default behavior. if ( diff --git a/troubadix/plugins/variable_redefinition_in_foreach.py b/troubadix/plugins/variable_redefinition_in_foreach.py index e4d70267..95f05d9a 100644 --- a/troubadix/plugins/variable_redefinition_in_foreach.py +++ b/troubadix/plugins/variable_redefinition_in_foreach.py @@ -8,17 +8,13 @@ from troubadix.plugin import FileContentPlugin, LinterResult, LinterWarning FOREACH_PATTERN = re.compile(r"foreach\s+(?P\w+)\s*\((?P.+)\)") -MAKE_LIST_PATTERN = re.compile( - r"^(?:make_list|make_list_unique)\((?P.+)\)$" -) +MAKE_LIST_PATTERN = re.compile(r"^(?:make_list|make_list_unique)\((?P.+)\)$") class CheckVariableRedefinitionInForeach(FileContentPlugin): name = "check_variable_redefinition_in_foreach" - def check_content( - self, nasl_file: Path, file_content: str - ) -> Iterator[LinterResult]: + def check_content(self, nasl_file: Path, file_content: str) -> Iterator[LinterResult]: """This plugin checks for a redefinition of the variable that is passed to the foreach loop. This can be caused by using same variable name diff --git a/troubadix/plugins/vt_placement.py b/troubadix/plugins/vt_placement.py index 4ca71479..4f69dd9e 100644 --- a/troubadix/plugins/vt_placement.py +++ b/troubadix/plugins/vt_placement.py @@ -71,17 +71,11 @@ def check_content( if match is not None: return - if any( - (root / vers / nasl_file.name) == nasl_file - for vers in FEED_VERSIONS - ): + if any((root / vers / nasl_file.name) == nasl_file for vers in FEED_VERSIONS): return for folder in chain(["attic"], ENTERPRISE_FOLDERS): - if any( - (root / vers / folder / nasl_file.name) == nasl_file - for vers in FEED_VERSIONS - ): + if any((root / vers / folder / nasl_file.name) == nasl_file for vers in FEED_VERSIONS): return yield LinterError( diff --git a/troubadix/reporter.py b/troubadix/reporter.py index ed749d08..2ac5e7e0 100644 --- a/troubadix/reporter.py +++ b/troubadix/reporter.py @@ -77,9 +77,7 @@ def _report_ok(self, message: str) -> None: self._term.ok(message) self._log_append(f"\t\t{message}".replace("\n", "\n\t\t")) - def _process_plugin_results( - self, plugin_name: str, plugin_results: Iterable[LinterResult] - ): + def _process_plugin_results(self, plugin_name: str, plugin_results: Iterable[LinterResult]): """Process the results of a plugin: Print/Log results if verbosity/logging fits and count the results""" if plugin_results and self._verbose > 0: @@ -123,9 +121,7 @@ def report_by_plugin(self, results: Results) -> None: with self._term.indent(): self._process_plugin_results(plugin_name, plugin_results) - def report_by_file_plugin( - self, file_results: FileResults, pos: int - ) -> None: + def report_by_file_plugin(self, file_results: FileResults, pos: int) -> None: """Print/log the results of all plugins for a specific file Arguments: @@ -135,12 +131,8 @@ def report_by_file_plugin( """ if file_results and self._verbose > 0 or self._verbose > 1: # only print the part "common/some_nasl.nasl" - from_root_path = get_path_from_root( - file_results.file_path, self._root - ) - self._report_bold_info( - f"Checking {from_root_path} ({pos}/{self._files_count})" - ) + from_root_path = get_path_from_root(file_results.file_path, self._root) + self._report_bold_info(f"Checking {from_root_path} ({pos}/{self._files_count})") with self._term.indent(): for ( @@ -164,9 +156,7 @@ def report_plugin_overview( if included: self.report_info(f"Included Plugins: {', '.join(included)}") - self.report_info( - f"Running plugins: {', '.join([p.name for p in plugins])}" - ) + self.report_info(f"Running plugins: {', '.join([p.name for p in plugins])}") def report_statistic(self) -> None: """Print a Error/Warning summary from the different plugins""" @@ -195,10 +185,7 @@ def report_statistic(self) -> None: if self._fix and self._ignore_warnings: line = f"{plugin:48} {count['error']:8} {count['fix']:8}" elif self._fix: - line = ( - f"{plugin:48} {count['error']:8} {count['warning']:8}" - f" {count['fix']:8}" - ) + line = f"{plugin:48} {count['error']:8} {count['warning']:8}" f" {count['fix']:8}" elif self._ignore_warnings: line = f"{plugin:48} {count['error']:8}" else: diff --git a/troubadix/results.py b/troubadix/results.py index b2ece914..9b1cb468 100644 --- a/troubadix/results.py +++ b/troubadix/results.py @@ -28,15 +28,9 @@ def __init__(self, ignore_warnings: bool = False) -> None: self.has_plugin_results = False self._ignore_warnings = ignore_warnings - def add_plugin_results( - self, plugin_name: str, results: Iterator[LinterResult] - ) -> "Results": + def add_plugin_results(self, plugin_name: str, results: Iterator[LinterResult]) -> "Results": if self._ignore_warnings: - results = [ - result - for result in results - if not isinstance(result, LinterWarning) - ] + results = [result for result in results if not isinstance(result, LinterWarning)] else: results = list(results) diff --git a/troubadix/runner.py b/troubadix/runner.py index ea8b9bda..8ae9c1d1 100644 --- a/troubadix/runner.py +++ b/troubadix/runner.py @@ -86,9 +86,7 @@ def _check_files(self, plugin: Plugin) -> Results: def _check_file(self, file_path: Path) -> FileResults: """Run all file plugins on a single file and collect the results""" results = FileResults(file_path, ignore_warnings=self._ignore_warnings) - context = FilePluginContext( - root=self._root, nasl_file=file_path.resolve() - ) + context = FilePluginContext(root=self._root, nasl_file=file_path.resolve()) for plugin_class in self.plugins.file_plugins: plugin = plugin_class(context) @@ -105,8 +103,7 @@ def _run_pooled(self, files: Iterable[Path]): # run files plugins context = FilesPluginContext(root=self._root, nasl_files=files) files_plugins = [ - plugin_class(context) - for plugin_class in self.plugins.files_plugins + plugin_class(context) for plugin_class in self.plugins.files_plugins ] for results in pool.imap_unordered( @@ -116,14 +113,10 @@ def _run_pooled(self, files: Iterable[Path]): # run file plugins for i, results in enumerate( - iterable=pool.imap_unordered( - self._check_file, files, chunksize=CHUNKSIZE - ), + iterable=pool.imap_unordered(self._check_file, files, chunksize=CHUNKSIZE), start=1, ): - self._reporter.report_by_file_plugin( - file_results=results, pos=i - ) + self._reporter.report_by_file_plugin(file_results=results, pos=i) except KeyboardInterrupt: pool.terminate() @@ -145,9 +138,7 @@ def run(self, files: Iterable[Path]) -> bool: start = datetime.datetime.now() self._run_pooled(files) - self._reporter.report_info( - f"Time elapsed: {datetime.datetime.now() - start}" - ) + self._reporter.report_info(f"Time elapsed: {datetime.datetime.now() - start}") self._reporter.report_statistic() # Return true if no error exists diff --git a/troubadix/standalone_plugins/allowed_rev_diff.py b/troubadix/standalone_plugins/allowed_rev_diff.py index be62f08c..fc65549c 100644 --- a/troubadix/standalone_plugins/allowed_rev_diff.py +++ b/troubadix/standalone_plugins/allowed_rev_diff.py @@ -29,8 +29,7 @@ def parse_arguments() -> Namespace: "--directory", default=Path.cwd(), type=Path, - help="The directory the repository to check is located in. " - "Defaults to 'pwd'", + help="The directory the repository to check is located in. " "Defaults to 'pwd'", ) ignored_linestart_group = argument_parser.add_mutually_exclusive_group() @@ -42,8 +41,7 @@ def parse_arguments() -> Namespace: nargs="*", type=str, default=DEFAULT_IGNORED_LINESTARTS, - help="A list of line starts which will make the line be ignored. " - "Default: %(default)s", + help="A list of line starts which will make the line be ignored. " "Default: %(default)s", ) ignored_linestart_group.add_argument( @@ -73,9 +71,7 @@ def parse_arguments() -> Namespace: "to check the diff for", ) - argument_parser.add_argument( - "-s", "--source", type=str, required=True, help="The upstream rev" - ) + argument_parser.add_argument("-s", "--source", type=str, required=True, help="The upstream rev") argument_parser.add_argument( "-t", "--target", type=str, required=True, help="The downstream rev" @@ -84,14 +80,8 @@ def parse_arguments() -> Namespace: return argument_parser.parse_args() -def check_diff_line_starts_with_ignored_linestart( - line: str, ignored_linestarts: List[str] -) -> bool: - return any( - linestart - for linestart in ignored_linestarts - if line.startswith(linestart) - ) +def check_diff_line_starts_with_ignored_linestart(line: str, ignored_linestarts: List[str]) -> bool: + return any(linestart for linestart in ignored_linestarts if line.startswith(linestart)) def check_diff_line_matches_pattern(line: str, patterns: List[Pattern]) -> bool: @@ -104,9 +94,7 @@ def check_diff( return [ line for line in lines - if not check_diff_line_starts_with_ignored_linestart( - line, ignored_linestarts - ) + if not check_diff_line_starts_with_ignored_linestart(line, ignored_linestarts) and not check_diff_line_matches_pattern(line, patterns) ] @@ -121,10 +109,7 @@ def read_ignored_linestarts(path: Path) -> List[str]: def read_patterns(path: Path) -> List[Pattern]: with open(path, "r", encoding="UTF-8") as file: - return [ - re.compile(pattern.removesuffix("\n")) - for pattern in file.readlines() - ] + return [re.compile(pattern.removesuffix("\n")) for pattern in file.readlines()] def main() -> int: @@ -140,9 +125,7 @@ def main() -> int: diff = repo.git.diff(target, merge_base, unified=0) - result = check_diff( - diff.splitlines(), arguments.ignored_linestarts, patterns - ) + result = check_diff(diff.splitlines(), arguments.ignored_linestarts, patterns) if result: print("The following lines don't match the any pattern:") diff --git a/troubadix/standalone_plugins/changed_creation_date.py b/troubadix/standalone_plugins/changed_creation_date.py index dbcb0942..2b989b4a 100644 --- a/troubadix/standalone_plugins/changed_creation_date.py +++ b/troubadix/standalone_plugins/changed_creation_date.py @@ -61,9 +61,7 @@ def parse_arguments() -> Namespace: return args -def check_changed_creation_date( - commit_range: str, nasl_files: list[Path] -) -> bool: +def check_changed_creation_date(commit_range: str, nasl_files: list[Path]) -> bool: """ This script checks (via git diff) if the creation date of passed VTs has changed, which is not allowed. @@ -90,9 +88,7 @@ def check_changed_creation_date( text, re.MULTILINE, ) - if not creation_date_added or not ( - added := creation_date_added.group("creation_date") - ): + if not creation_date_added or not (added := creation_date_added.group("creation_date")): continue creation_date_removed = re.search( @@ -125,9 +121,7 @@ def main() -> int: git_base = git("rev-parse", "--show-toplevel") os.chdir(git_base.rstrip("\n")) except subprocess.SubprocessError: - logger.error( - "Your current working directory doesn't belong to a git repository" - ) + logger.error("Your current working directory doesn't belong to a git repository") return 1 args = parse_arguments() diff --git a/troubadix/standalone_plugins/changed_cves.py b/troubadix/standalone_plugins/changed_cves.py index 7a109ec7..cb9dbdd5 100644 --- a/troubadix/standalone_plugins/changed_cves.py +++ b/troubadix/standalone_plugins/changed_cves.py @@ -12,9 +12,7 @@ CVE_PATTERN = re.compile(r"CVE-\d{4}-\d{4,}") -def compare( - old_content: str, current_content: str -) -> Tuple[List[str], List[str]]: +def compare(old_content: str, current_content: str) -> Tuple[List[str], List[str]]: old_cves = get_cves_from_content(old_content) current_cves = get_cves_from_content(current_content) @@ -25,9 +23,7 @@ def compare( def get_cves_from_content(content: str) -> Set[str]: - pattern = _get_special_script_tag_pattern( - name="cve_id", flags=re.MULTILINE | re.DOTALL - ) + pattern = _get_special_script_tag_pattern(name="cve_id", flags=re.MULTILINE | re.DOTALL) match = pattern.search(content) if not match: return set() @@ -72,18 +68,14 @@ def main(): args = parse_args() terminal = ConsoleTerminal() - terminal.info( - f"Checking {len(args.files)} file(s) from {args.start_commit} to HEAD" - ) + terminal.info(f"Checking {len(args.files)} file(s) from {args.start_commit} to HEAD") for file in args.files: try: old_content = git("show", f"{args.start_commit}:{file}") current_content = git("show", f"HEAD:{file}") except CalledProcessError: - terminal.error( - f"Could not find {file} at {args.start_commit} or HEAD" - ) + terminal.error(f"Could not find {file} at {args.start_commit} or HEAD") continue missing_cves, added_cves = compare(old_content, current_content) diff --git a/troubadix/standalone_plugins/changed_oid.py b/troubadix/standalone_plugins/changed_oid.py index a8e3375a..71444447 100644 --- a/troubadix/standalone_plugins/changed_oid.py +++ b/troubadix/standalone_plugins/changed_oid.py @@ -69,9 +69,7 @@ def check_oid(args: Namespace) -> bool: if not args.files: args.files += [ Path(f) - for f in git( - "diff", "--name-only", "--diff-filter=d", args.commit_range - ).splitlines() + for f in git("diff", "--name-only", "--diff-filter=d", args.commit_range).splitlines() ] rcode = False @@ -125,9 +123,7 @@ def main() -> int: git_base = git("rev-parse", "--show-toplevel") os.chdir(git_base.rstrip("\n")) except subprocess.SubprocessError: - print( - "Your current working directory doesn't belong to a git repository" - ) + print("Your current working directory doesn't belong to a git repository") return 1 if check_oid(parse_args(args)): diff --git a/troubadix/standalone_plugins/changed_packages/changed_packages.py b/troubadix/standalone_plugins/changed_packages/changed_packages.py index b90bbd02..5ae19c7f 100644 --- a/troubadix/standalone_plugins/changed_packages/changed_packages.py +++ b/troubadix/standalone_plugins/changed_packages/changed_packages.py @@ -64,8 +64,7 @@ def filter_reasons(packages: List[Package], reasons: Iterable[Reasons]): return [ package for package in packages - if not package.reasons - or any([reason not in reasons for reason in package.reasons]) + if not package.reasons or any([reason not in reasons for reason in package.reasons]) ] @@ -154,9 +153,7 @@ def main(): hide_reasons = set(args.hide_reasons) terminal = ConsoleTerminal() - terminal.info( - f"Checking {len(args.files)} file(s) from {args.start_commit} to HEAD" - ) + terminal.info(f"Checking {len(args.files)} file(s) from {args.start_commit} to HEAD") for file in args.files: try: @@ -164,9 +161,7 @@ def main(): content = git("show", f"HEAD:{file}") missing_packages, new_packages = compare(old_content, content) except CalledProcessError: - terminal.error( - f"Could not find {file} at {args.start_commit} or HEAD" - ) + terminal.error(f"Could not find {file} at {args.start_commit} or HEAD") continue except ValueError as e: terminal.error(f"Error while handling {file}: {e}") diff --git a/troubadix/standalone_plugins/changed_packages/marker/changed_update.py b/troubadix/standalone_plugins/changed_packages/marker/changed_update.py index f817f011..cd9bc2c6 100644 --- a/troubadix/standalone_plugins/changed_packages/marker/changed_update.py +++ b/troubadix/standalone_plugins/changed_packages/marker/changed_update.py @@ -43,9 +43,7 @@ def mark(cls, missing_packages: List[Package], new_packages: List[Package]): old_package for old_package in missing_packages if package.name == old_package.name - and old_package.version.startswith( - package.version.replace(suffix, "") - ) + and old_package.version.startswith(package.version.replace(suffix, "")) and package.release == old_package.release ), None, diff --git a/troubadix/standalone_plugins/changed_packages/marker/dropped_architecture.py b/troubadix/standalone_plugins/changed_packages/marker/dropped_architecture.py index 0f913f6e..a610f273 100644 --- a/troubadix/standalone_plugins/changed_packages/marker/dropped_architecture.py +++ b/troubadix/standalone_plugins/changed_packages/marker/dropped_architecture.py @@ -46,6 +46,4 @@ def mark(cls, missing_packages: List[Package], new_packages: List[Package]): continue package.reasons[Reasons.DROPPED_ARCHITECTURE] = Direction.PASSIVE - other_package.reasons[Reasons.DROPPED_ARCHITECTURE] = ( - Direction.ACTIVE - ) + other_package.reasons[Reasons.DROPPED_ARCHITECTURE] = Direction.ACTIVE diff --git a/troubadix/standalone_plugins/changed_packages/package.py b/troubadix/standalone_plugins/changed_packages/package.py index f4c0b12a..fcb43ede 100644 --- a/troubadix/standalone_plugins/changed_packages/package.py +++ b/troubadix/standalone_plugins/changed_packages/package.py @@ -42,9 +42,7 @@ def from_cli_argument(cls, cli_argument: str): try: return cls[cli_argument.upper().replace("-", "_")] except KeyError as error: - raise ArgumentError( - None, f"Invalid reason '{cli_argument}'" - ) from error + raise ArgumentError(None, f"Invalid reason '{cli_argument}'") from error @dataclass() @@ -80,8 +78,7 @@ def __str__(self) -> str: result = f"{self.name : <50} {self.version : <40} {self.release : <10}" reasons = ", ".join( - f"{change}" - f"{' in new package' if direction == Direction.PASSIVE else ''}" + f"{change}" f"{' in new package' if direction == Direction.PASSIVE else ''}" for change, direction in self.reasons.items() ) result += f"{reasons : <10}" diff --git a/troubadix/standalone_plugins/dependency_graph/checks.py b/troubadix/standalone_plugins/dependency_graph/checks.py index de94486d..685f64b4 100644 --- a/troubadix/standalone_plugins/dependency_graph/checks.py +++ b/troubadix/standalone_plugins/dependency_graph/checks.py @@ -23,28 +23,21 @@ def check_duplicates(scripts: list[Script]) -> Result: return Result(name="duplicate dependency", warnings=warnings) -def check_missing_dependencies( - scripts: list[Script], graph: nx.DiGraph -) -> Result: +def check_missing_dependencies(scripts: list[Script], graph: nx.DiGraph) -> Result: """ Checks if any scripts that are depended on are missing from the list of scripts created from the local file system, logs the scripts dependending on the missing script """ errors = [] - dependency_names = { - dep.name for script in scripts for dep in script.dependencies - } + dependency_names = {dep.name for script in scripts for dep in script.dependencies} script_names = {script.name for script in scripts} missing_dependencies = dependency_names - script_names for missing in missing_dependencies: depending_scripts = graph.predecessors(missing) errors.append( - f"{missing}:" - + "".join( - f"\n - used by: {script}" for script in depending_scripts - ) + f"{missing}:" + "".join(f"\n - used by: {script}" for script in depending_scripts) ) return Result(name="missing dependency", errors=errors) @@ -63,9 +56,7 @@ def check_cycles(graph) -> Result: return Result(name="cyclic dependency", errors=errors) -def cross_feed_dependencies( - graph, is_enterprise_checked: bool -) -> list[tuple[str, str]]: +def cross_feed_dependencies(graph, is_enterprise_checked: bool) -> list[tuple[str, str]]: """ creates a list of script and dependency for scripts in community feed that depend on scripts in enterprise folders @@ -105,8 +96,7 @@ def check_category_order(graph) -> Result: problematic_edges = [ (dependent, dependency) for dependent, dependency in graph.edges() - if graph.nodes[dependent]["category"] - < graph.nodes[dependency].get("category", -1) + if graph.nodes[dependent]["category"] < graph.nodes[dependency].get("category", -1) ] errors = [ diff --git a/troubadix/standalone_plugins/dependency_graph/dependency_graph.py b/troubadix/standalone_plugins/dependency_graph/dependency_graph.py index d495c7a9..ba7df09b 100644 --- a/troubadix/standalone_plugins/dependency_graph/dependency_graph.py +++ b/troubadix/standalone_plugins/dependency_graph/dependency_graph.py @@ -34,9 +34,7 @@ from .cli import Feed, parse_args from .models import Dependency, Result, Script -DEPENDENCY_PATTERN = _get_special_script_tag_pattern( - "dependencies", flags=re.DOTALL | re.MULTILINE -) +DEPENDENCY_PATTERN = _get_special_script_tag_pattern("dependencies", flags=re.DOTALL | re.MULTILINE) CATEGORY_PATTERN = get_special_script_tag_pattern(SpecialScriptTag.CATEGORY) DEPRECATED_PATTERN = get_script_tag_pattern(ScriptTag.DEPRECATED) ENTERPRISE_FEED_CHECK_PATTERN = re.compile( @@ -84,9 +82,7 @@ def get_scripts(directory: Path) -> list[Script]: dependencies = extract_dependencies(content) category = extract_category(content) deprecated = bool(DEPRECATED_PATTERN.search(content)) - scripts.append( - Script(name, feed, dependencies, category, deprecated) - ) + scripts.append(Script(name, feed, dependencies, category, deprecated)) except Exception as e: logger.error(f"Error processing {path}: {e}") @@ -105,20 +101,16 @@ def extract_dependencies(content: str) -> list[Dependency]: dependencies = [] if_blocks = [ - (match.start(), match.end()) - for match in ENTERPRISE_FEED_CHECK_PATTERN.finditer(content) + (match.start(), match.end()) for match in ENTERPRISE_FEED_CHECK_PATTERN.finditer(content) ] for match in DEPENDENCY_PATTERN.finditer(content): start, end = match.span() is_enterprise_feed = any( - start >= block_start and end <= block_end - for block_start, block_end in if_blocks + start >= block_start and end <= block_end for block_start, block_end in if_blocks ) dep_list = split_dependencies(match.group("value")) - dependencies.extend( - Dependency(dep, is_enterprise_feed) for dep in dep_list - ) + dependencies.extend(Dependency(dep, is_enterprise_feed) for dep in dep_list) return dependencies diff --git a/troubadix/standalone_plugins/deprecate_vts.py b/troubadix/standalone_plugins/deprecate_vts.py index 3075f59b..99418468 100644 --- a/troubadix/standalone_plugins/deprecate_vts.py +++ b/troubadix/standalone_plugins/deprecate_vts.py @@ -42,9 +42,7 @@ class DeprecatedFile: def load_transition_oid_mapping(transition_file: Path) -> dict[str, str]: - spec = importlib.util.spec_from_file_location( - "transition_layer", transition_file - ) + spec = importlib.util.spec_from_file_location("transition_layer", transition_file) transition_layer = importlib.util.module_from_spec(spec) spec.loader.exec_module(transition_layer) @@ -151,9 +149,7 @@ def find_replacement_oid( file.content, ) if not oid_match: - raise ValueError( - f"No OID found in {file.name}. Cannot map to replacement OID." - ) + raise ValueError(f"No OID found in {file.name}. Cannot map to replacement OID.") oid = oid_match.group("value") replacement_oid = oid_mapping.get(oid) if not replacement_oid: @@ -181,9 +177,7 @@ def deprecate( output_path.mkdir(parents=True, exist_ok=True) for file in to_deprecate: if re.findall(KB_ITEMS_PATTERN, file.content): - logger.warning( - f"Unable to deprecate {file.name}. There are still KB keys remaining." - ) + logger.warning(f"Unable to deprecate {file.name}. There are still KB keys remaining.") continue replacement_oid = find_replacement_oid(file, oid_mapping) diff --git a/troubadix/standalone_plugins/file_extensions.py b/troubadix/standalone_plugins/file_extensions.py index 42d7c50e..475265e3 100644 --- a/troubadix/standalone_plugins/file_extensions.py +++ b/troubadix/standalone_plugins/file_extensions.py @@ -19,9 +19,7 @@ def parse_args() -> Namespace: type=directory_type_existing, help="directory that should be linted", ) - parser.add_argument( - "--ignore-file", type=file_type_existing, help="path to ignore file" - ) + parser.add_argument("--ignore-file", type=file_type_existing, help="path to ignore file") parser.add_argument( "--gen-ignore-entries", action="store_true", @@ -35,9 +33,7 @@ def create_exclusions(ignore_file: Path) -> set[Path]: return set() with open(ignore_file, "r", encoding="utf-8") as file: - return { - Path(line.strip()) for line in file if not re.match(r"^\s*#", line) - } + return {Path(line.strip()) for line in file if not re.match(r"^\s*#", line)} def check_extensions(args: Namespace) -> List[Path]: @@ -77,10 +73,7 @@ def main() -> int: print(file.relative_to(args.dir)) return 0 - print( - f"{len(unwanted_files)} " - "Files with unwanted file extension were found:" - ) + print(f"{len(unwanted_files)} " "Files with unwanted file extension were found:") for file in unwanted_files: print(file) return 1 diff --git a/troubadix/standalone_plugins/last_modification.py b/troubadix/standalone_plugins/last_modification.py index 5bfe133f..5fb2cdcd 100644 --- a/troubadix/standalone_plugins/last_modification.py +++ b/troubadix/standalone_plugins/last_modification.py @@ -48,9 +48,7 @@ def update(nasl_file: Path, terminal: Terminal): ) if not match_last_modification_any_value: - terminal.warning( - f'Ignoring "{nasl_file}" because it is missing a last_modification tag.' - ) + terminal.warning(f'Ignoring "{nasl_file}" because it is missing a last_modification tag.') return now = datetime.datetime.now(datetime.timezone.utc) @@ -71,9 +69,7 @@ def update(nasl_file: Path, terminal: Terminal): string=file_content, ) if not match_script_version: - terminal.warning( - f'Ignoring "{nasl_file}" because it is missing a script_version.' - ) + terminal.warning(f'Ignoring "{nasl_file}" because it is missing a script_version.') return # get that date formatted correctly: @@ -89,9 +85,7 @@ def update(nasl_file: Path, terminal: Terminal): def parse_args(args: Sequence[str] = None) -> Namespace: - parser = ArgumentParser( - description="Update script_version and last_modification tags" - ) + parser = ArgumentParser(description="Update script_version and last_modification tags") what_group = parser.add_mutually_exclusive_group(required=True) what_group.add_argument( "--files", diff --git a/troubadix/standalone_plugins/no_solution.py b/troubadix/standalone_plugins/no_solution.py index 298a8660..7726b2a0 100644 --- a/troubadix/standalone_plugins/no_solution.py +++ b/troubadix/standalone_plugins/no_solution.py @@ -53,9 +53,7 @@ def parse_solution_date(date_string: str) -> datetime: """Convert date string to date trying different formats""" - date_string = re.sub( - r"(?P.\d{1,2})(st|nd|rd|th)", r"\g", date_string - ) + date_string = re.sub(r"(?P.\d{1,2})(st|nd|rd|th)", r"\g", date_string) for strptime in SOLUTION_DATE_FORMATS: try: @@ -99,8 +97,7 @@ def parse_args() -> Namespace: dest="threshold", type=int, default=12, - help="The threshold after which to assume no solution " - "will be provided anymore", + help="The threshold after which to assume no solution " "will be provided anymore", ) parser.add_argument( @@ -118,10 +115,7 @@ def parse_args() -> Namespace: def check_skip_script(file_content: str) -> bool: solution_type = SOLUTION_TYPE_PATTERN.search(file_content) - if ( - solution_type - and solution_type.group("value") != SOLUTION_TYPE_NONE_AVAILABLE - ): + if solution_type and solution_type.group("value") != SOLUTION_TYPE_NONE_AVAILABLE: return True cvss = CVSS_PATTERN.search(file_content) @@ -148,9 +142,7 @@ def extract_tags(content: str) -> Optional[Tuple[str, datetime, datetime]]: if not creation_match: return None - creation_date = datetime.strptime( - creation_match.group("value")[:10], CREATION_DATE_FORMAT - ) + creation_date = datetime.strptime(creation_match.group("value")[:10], CREATION_DATE_FORMAT) oid_match = OID_PATTERN.search(content) if not oid_match: @@ -164,9 +156,7 @@ def extract_tags(content: str) -> Optional[Tuple[str, datetime, datetime]]: def get_no_solution_vts( files: Iterable[Path], ) -> Iterable[Tuple[Path, str, datetime, datetime]]: - file_contents = ( - (file, file.read_text(encoding=CURRENT_ENCODING)) for file in files - ) + file_contents = ((file, file.read_text(encoding=CURRENT_ENCODING)) for file in files) return ( (file, *extract_tags(content)) for file, content in file_contents @@ -191,22 +181,17 @@ def check_no_solutions( ( milestone for milestone in milestones - if solution_date - < creation_date + timedelta(days=milestone * MONTH_AS_DAYS) - and milestone * MONTH_AS_DAYS - <= (datetime.now() - creation_date).days + if solution_date < creation_date + timedelta(days=milestone * MONTH_AS_DAYS) + and milestone * MONTH_AS_DAYS <= (datetime.now() - creation_date).days ), None, ) - if solution_date > creation_date + timedelta( - days=last_milestone * MONTH_AS_DAYS - ): + if solution_date > creation_date + timedelta(days=last_milestone * MONTH_AS_DAYS): milestone = last_milestone if not milestone or ( - milestone == last_milestone - and (datetime.now() - solution_date) < snooze_duration + milestone == last_milestone and (datetime.now() - solution_date) < snooze_duration ): continue @@ -255,8 +240,7 @@ def print_report( ) else: term.bold_info( - f"{len(vts)} VTs with no solution for " - f"more than {milestone} month(s)" + f"{len(vts)} VTs with no solution for " f"more than {milestone} month(s)" ) for vt, oid, creation, solution in vts: @@ -265,9 +249,7 @@ def print_report( with term.indent(): term.print(f"OID: {oid}") term.print(f"Created: {creation.strftime('%Y-%m-%d')}") - term.print( - f"Last solution update: {solution.strftime('%Y-%m-%d')}" - ) + term.print(f"Last solution update: {solution.strftime('%Y-%m-%d')}") term.print() @@ -284,9 +266,7 @@ def main(): term = ConsoleTerminal() - print_info( - term, milestones, arguments.threshold, arguments.snooze, root - ) + print_info(term, milestones, arguments.threshold, arguments.snooze, root) summary = check_no_solutions(files, milestones, arguments.snooze) diff --git a/troubadix/standalone_plugins/version_updated.py b/troubadix/standalone_plugins/version_updated.py index fd04a7b7..362f0a34 100644 --- a/troubadix/standalone_plugins/version_updated.py +++ b/troubadix/standalone_plugins/version_updated.py @@ -31,9 +31,7 @@ ) from troubadix.standalone_plugins.common import git -SCRIPT_VERSION_PATTERN = re.compile( - r"^\+\s*" + SCRIPT_VERSION_ANY_VALUE_PATTERN, re.MULTILINE -) +SCRIPT_VERSION_PATTERN = re.compile(r"^\+\s*" + SCRIPT_VERSION_ANY_VALUE_PATTERN, re.MULTILINE) SCRIPT_LAST_MODIFICATION_PATTERN = re.compile( r"^\+\s*" + LAST_MODIFICATION_ANY_VALUE_PATTERN, re.MULTILINE ) @@ -88,9 +86,7 @@ def check_version_updated(files: List[Path], commit_range: str) -> bool: if not files: files = [ Path(f) - for f in git( - "diff", "--name-only", "--diff-filter=d", commit_range - ).splitlines() + for f in git("diff", "--name-only", "--diff-filter=d", commit_range).splitlines() ] rcode = True @@ -113,9 +109,7 @@ def check_version_updated(files: List[Path], commit_range: str) -> bool: ) if not SCRIPT_VERSION_PATTERN.search(text): - print( - f"{nasl_file}: Missing updated script_version", file=sys.stderr - ) + print(f"{nasl_file}: Missing updated script_version", file=sys.stderr) rcode = False if not SCRIPT_LAST_MODIFICATION_PATTERN.search(text): @@ -135,9 +129,7 @@ def main() -> int: git_base = git("rev-parse", "--show-toplevel") os.chdir(git_base.rstrip("\n")) except subprocess.SubprocessError: - print( - "Your current working directory doesn't belong to a git repository" - ) + print("Your current working directory doesn't belong to a git repository") return 1 parsed_args = parse_args(args) diff --git a/troubadix/troubadix.py b/troubadix/troubadix.py index 90c20bb8..c19410ee 100644 --- a/troubadix/troubadix.py +++ b/troubadix/troubadix.py @@ -98,10 +98,7 @@ def generate_patterns( def from_file(include_file: Path, term: Terminal) -> Iterable[Path]: """Parse the given file containing a list of files into""" try: - return [ - Path(f) - for f in include_file.read_text(encoding="utf-8").splitlines() - ] + return [Path(f) for f in include_file.read_text(encoding="utf-8").splitlines()] except FileNotFoundError: term.error(f"File {include_file} containing the file list not found.") sys.exit(1)