diff --git a/dojo/pipeline.py b/dojo/pipeline.py index befabc0e836..91dc1500089 100644 --- a/dojo/pipeline.py +++ b/dojo/pipeline.py @@ -107,7 +107,7 @@ def update_azure_groups(backend, uid, user=None, social=None, *args, **kwargs): def is_group_id(group): - return bool(re.search("^[a-zA-Z0-9]{8,}-[a-zA-Z0-9]{4,}-[a-zA-Z0-9]{4,}-[a-zA-Z0-9]{4,}-[a-zA-Z0-9]{12,}$", group)) + return bool(re.search(r"^[a-zA-Z0-9]{8,}-[a-zA-Z0-9]{4,}-[a-zA-Z0-9]{4,}-[a-zA-Z0-9]{4,}-[a-zA-Z0-9]{12,}$", group)) def assign_user_to_groups(user, group_names, social_provider): diff --git a/dojo/tools/crashtest_security/parser.py b/dojo/tools/crashtest_security/parser.py index deedb916b81..a12c194723a 100644 --- a/dojo/tools/crashtest_security/parser.py +++ b/dojo/tools/crashtest_security/parser.py @@ -185,7 +185,7 @@ def get_items(self, tree, test): title = re.sub(r" \([0-9]*\)$", "", title) # Attache CVEs - vulnerability_id = re.findall("CVE-\\d{4}-\\d{4,10}", title)[0] if "CVE" in title else None + vulnerability_id = re.findall(r"CVE-\d{4}-\d{4,10}", title)[0] if "CVE" in title else None description = failure.get("message") severity = failure.get("type").capitalize() diff --git a/dojo/tools/factory.py b/dojo/tools/factory.py index 04930321c50..b69fea12ac0 100644 --- a/dojo/tools/factory.py +++ b/dojo/tools/factory.py @@ -115,7 +115,7 @@ def requires_tool_type(scan_type): # iterate through the modules in the current package package_dir = str(Path(__file__).resolve().parent) -for module_name in os.listdir(package_dir): +for module_name in os.listdir(package_dir): # noqa: PTH208 # check if it's dir if Path(os.path.join(package_dir, module_name)).is_dir(): try: diff --git a/requirements-lint.txt b/requirements-lint.txt index 25336e7513c..8f161d317ec 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -1 +1 @@ -ruff==0.8.0 +ruff==0.8.1 \ No newline at end of file diff --git a/tests/Import_scanner_test.py b/tests/Import_scanner_test.py index 07da3dfc125..7f2e3abd9bd 100644 --- a/tests/Import_scanner_test.py +++ b/tests/Import_scanner_test.py @@ -28,9 +28,10 @@ def setUp(self): git.Repo.clone_from("https://github.com/DefectDojo/sample-scan-files", self.repo_path) self.remove_items = ["__init__.py", "__init__.pyc", "factory.py", "factory.pyc", "factory.py", "LICENSE", "README.md", ".gitignore", ".git", "__pycache__"] - tool_path = dir_path[:-5] + "dojo/tools" - tools = sorted(os.listdir(tool_path)) - tests = sorted(os.listdir(self.repo_path)) + tool_path = Path(dir_path[:-5] + "dojo/tools") + tools = sorted(any(tool_path.iterdir())) + p = Path(self.repo_path) + tests = sorted(any(p.iterdir())) self.tools = [i for i in tools if i not in self.remove_items] self.tests = [i for i in tests if i not in self.remove_items] @@ -43,7 +44,8 @@ def test_check_test_file(self): missing_tests += ["\nNO TEST FILES"] for test in self.tests: - cases = sorted(os.listdir(self.repo_path + "/" + test)) + p = Path(self.repo_path + "/" + test) + cases = sorted(any(p.iterdir())) cases = [i for i in cases if i not in self.remove_items] if len(cases) == 0 and tool not in missing_tests: missing_tests += [test] @@ -145,8 +147,8 @@ def test_engagement_import_scan_result(self): options_text = [scan.strip() for scan in options_text] mod_options = options_text - mod_options = [re.sub(r" Scanner", "", scan) for scan in mod_options] - mod_options = [re.sub(r" Scan", "", scan) for scan in mod_options] + mod_options = [scan.replace(" Scanner", "") for scan in mod_options] + mod_options = [scan.replace(" Scan", "") for scan in mod_options] mod_options = [scan.lower().replace("-", " ").replace(".", "") for scan in mod_options] acronyms = [] @@ -180,7 +182,8 @@ def test_engagement_import_scan_result(self): failed_tests = [] for test in self.tests: - cases = sorted(os.listdir(self.repo_path + "/" + test)) + p = Path(self.repo_path + "/" + test) + cases = sorted(any(p.iterdir())) cases = [i for i in cases if i not in self.remove_items] if len(cases) == 0: failed_tests += [test.upper() + ": No test cases"] diff --git a/unittests/test_factory.py b/unittests/test_factory.py index 43fb5b54771..5d8b4040dd5 100644 --- a/unittests/test_factory.py +++ b/unittests/test_factory.py @@ -64,8 +64,8 @@ def test_get_parser_test_active_in_db(self): def test_parser_name_matches_module(self): """Test to ensure that parsers' class names match their module names""" - package_dir = "dojo/tools" - module_names = os.listdir(package_dir) + package_dir = Path("dojo/tools") + module_names = package_dir.iterdir() missing_parsers = [] excluded_parsers = [ "wizcli_common_parsers", # common class for other wizcli parsers, there is not parsing here