Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dojo/api_v2/prefetch/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .prefetcher import _Prefetcher
from .utils import _get_prefetchable_fields
from .utils import get_prefetchable_fields


def _get_path_to_GET_serializer_map(generator):
Expand Down Expand Up @@ -53,7 +53,7 @@ def prefetch_postprocessing_hook(result, generator, request, public):
if parameter["name"] == "prefetch":
prefetcher = _Prefetcher()

fields = _get_prefetchable_fields(
fields = get_prefetchable_fields(
serializer_classes[path](),
)

Expand Down
2 changes: 1 addition & 1 deletion dojo/api_v2/prefetch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _is_one_to_one_relation(field):
return isinstance(field, related.ForwardManyToOneDescriptor)


def _get_prefetchable_fields(serializer):
def get_prefetchable_fields(serializer):
"""
Get the fields that are prefetchable according to the serializer description.
Method mainly used by for automatic schema generation.
Expand Down
2 changes: 1 addition & 1 deletion dojo/endpoint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.db.models import Count, Q
from django.http import HttpResponseRedirect
from django.urls import reverse
from hyperlink._url import SCHEME_PORT_MAP
from hyperlink._url import SCHEME_PORT_MAP # noqa: PLC2701

from dojo.models import DojoMeta, Endpoint

Expand Down
18 changes: 9 additions & 9 deletions dojo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _manage_inherited_tags(obj, incoming_inherited_tags, potentially_existing_ta
obj.tags.set(cleaned_tag_list)


def _copy_model_util(model_in_database, exclude_fields: list[str] | None = None):
def copy_model_util(model_in_database, exclude_fields: list[str] | None = None):
if exclude_fields is None:
exclude_fields = []
new_model_instance = model_in_database.__class__()
Expand Down Expand Up @@ -750,7 +750,7 @@ class NoteHistory(models.Model):
current_editor = models.ForeignKey(Dojo_User, editable=False, null=True, on_delete=models.CASCADE)

def copy(self):
copy = _copy_model_util(self)
copy = copy_model_util(self)
copy.save()
return copy

Expand All @@ -776,7 +776,7 @@ def __str__(self):
return self.entry

def copy(self):
copy = _copy_model_util(self)
copy = copy_model_util(self)
# Save the necessary ManyToMany relationships
old_history = list(self.history.all())
# Save the object before setting any ManyToMany relationships
Expand All @@ -801,7 +801,7 @@ def delete(self, *args, **kwargs):
storage.delete(path)

def copy(self):
copy = _copy_model_util(self)
copy = copy_model_util(self)
# Add unique modifier to file name
copy.title = f"{self.title} - clone-{str(uuid4())[:8]}"
# Create new unique file name
Expand Down Expand Up @@ -1581,7 +1581,7 @@ def get_absolute_url(self):
return reverse("view_engagement", args=[str(self.id)])

def copy(self):
copy = _copy_model_util(self)
copy = copy_model_util(self)
# Save the necessary ManyToMany relationships
old_notes = list(self.notes.all())
old_files = list(self.files.all())
Expand Down Expand Up @@ -1699,7 +1699,7 @@ def __str__(self):
return f"'{self.finding}' on '{self.endpoint}'"

def copy(self, finding=None):
copy = _copy_model_util(self)
copy = copy_model_util(self)
current_endpoint = self.endpoint
if finding:
copy.finding = finding
Expand Down Expand Up @@ -2161,7 +2161,7 @@ def get_breadcrumbs(self):
return bc

def copy(self, engagement=None):
copy = _copy_model_util(self)
copy = copy_model_util(self)
# Save the necessary ManyToMany relationships
old_notes = list(self.notes.all())
old_files = list(self.files.all())
Expand Down Expand Up @@ -2827,7 +2827,7 @@ def get_absolute_url(self):
return reverse("view_finding", args=[str(self.id)])

def copy(self, test=None):
copy = _copy_model_util(self)
copy = copy_model_util(self)
# Save the necessary ManyToMany relationships
old_notes = list(self.notes.all())
old_files = list(self.files.all())
Expand Down Expand Up @@ -3804,7 +3804,7 @@ def engagement(self):
return None

def copy(self, engagement=None):
copy = _copy_model_util(self)
copy = copy_model_util(self)
# Save the necessary ManyToMany relationships
old_notes = list(self.notes.all())
old_accepted_findings_hash_codes = [finding.hash_code for finding in self.accepted_findings.all()]
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/nexpose/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import html2text
from defusedxml import ElementTree
from django.conf import settings
from hyperlink._url import SCHEME_PORT_MAP
from hyperlink._url import SCHEME_PORT_MAP # noqa: PLC2701

from dojo.models import Endpoint, Finding

Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/tenable/xml_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from cvss import CVSS3
from defusedxml import ElementTree
from hyperlink._url import SCHEME_PORT_MAP
from hyperlink._url import SCHEME_PORT_MAP # noqa: PLC2701

from dojo.models import Endpoint, Finding, Test

Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ select = [
"D2", "D3", "D402", "D403", "D405", "D406", "D407", "D408", "D409", "D410", "D411", "D412", "D413", "D414", "D416",
"F",
"PGH",
"PLC0", "PLC1", "PLC24", "PLC28", "PLC3",
"PLC",
"PLE",
"PLR01", "PLR02", "PLR04", "PLR0915", "PLR1711", "PLR1704", "PLR1714", "PLR1716", "PLR172", "PLR173", "PLR2044", "PLR5", "PLR6104", "PLR6201",
"PLW",
Expand Down
8 changes: 4 additions & 4 deletions unittests/test_deduplication_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
System_Settings,
Test,
User,
_copy_model_util,
copy_model_util,
)

from .dojo_test_case import DojoTestCase
Expand Down Expand Up @@ -1199,7 +1199,7 @@ def log_summary(self, product=None, engagement=None, test=None):

def copy_and_reset_finding(self, find_id):
org = Finding.objects.get(id=find_id)
new = _copy_model_util(org)
new = copy_model_util(org)
new.duplicate = False
new.duplicate_finding = None
new.active = True
Expand Down Expand Up @@ -1236,13 +1236,13 @@ def copy_and_reset_finding_add_endpoints(self, find_id, *, static=False, dynamic

def copy_and_reset_test(self, test_id):
org = Test.objects.get(id=test_id)
new = _copy_model_util(org)
new = copy_model_util(org)
# return unsaved new finding and reloaded existing finding
return new, Test.objects.get(id=test_id)

def copy_and_reset_engagement(self, eng_id):
org = Engagement.objects.get(id=eng_id)
new = _copy_model_util(org)
new = copy_model_util(org)
# return unsaved new finding and reloaded existing finding
return new, Engagement.objects.get(id=eng_id)

Expand Down
10 changes: 5 additions & 5 deletions unittests/test_duplication_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.test.utils import override_settings

from dojo.management.commands.fix_loop_duplicates import fix_loop_duplicates
from dojo.models import Engagement, Finding, Product, User, _copy_model_util
from dojo.models import Engagement, Finding, Product, User, copy_model_util
from dojo.utils import set_duplicate

from .dojo_test_case import DojoTestCase
Expand All @@ -27,19 +27,19 @@ def run(self, result=None):
super().run(result)

def setUp(self):
self.finding_a = _copy_model_util(Finding.objects.get(id=2), exclude_fields=["duplicate_finding"])
self.finding_a = copy_model_util(Finding.objects.get(id=2), exclude_fields=["duplicate_finding"])
self.finding_a.title = "A: " + self.finding_a.title
self.finding_a.duplicate = False
self.finding_a.hash_code = None
self.finding_a.save()

self.finding_b = _copy_model_util(Finding.objects.get(id=3), exclude_fields=["duplicate_finding"])
self.finding_b = copy_model_util(Finding.objects.get(id=3), exclude_fields=["duplicate_finding"])
self.finding_b.title = "B: " + self.finding_b.title
self.finding_b.duplicate = False
self.finding_b.hash_code = None
self.finding_b.save()

self.finding_c = _copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"])
self.finding_c = copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"])
self.finding_c.pk = None
self.finding_c.title = "C: " + self.finding_c.title
self.finding_c.duplicate = False
Expand Down Expand Up @@ -262,7 +262,7 @@ def test_loop_relations_for_three(self):

# Another loop-test for 4 findings
def test_loop_relations_for_four(self):
self.finding_d = _copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"])
self.finding_d = copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"])
self.finding_d.duplicate = False
self.finding_d.save()

Expand Down
10 changes: 5 additions & 5 deletions unittests/test_false_positive_history_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
System_Settings,
Test,
User,
_copy_model_util,
copy_model_util,
)

from .dojo_test_case import DojoTestCase
Expand Down Expand Up @@ -1719,7 +1719,7 @@ def log_summary(self, product=None, engagement=None, test=None):

def copy_and_reset_finding(self, find_id):
org = Finding.objects.get(id=find_id)
new = _copy_model_util(org)
new = copy_model_util(org)
new.duplicate = False
new.duplicate_finding = None
new.false_p = False
Expand All @@ -1730,19 +1730,19 @@ def copy_and_reset_finding(self, find_id):

def copy_and_reset_test(self, test_id):
org = Test.objects.get(id=test_id)
new = _copy_model_util(org)
new = copy_model_util(org)
# return unsaved new test and reloaded existing test
return new, Test.objects.get(id=test_id)

def copy_and_reset_engagement(self, eng_id):
org = Engagement.objects.get(id=eng_id)
new = _copy_model_util(org)
new = copy_model_util(org)
# return unsaved new engagement and reloaded existing engagement
return new, Engagement.objects.get(id=eng_id)

def copy_and_reset_product(self, prod_id):
org = Product.objects.get(id=prod_id)
new = _copy_model_util(org)
new = copy_model_util(org)
new.name = f"{org.name} (Copy {datetime.now()})"
# return unsaved new product and reloaded existing product
return new, Product.objects.get(id=prod_id)
Expand Down
6 changes: 3 additions & 3 deletions unittests/test_rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from dojo.api_v2.mixins import DeletePreviewModelMixin
from dojo.api_v2.prefetch import PrefetchListMixin, PrefetchRetrieveMixin
from dojo.api_v2.prefetch.utils import _get_prefetchable_fields
from dojo.api_v2.prefetch.utils import get_prefetchable_fields
from dojo.api_v2.views import (
AnnouncementViewSet,
AppAnalysisViewSet,
Expand Down Expand Up @@ -416,7 +416,7 @@ def test_detail(self):
@skipIfNotSubclass(PrefetchRetrieveMixin)
def test_detail_prefetch(self):
# print("=======================================================")
prefetchable_fields = [x[0] for x in _get_prefetchable_fields(self.viewset.serializer_class)]
prefetchable_fields = [x[0] for x in get_prefetchable_fields(self.viewset.serializer_class)]

current_objects = self.client.get(self.url, format="json").data
relative_url = self.url + "{}/".format(current_objects["results"][0]["id"])
Expand Down Expand Up @@ -508,7 +508,7 @@ def test_list(self):

@skipIfNotSubclass(PrefetchListMixin)
def test_list_prefetch(self):
prefetchable_fields = [x[0] for x in _get_prefetchable_fields(self.viewset.serializer_class)]
prefetchable_fields = [x[0] for x in get_prefetchable_fields(self.viewset.serializer_class)]

response = self.client.get(self.url, data={
"prefetch": ",".join(prefetchable_fields),
Expand Down
10 changes: 5 additions & 5 deletions unittests/test_utils_deduplication_reopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from dojo.management.commands.fix_loop_duplicates import fix_loop_duplicates
from dojo.models import Finding, _copy_model_util
from dojo.models import Finding, copy_model_util
from dojo.utils import set_duplicate

from .dojo_test_case import DojoTestCase
Expand All @@ -14,27 +14,27 @@ class TestDuplicationReopen(DojoTestCase):
fixtures = ["dojo_testdata.json"]

def setUp(self):
self.finding_a = _copy_model_util(Finding.objects.get(id=2), exclude_fields=["duplicate_finding"])
self.finding_a = copy_model_util(Finding.objects.get(id=2), exclude_fields=["duplicate_finding"])
self.finding_a.duplicate = False
self.finding_a.mitigated = datetime.datetime(1970, 1, 1, tzinfo=datetime.UTC)
self.finding_a.is_mitigated = True
self.finding_a.false_p = True
self.finding_a.active = False
self.finding_a.save()

self.finding_b = _copy_model_util(Finding.objects.get(id=3), exclude_fields=["duplicate_finding"])
self.finding_b = copy_model_util(Finding.objects.get(id=3), exclude_fields=["duplicate_finding"])
self.finding_a.active = True
self.finding_b.duplicate = False
self.finding_b.save()

self.finding_c = _copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"])
self.finding_c = copy_model_util(Finding.objects.get(id=4), exclude_fields=["duplicate_finding"])
self.finding_c.duplicate = False
self.finding_c.out_of_scope = True
self.finding_c.active = False
logger.debug("creating finding_c")
self.finding_c.save()

self.finding_d = _copy_model_util(Finding.objects.get(id=5), exclude_fields=["duplicate_finding"])
self.finding_d = copy_model_util(Finding.objects.get(id=5), exclude_fields=["duplicate_finding"])
self.finding_d.duplicate = False
logger.debug("creating finding_d")
self.finding_d.save()
Expand Down