diff --git a/.flake8 b/.flake8 index df8b8c2c9c2..cccf6cce296 100644 --- a/.flake8 +++ b/.flake8 @@ -16,8 +16,6 @@ ignore = E128 # Line break occurred before a binary operator (conflicting with black) W503 - # undefined file name excpetion - F821 # We should not touch migrations that are already used, but check new migrations per-file-ignores = diff --git a/dojo/engagement/views.py b/dojo/engagement/views.py index f28a0863fb9..e680a18ef71 100644 --- a/dojo/engagement/views.py +++ b/dojo/engagement/views.py @@ -20,6 +20,7 @@ from django.shortcuts import get_object_or_404, render from django.urls import Resolver404, reverse from django.utils import timezone +from django.utils.translation import gettext as _ from django.views import View from django.views.decorators.cache import cache_page from django.views.decorators.vary import vary_on_cookie diff --git a/dojo/jira_link/views.py b/dojo/jira_link/views.py index 80065f78add..2a9a0af206e 100644 --- a/dojo/jira_link/views.py +++ b/dojo/jira_link/views.py @@ -13,6 +13,7 @@ from django.urls import reverse from django.utils import timezone from django.utils.dateparse import parse_datetime +from django.utils.translation import gettext as _ from django.views import View from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST diff --git a/dojo/management/commands/jira_async_updates.py b/dojo/management/commands/jira_async_updates.py index e85afdc1776..a1530ec1c86 100644 --- a/dojo/management/commands/jira_async_updates.py +++ b/dojo/management/commands/jira_async_updates.py @@ -2,6 +2,7 @@ from django.utils import timezone from jira.exceptions import JIRAError +import dojo.jira_link.helper as jira_helper from dojo.models import Dojo_User, Finding, Notes, User """ diff --git a/dojo/management/commands/rename_mend_findings.py b/dojo/management/commands/rename_mend_findings.py index 336988e64c1..6c1baacc2e5 100644 --- a/dojo/management/commands/rename_mend_findings.py +++ b/dojo/management/commands/rename_mend_findings.py @@ -1,7 +1,14 @@ +import logging +import re + from django.core.management.base import BaseCommand from pytz import timezone from dojo.celery import app +from dojo.models import Finding, Test_Type +from dojo.utils import get_system_setting + +logger = logging.getLogger(__name__) locale = timezone(get_system_setting('time_zone')) diff --git a/dojo/management/commands/test_celery_decorator.py b/dojo/management/commands/test_celery_decorator.py index 6fe77e02348..6899147cc1a 100644 --- a/dojo/management/commands/test_celery_decorator.py +++ b/dojo/management/commands/test_celery_decorator.py @@ -1,13 +1,18 @@ +import logging from functools import wraps from django.core.management.base import BaseCommand -# from dojo.utils import get_system_setting, do_dedupe_finding, dojo_async_task from dojo.celery import app + +# from dojo.utils import get_system_setting, do_dedupe_finding, dojo_async_task +from dojo.decorators import dojo_async_task, dojo_model_from_id, dojo_model_to_id from dojo.models import Finding, Notes from dojo.utils import test_valentijn +logger = logging.getLogger(__name__) + class Command(BaseCommand): help = "Command to do some tests with celery and decorators. Just committing it so 'we never forget'" diff --git a/dojo/settings/settings.py b/dojo/settings/settings.py index 2d378c742f7..d848ad9ef31 100644 --- a/dojo/settings/settings.py +++ b/dojo/settings/settings.py @@ -12,7 +12,7 @@ optional('local_settings.py'), ) -if not (DEBUG or ('collectstatic' in sys.argv)): +if not (DEBUG or ('collectstatic' in sys.argv)): # noqa: F821 - not declared DEBUG is acceptable because we are sure it will be loaded from 'include' with (Path(__file__).parent / 'settings.dist.py').open('rb') as file: real_hash = hashlib.sha256(file.read()).hexdigest() with (Path(__file__).parent / '.settings.dist.py.sha256sum').open('rb') as file: diff --git a/dojo/tools/qualys/csv_parser.py b/dojo/tools/qualys/csv_parser.py index 98a8ec00af9..16ad062fc69 100644 --- a/dojo/tools/qualys/csv_parser.py +++ b/dojo/tools/qualys/csv_parser.py @@ -4,6 +4,7 @@ import re from datetime import datetime +from dateutil import parser from django.conf import settings from dojo.models import Endpoint, Finding diff --git a/dojo/tools/qualys_webapp/parser.py b/dojo/tools/qualys_webapp/parser.py index 47be5bb9482..db07fc1bd4d 100644 --- a/dojo/tools/qualys_webapp/parser.py +++ b/dojo/tools/qualys_webapp/parser.py @@ -2,6 +2,7 @@ import re import xml.etree.ElementTree from datetime import datetime +from urllib.parse import urlparse from dojo.models import Endpoint, Finding diff --git a/ruff.toml b/ruff.toml index 30a62e2c0c1..84218675861 100644 --- a/ruff.toml +++ b/ruff.toml @@ -65,7 +65,7 @@ select = [ "NPY", "AIR", ] -ignore = ["E501", "E722", "F821"] +ignore = ["E501", "E722"] # Allow autofix for all enabled rules (when `--fix`) is provided. fixable = ["ALL"] diff --git a/tests/Import_scanner_test.py b/tests/Import_scanner_test.py index 2a9f1701194..7265c6a061f 100644 --- a/tests/Import_scanner_test.py +++ b/tests/Import_scanner_test.py @@ -1,3 +1,4 @@ +# ruff: noqa: F821 import os import re import shutil @@ -10,6 +11,8 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select +dir_path = os.path.dirname(os.path.realpath(__file__)) + class ScannerTest(BaseTestCase): def setUp(self): @@ -51,34 +54,6 @@ def test_check_test_file(self): print() assert len(missing_tests) == 0 - def test_check_for_doc(self): - driver = self.driver - driver.get('https://documentation.defectdojo.com/integrations/import/') - integration_index = integration_text.index('Integrations') + len('Integrations') + 1 - usage_index = integration_text.index('Usage Examples') - len('Models') - 2 - integration_text = integration_text[integration_index:usage_index].lower() - integration_text = integration_text.replace('_', ' ').replace('-', ' ').replace('.', '').split('\n') - acronyms = [] - for words in integration_text: - acronyms += ["".join(word[0] for word in words.split())] - - missing_docs = [] - for tool in self.tools: - reg = re.compile('.*' + tool.replace('_', ' ') + '.*') - if len(list(filter(reg.search, integration_text))) < 1: - if len(list(filter(reg.search, acronyms))) < 1: - missing_docs += [tool] - - if len(missing_docs) > 0: - print('The following scanners are missing documentation') - print('Names must match those listed in /dojo/tools') - print('Documentation can be added here:') - print('https://github.com/DefectDojo/django-DefectDojo/tree/dev/docs\n') - for tool in missing_docs: - print(tool) - print() - assert len(missing_docs) == 0 - def test_check_for_forms(self): forms_path = dir_path[:-5] + 'dojo/forms.py' file = open(forms_path, 'r+') diff --git a/tests/zap.py b/tests/zap.py index db0f77bf3d9..fbaf96a65c6 100755 --- a/tests/zap.py +++ b/tests/zap.py @@ -2,6 +2,7 @@ import collections import re import socket +import sys import time from urllib.parse import urlparse @@ -53,7 +54,7 @@ class Main: loginUrl = "http://os.environ['DD_BASE_URL']/login" # loginUrlregex = "\Q" + loginUrl + "\E.*" # The above line is flake8 violation as \Q and \E are not supported by python - loginURLregex = re.escape(loginURL) + loginURLregex = re.escape(loginUrl) result = zap.context.exclude_from_context(contextname, ".*logout.*", apikey) result = zap.context.exclude_from_context(contextname, ".*/static/.*", apikey) diff --git a/unittests/test_parsers.py b/unittests/test_parsers.py index 53af54d17a0..c43f5b5d594 100644 --- a/unittests/test_parsers.py +++ b/unittests/test_parsers.py @@ -82,6 +82,7 @@ def test_file_existence(self): f = os.path.join(basedir, 'dojo', 'tools', parser_dir.name, file.name) read_true = False with open(f) as f: + i = 0 for line in f.readlines(): if read_true is True: if ('"utf-8"' in str(line) or "'utf-8'" in str(line) or '"utf-8-sig"' in str(line) or "'utf-8-sig'" in str(line)) and i <= 4: diff --git a/unittests/tools/test_api_sonarqube_parser.py b/unittests/tools/test_api_sonarqube_parser.py index d9963d1fb77..9d5035ac26a 100644 --- a/unittests/tools/test_api_sonarqube_parser.py +++ b/unittests/tools/test_api_sonarqube_parser.py @@ -11,7 +11,7 @@ Tool_Type, ) from dojo.tools.api_sonarqube.parser import ApiSonarQubeParser -from unittests.dojo_test_case import DojoTestCase +from unittests.dojo_test_case import DojoTestCase, get_unit_tests_path def dummy_product(self, *args, **kwargs):