Skip to content

Commit 3a25728

Browse files
authored
Merge pull request #10677 from DefectDojo/bugfix
Bugfix -> Dev for 2.37.0
2 parents e2f4445 + 3fd43db commit 3a25728

File tree

10 files changed

+116
-52
lines changed

10 files changed

+116
-52
lines changed

dojo/filters.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,6 +2886,17 @@ class ReportFindingFilterHelper(FilterSet):
28862886
outside_of_sla = FindingSLAFilter(label="Outside of SLA")
28872887
file_path = CharFilter(lookup_expr="icontains")
28882888

2889+
o = OrderingFilter(
2890+
fields=(
2891+
("title", "title"),
2892+
("date", "date"),
2893+
("numerical_severity", "numerical_severity"),
2894+
("epss_score", "epss_score"),
2895+
("epss_percentile", "epss_percentile"),
2896+
("test__engagement__product__name", "test__engagement__product__name"),
2897+
),
2898+
)
2899+
28892900
class Meta:
28902901
model = Finding
28912902
# exclude sonarqube issue as by default it will show all without checking permissions

dojo/reports/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def report_findings(request):
175175
title_words = get_words_for_field(Finding, "title")
176176
component_words = get_words_for_field(Finding, "component_name")
177177

178-
paged_findings = get_page_items(request, findings.qs.distinct().order_by("numerical_severity"), 25)
178+
paged_findings = get_page_items(request, findings.qs.distinct(), 25)
179179

180180
return render(request,
181181
"dojo/report_findings.html",

dojo/templates/dojo/report_builder.html

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -272,52 +272,73 @@ <h4>Available Widgets</h4>
272272
.selectpicker('render');
273273
}
274274

