Skip to content

Commit b55c609

Browse files
authored
Test Types: Return support for disabling test types via the active flag (#10562)
* Simplify checks for inactive test types * Accommodate fixtures
1 parent c827ab8 commit b55c609

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

dojo/tools/factory.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,38 @@ def get_parser(scan_type):
3939
raise ValueError(msg)
4040
rg = re.compile(settings.PARSER_EXCLUDE)
4141
if not rg.match(scan_type) or settings.PARSER_EXCLUDE.strip() == "":
42-
# update DB dynamicaly
42+
# update DB dynamically
4343
test_type, _ = Test_Type.objects.get_or_create(name=scan_type)
4444
if test_type.active:
4545
return PARSERS[scan_type]
4646
msg = f"Parser {scan_type} is not active"
4747
raise ValueError(msg)
4848

4949

50+
def get_inactive_test_types():
51+
try:
52+
return list(Test_Type.objects.filter(active=False).values_list("name", flat=True))
53+
except Exception:
54+
# This exception is reached in the event of loading fixtures in to an empty database
55+
# prior to migrations runnings
56+
return []
57+
58+
5059
def get_scan_types_sorted():
5160
res = []
61+
inactive_test_types = get_inactive_test_types()
5262
for key in PARSERS:
53-
res.append((key, PARSERS[key].get_description_for_scan_types(key)))
63+
if key not in inactive_test_types:
64+
res.append((key, PARSERS[key].get_description_for_scan_types(key)))
5465
return sorted(res, key=lambda x: x[0].lower())
5566

5667

5768
def get_choices_sorted():
5869
res = []
70+
inactive_test_types = get_inactive_test_types()
5971
for key in PARSERS:
60-
res.append((key, key))
72+
if key not in inactive_test_types:
73+
res.append((key, key))
6174
return sorted(res, key=lambda x: x[1].lower())
6275

6376

@@ -74,8 +87,9 @@ def requires_file(scan_type):
7487

7588
def get_api_scan_configuration_hints():
7689
res = []
90+
inactive_test_types = get_inactive_test_types()
7791
for name, parser in PARSERS.items():
78-
if hasattr(parser, "api_scan_configuration_hint"):
92+
if name not in inactive_test_types and hasattr(parser, "api_scan_configuration_hint"):
7993
scan_types = parser.get_scan_types()
8094
for scan_type in scan_types:
8195
tool_type = parser.requires_tool_type(scan_type)

0 commit comments

Comments
 (0)