275-
$(document).on('submit', 'form.finding-list', function (event) {
276-
var form = this;
277-
$.get("{% url 'report_findings' %}?" + $(this).serialize()).done(function (data) {
275+
// Retrieves (report) data at the given url and inserts it as HTMl into $targetEl, and configures filters
276+
// on the returned data.
277+
function retrieveReportData(url, $targetEl) {
278+
$.get(url).done(function (data) {
278279
filterFieldInit(
279-
$(form).closest('li.finding-list').html(data)
280+
$targetEl.html(data)
280281
);
281282
setUpFindingFilters();
282283
});
284+
}
285+
286+
// --------
287+
// Findings
288+
// --------
283289

290+
// "Apply Filters"
291+
$(document).on('submit', 'form.finding-list', function (event) {
292+
const $form = $(this);
284293
event.preventDefault();
294+
retrieveReportData(
295+
"{% url 'report_findings' %}?" + $form.serialize(),
296+
$form.closest('li.finding-list')
297+
);
285298
});
286299

287-
$(document).on('click', 'form.finding-list a.clear.centered, div.finding-pagination a', function (event) {
288-
$.get("{% url 'report_findings' %}").done(function (data) {
289-
filterFieldInit(
290-
$('div.in-use-widgets li.finding-list').html(data)
291-
);
292-
setUpFindingFilters();
293-
});
300+
// "Clear filters"
301+
$(document).on('click', 'form.finding-list a.clear.centered', function (event) {
302+
const $a = $(this);
303+
event.preventDefault();
304+
retrieveReportData("{% url 'report_findings' %}", $a.closest('li.finding-list'));
305+
});
294306

307+
// Sort/order columns and Pagination
308+
$(document).on('click', 'li.finding-list th a, div.finding-pagination a', function (event) {
309+
const $a = $(this);
295310
event.preventDefault();
311+
retrieveReportData("{% url 'report_findings' %}" + $a.attr('href'), $a.closest('li.finding-list'));
296312
});
297313

298-
$(document).on('submit', 'form.endpoint-list', function (event) {
299-
var form = this;
300-
$.get("{% url 'report_endpoints' %}?" + $(this).serialize()).done(function (data) {
301-
filterFieldInit(
302-
$(form).closest('li.endpoint-list').html(data)
303-
);
304-
setUpFindingFilters();
305-
});
314+
/// --------
315+
// Endpoints
316+
// ---------
306317

318+
// "Apply filters"
319+
$(document).on('submit', 'form.endpoint-list', function (event) {
320+
const $form = $(this);
307321
event.preventDefault();
322+
retrieveReportData(
323+
"{% url 'report_endpoints' %}?" + $form.serialize(),
324+
$form.closest('li.endpoint-list')
325+
);
308326
});
309327

310-
$(document).on('click', 'form.endpoint-list a.clear.centered, div.endpoint-pagination a', function (event) {
311-
$.get("{% url 'report_endpoints' %}").done(function (data) {
312-
filterFieldInit(
313-
$('div.in-use-widgets li.endpoint-list').html(data)
314-
);
315-
setUpFindingFilters();
316-
});
317-
328+
// "Clear filters"
329+
$(document).on('click', 'form.endpoint-list a.clear.centered', function (event) {
330+
const $a = $(this);
318331
event.preventDefault();
332+
retrieveReportData("{% url 'report_endpoints' %}", $a.closest('li.endpoint-list'));
319333
});
320334

335+
// Pagination
336+
$(document).on('click', 'div.endpoint-pagination a', function (event) {
337+
const $a = $(this);
338+
event.preventDefault();
339+
retrieveReportData("{% url 'report_endpoints' %}" + $a.attr('href'), $a.closest('li.endpoint-list'));
340+
})
341+
321342
$('[data-toggle="tooltip"]').tooltip()
322343

323344
$(document).on('click', '.in-use-widgets .panel-available-widget .panel-heading', function (event) {

dojo/templates/dojo/report_endpoints.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ <h6>Filters</h6>
4747
</tbody>
4848
</table>
4949
</div>
50-
<div class="clearfix">
51-
{% include "dojo/paging_snippet.html" with page=findings page_size=False %}
50+
<div class="clearfix endpoint-pagination">
51+
{% include "dojo/paging_snippet.html" with page=endpoints page_size=False %}
5252
</div>
5353

5454
{% endif %}

dojo/templates/dojo/report_findings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h6>Filters</h6>
6262
</tbody>
6363
</table>
6464
</div>
65-
<div class="clearfix">
65+
<div class="clearfix finding-pagination">
6666
{% include "dojo/paging_snippet.html" with page=findings page_size=False %}
6767
</div>
6868

dojo/templates/dojo/view_group.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% load authorization_tags %}
44

55
{% block content %}
6-
<h3 id="id_heading"> Group {{ group.name }}</h3>
6+
<h3 id="id_heading"> Group: {{ group.name }}</h3>
77
<div class="row">
88
<div id="tests" class="col-md-8">
99
<div class="panel panel-default">
@@ -43,7 +43,7 @@ <h3 class="pull-left">Description</h3>
4343
<div class="panel panel-default">
4444
<div class="panel-heading">
4545
<div class="clearfix">
46-
<h4 class="pull-left">Members</h4>
46+
<h4 class="pull-left">Members of this Group</h4>
4747
&nbsp;
4848
<a href="https://documentation.defectdojo.com/usage/permissions/#groups" target="_blank">
4949
<i class="fa-solid fa-circle-question"></i></a>
@@ -72,7 +72,7 @@ <h4 class="pull-left">Members</h4>
7272
<tr>
7373
<th label="Actions"></th>
7474
<th>User</th>
75-
<th>Group role</th>
75+
<th>Role in this Group</th>
7676
</tr>
7777
</thead>
7878
<tbody>
@@ -108,15 +108,15 @@ <h4 class="pull-left">Members</h4>
108108
</div>
109109
{% else %}
110110
<div class="panel-body">
111-
<small class="text-muted"><em>No members found.</em></small>
111+
<small class="text-muted"><em>This Group has no members.</em></small>
112112
</div>
113113
{% endif %}
114114
</div>
115115

116116
<div class="panel panel-default">
117117
<div class="panel-heading">
118118
<div class="clearfix">
119-
<h4 class="pull-left">Product Type Groups</h4>
119+
<h4 class="pull-left">Product Types this Group can access</h4>
120120
&nbsp;
121121
<a href="https://documentation.defectdojo.com/usage/permissions/" target="_blank">
122122
<i class="fa-solid fa-circle-question"></i></a>
@@ -182,15 +182,15 @@ <h4 class="pull-left">Product Type Groups</h4>
182182
</div>
183183
{% else %}
184184
<div class="panel-body">
185-
<small class="text-muted"><em>No product type groups found.</em></small>
185+
<small class="text-muted"><em>This Group cannot access any Product Types.</em></small>
186186
</div>
187187
{% endif %}
188188
</div>
189189

190190
<div class="panel panel-default">
191191
<div class="panel-heading">
192192
<div class="clearfix">
193-
<h4 class="pull-left">Product Groups</h4>
193+
<h4 class="pull-left">Products this Group can access</h4>
194194
&nbsp;
195195
<a href="https://documentation.defectdojo.com/usage/permissions/" target="_blank">
196196
<i class="fa-solid fa-circle-question"></i></a>
@@ -256,7 +256,7 @@ <h4 class="pull-left">Product Groups</h4>
256256
</div>
257257
{% else %}
258258
<div class="panel-body">
259-
<small class="text-muted"><em>No product groups found.</em></small>
259+
<small class="text-muted"><em>This Group cannot access any Products.</em></small>
260260
</div>
261261
{% endif %}
262262
</div>

dojo/templates/dojo/view_user.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{% block content %}
77
{{ block.super }}
8-
<h3 id="id_heading">{% blocktrans with full_name=user.get_full_name %}User {{ full_name }}{% endblocktrans %}</h3>
8+
<h3 id="id_heading">{% blocktrans with full_name=user.get_full_name %}User: {{ full_name }}{% endblocktrans %}</h3>
99
<div class="row">
1010
<div id="tests" class="col-md-8">
1111
<div class="panel panel-default">
@@ -104,7 +104,7 @@ <h4 class="pull-left">{% trans "Contact Information" %}</h4>
104104
<div class="panel panel-default">
105105
<div class="panel-heading">
106106
<div class="clearfix">
107-
<h4 class="pull-left">{% trans "Product Type Membership" %}</h4>
107+
<h4 class="pull-left">{% trans "Product Types this User can access" %}</h4>
108108
&nbsp;
109109
<a href="https://documentation.defectdojo.com/usage/permissions/" target="_blank">
110110
<i class="fa-solid fa-circle-question"></i></a>
@@ -170,14 +170,14 @@ <h4 class="pull-left">{% trans "Product Type Membership" %}</h4>
170170
</div>
171171
{% else %}
172172
<div class="panel-body">
173-
<small class="text-muted"><em>{% trans "No product type members found." %}</em></small>
173+
<small class="text-muted"><em>{% trans "This User is not assigned to any Product Types." %}</em></small>
174174
</div>
175175
{% endif %}
176176
</div>
177177
<div class="panel panel-default">
178178
<div class="panel-heading">
179179
<div class="clearfix">
180-
<h4 class="pull-left">{% trans "Product Membership" %}</h4>
180+
<h4 class="pull-left">{% trans "Products this User can access" %}</h4>
181181
&nbsp;
182182
<a href="https://documentation.defectdojo.com/usage/permissions/" target="_blank">
183183
<i class="fa-solid fa-circle-question"></i></a>
@@ -243,15 +243,15 @@ <h4 class="pull-left">{% trans "Product Membership" %}</h4>
243243
</div>
244244
{% else %}
245245
<div class="panel-body">
246-
<small class="text-muted"><em>{% trans "No product members found." %}</em></small>
246+
<small class="text-muted"><em>{% trans "This User is not assigned to any Products." %}</em></small>
247247
</div>
248248
{% endif %}
249249
</div>
250250

251251
<div class="panel panel-default">
252252
<div class="panel-heading">
253253
<div class="clearfix">
254-
<h4 class="pull-left">{% trans "Group Membership" %}</h4>
254+
<h4 class="pull-left">{% trans "Groups this User is a member of" %}</h4>
255255
&nbsp;
256256
<a href="https://documentation.defectdojo.com/usage/permissions/#groups" target="_blank">
257257
<i class="fa-solid fa-circle-question"></i></a>
@@ -280,7 +280,7 @@ <h4 class="pull-left">{% trans "Group Membership" %}</h4>
280280
<tr>
281281
<th></th>
282282
<th>{% trans "Group" %}</th>
283-
<th>{% trans "Group role" %}</th>
283+
<th>{% trans "Role in this Group" %}</th>
284284
</tr>
285285
</thead>
286286
<tbody>
@@ -317,7 +317,7 @@ <h4 class="pull-left">{% trans "Group Membership" %}</h4>
317317
</div>
318318
{% else %}
319319
<div class="panel-body">
320-
<small class="text-muted"><em>{% trans "No group members found." %}</em></small>
320+
<small class="text-muted"><em>{% trans "This User is not a member of any Groups." %}</em></small>
321321
</div>
322322
{% endif %}
323323
</div>

dojo/tools/bearer_cli/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dojo.models import Finding
44

55

6-
class BearerParser:
6+
class BearerCLIParser:
77
"""
88
Bearer CLI tool is a SAST scanner for multiple languages
99
"""

unittests/test_factory.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
import logging
2+
import os
3+
from importlib import import_module
4+
from importlib.util import find_spec
5+
from inspect import isclass
6+
17
from dojo.models import Test, Test_Type
28
from dojo.tools.factory import get_parser
9+
from unittests.dojo_test_case import DojoTestCase, get_unit_tests_path
310

4-
from .dojo_test_case import DojoTestCase, get_unit_tests_path
11+
logger = logging.getLogger(__name__)
512

613

714
class TestFactory(DojoTestCase):
@@ -53,3 +60,28 @@ def test_get_parser_test_active_in_db(self):
5360
)
5461
parser = get_parser(scan_type)
5562
self.assertIsNotNone(parser)
63+
64+
def test_parser_name_matches_module(self):
65+
"""Test to ensure that parsers' class names match their module names"""
66+
package_dir = "dojo/tools"
67+
module_names = os.listdir(package_dir)
68+
missing_parsers = []
69+
excluded_parsers = [
70+
"wizcli_common_parsers", # common class for other wizcli parsers, there is not parsing here
71+
]
72+
for module_name in module_names:
73+
if module_name in excluded_parsers:
74+
continue
75+
if os.path.isdir(os.path.join(package_dir, module_name)):
76+
found = False
77+
if find_spec(f"dojo.tools.{module_name}.parser"):
78+
module = import_module(f"dojo.tools.{module_name}.parser")
79+
for attribute_name in dir(module):
80+
attribute = getattr(module, attribute_name)
81+
if isclass(attribute) and attribute_name.lower() == module_name.replace("_", "") + "parser":
82+
found = True
83+
if not found and module_name != "__pycache__":
84+
missing_parsers.append(module_name)
85+
if len(missing_parsers) > 0:
86+
logger.error(f"Parsers with invalid names: {missing_parsers}")
87+
self.assertEqual(0, len(missing_parsers))

unittests/tools/test_bearer_cli_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from django.test import TestCase
22

33
from dojo.models import Test
4-
from dojo.tools.bearer_cli.parser import BearerParser
4+
from dojo.tools.bearer_cli.parser import BearerCLIParser
55

66

77
class TestBearerParser(TestCase):
88

99
def test_bearer_parser_with_one_vuln_has_one_findings(self):
1010
testfile = open("unittests/scans/bearer_cli/bearer_cli_one_vul.json")
11-
parser = BearerParser()
11+
parser = BearerCLIParser()
1212
findings = parser.get_findings(testfile, Test())
1313
testfile.close()
1414
self.assertEqual(1, len(findings))
@@ -22,7 +22,7 @@ def test_bearer_parser_with_one_vuln_has_one_findings(self):
2222

2323
def test_bearer_parser_with_many_vuln_has_many_findings(self):
2424
testfile = open("unittests/scans/bearer_cli/bearer_cli_many_vul.json")
25-
parser = BearerParser()
25+
parser = BearerCLIParser()
2626
findings = parser.get_findings(testfile, Test())
2727
testfile.close()
2828
self.assertEqual(4, len(findings))

0 commit comments

Comments
 (0)