Skip to content

Commit

Permalink
Ruff: add and fix FBT001 & FBT003
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Jul 4, 2024
1 parent a309c71 commit 585face
Show file tree
Hide file tree
Showing 27 changed files with 118 additions and 108 deletions.
2 changes: 1 addition & 1 deletion dojo/engagement/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def close_engagement(eng):
eng.save()

if jira_helper.get_jira_project(eng):
jira_helper.close_epic(eng, True)
jira_helper.close_epic(eng, push_to_jira=True)


def reopen_engagement(eng):
Expand Down
2 changes: 1 addition & 1 deletion dojo/finding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,7 @@ def edit_template(request, tid):
extra_tags="alert-danger",
)

count = apply_cwe_mitigation(True, template, False)
count = apply_cwe_mitigation(apply_to_findings=True, template=template, update=False)
add_breadcrumb(title="Edit Template", top_level=False, request=request)
return render(
request,
Expand Down
2 changes: 2 additions & 0 deletions dojo/importers/auto_create_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def get_or_create_product(
self,
product_name: str = None,
product_type_name: str = None,
*,
auto_create_context: bool = False,
**kwargs: dict,
) -> Product:
Expand Down Expand Up @@ -279,6 +280,7 @@ def get_or_create_engagement(
engagement_name: str = None,
product_name: str = None,
product_type_name: str = None,
*,
auto_create_context: bool = False,
deduplication_on_engagement: bool = False,
source_code_management_uri: str = None,
Expand Down
1 change: 1 addition & 0 deletions dojo/importers/base_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ def mitigate_finding(
self,
finding: Finding,
note_message: str,
*,
finding_groups_enabled: bool,
) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion dojo/importers/default_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def close_old_findings(
"This finding has been automatically closed "
"as it is not present anymore in recent scans."
),
self.findings_groups_enabled,
finding_groups_enabled=self.findings_groups_enabled,
)
# push finding groups to jira since we only only want to push whole groups
if self.findings_groups_enabled and self.push_to_jira:
Expand Down
2 changes: 1 addition & 1 deletion dojo/importers/default_reimporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def close_old_findings(
self.mitigate_finding(
finding,
f"Mitigated by {self.test.test_type} re-upload.",
self.findings_groups_enabled,
finding_groups_enabled=self.findings_groups_enabled,
)
mitigated_findings.append(finding)
# push finding groups to jira since we only only want to push whole groups
Expand Down
1 change: 1 addition & 0 deletions dojo/importers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def validate(
self,
field_name: str,
expected_types: List[Callable] = [],
*,
required: bool = False,
default: Any = None,
**kwargs: dict,
Expand Down
2 changes: 1 addition & 1 deletion dojo/management/commands/push_to_jira_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def handle(self, *args, **options):

for finding in findings:
print("Checking issue:" + str(finding.id))
jira_helper.update_jira_issue(finding, True)
jira_helper.update_jira_issue(finding, *[True])
print("########\n")
6 changes: 4 additions & 2 deletions dojo/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ def query_counts(
:return: A method that takes period information to generate statistics for the given QuerySets
"""
def _aggregates_for_period(period: MetricsPeriod, period_count: int) -> dict[str, list[dict]]:
def _aggregate_data(qs: MetricsQuerySet, include_closed: bool = False) -> list[dict]:
def _aggregate_data(qs: MetricsQuerySet, *, include_closed: bool = False) -> list[dict]:
chart_data = partial(get_charting_data, start_date=start_date, period=period, period_count=period_count)
agg_qs = partial(aggregate_counts_by_period, period=period, metrics_type=metrics_type)
return chart_data(agg_qs(qs, include_closed=include_closed), include_closed=include_closed)
return {
'opened_per_period': _aggregate_data(open_qs, True),
'opened_per_period': _aggregate_data(open_qs, include_closed=True),
'active_per_period': _aggregate_data(active_qs),
'accepted_per_period': _aggregate_data(accepted_qs),
}
Expand Down Expand Up @@ -400,6 +400,7 @@ def get_charting_data(
start_date: date,
period: MetricsPeriod,
period_count: int,
*,
include_closed: bool,
) -> list[dict]:
"""
Expand Down Expand Up @@ -466,6 +467,7 @@ def aggregate_counts_by_period(
qs: MetricsQuerySet,
period: MetricsPeriod,
metrics_type: MetricsType,
*,
include_closed: bool,
) -> QuerySet:
"""
Expand Down
4 changes: 2 additions & 2 deletions dojo/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ def test_report(request, tid):
@user_is_authorized(Endpoint, Permissions.Endpoint_View, 'eid')
def endpoint_report(request, eid):
endpoint = get_object_or_404(Endpoint, id=eid)
return generate_report(request, endpoint, False)
return generate_report(request, endpoint, host_view=False)


@user_is_authorized(Endpoint, Permissions.Endpoint_View, 'eid')
def endpoint_host_report(request, eid):
endpoint = get_object_or_404(Endpoint, id=eid)
return generate_report(request, endpoint, True)
return generate_report(request, endpoint, host_view=True)


@user_is_authorized(Product, Permissions.Product_View, 'pid')
Expand Down
16 changes: 8 additions & 8 deletions dojo/risk_acceptance/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def expire_now(risk_acceptance):
finding.active = True
finding.risk_accepted = False
# Update any endpoint statuses on each of the findings
update_endpoint_statuses(finding, False)
update_endpoint_statuses(finding, accept_risk=False)

if risk_acceptance.restart_sla_expired:
finding.sla_start_date = timezone.now().date()
Expand Down Expand Up @@ -68,7 +68,7 @@ def reinstate(risk_acceptance, old_expiration_date):
finding.active = False
finding.risk_accepted = True
# Update any endpoint statuses on each of the findings
update_endpoint_statuses(finding, True)
update_endpoint_statuses(finding, accept_risk=True)
finding.save(dedupe_option=False)
reinstated_findings.append(finding)
else:
Expand All @@ -88,7 +88,7 @@ def delete(eng, risk_acceptance):
finding.active = True
finding.risk_accepted = False
# Update any endpoint statuses on each of the findings
update_endpoint_statuses(finding, False)
update_endpoint_statuses(finding, accept_risk=False)
finding.save(dedupe_option=False)

# best effort jira integration, no status changes
Expand All @@ -111,7 +111,7 @@ def remove_finding_from_risk_acceptance(risk_acceptance, finding):
finding.active = True
finding.risk_accepted = False
# Update any endpoint statuses on each of the findings
update_endpoint_statuses(finding, False)
update_endpoint_statuses(finding, accept_risk=False)
finding.save(dedupe_option=False)
# best effort jira integration, no status changes
post_jira_comments(risk_acceptance, [finding], unaccepted_message_creator)
Expand All @@ -124,7 +124,7 @@ def add_findings_to_risk_acceptance(risk_acceptance, findings):
finding.risk_accepted = True
finding.save(dedupe_option=False)
# Update any endpoint statuses on each of the findings
update_endpoint_statuses(finding, True)
update_endpoint_statuses(finding, accept_risk=True)
risk_acceptance.accepted_findings.add(finding)
risk_acceptance.save()

Expand Down Expand Up @@ -279,7 +279,7 @@ def simple_risk_accept(finding, perform_save=True):
# risk accepted, so finding no longer considered active
finding.active = False
# Update any endpoint statuses on each of the findings
update_endpoint_statuses(finding, True)
update_endpoint_statuses(finding, accept_risk=True)
if perform_save:
finding.save(dedupe_option=False)
# post_jira_comment might reload from database so see unaccepted finding. but the comment
Expand All @@ -297,7 +297,7 @@ def risk_unaccept(finding, perform_save=True):
finding.active = True
finding.risk_accepted = False
# Update any endpoint statuses on each of the findings
update_endpoint_statuses(finding, False)
update_endpoint_statuses(finding, accept_risk=False)
if perform_save:
logger.debug('saving unaccepted finding %i:%s', finding.id, finding)
finding.save(dedupe_option=False)
Expand All @@ -312,7 +312,7 @@ def remove_from_any_risk_acceptance(finding):
r.accepted_findings.remove(finding)


def update_endpoint_statuses(finding: Finding, accept_risk: bool) -> None:
def update_endpoint_statuses(finding: Finding, *, accept_risk: bool) -> None:
for status in finding.status_finding.all():
if accept_risk:
status.active = False
Expand Down
2 changes: 1 addition & 1 deletion dojo/settings/.settings.dist.py.sha256sum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cce215fa477d611d45cae69a29185e943eb209526fec2b38659666e5e9513fe3
09f9dea5143b9be4988917e7ddb28f24086b7d2cc1feb04a1e429bc0260f5847
16 changes: 8 additions & 8 deletions dojo/settings/settings.dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,14 +1085,14 @@ def saml2_attrib_map_format(dict):
# Celery settings
CELERY_BROKER_URL = env('DD_CELERY_BROKER_URL') \
if len(env('DD_CELERY_BROKER_URL')) > 0 else generate_url(
env('DD_CELERY_BROKER_SCHEME'),
True,
env('DD_CELERY_BROKER_USER'),
env('DD_CELERY_BROKER_PASSWORD'),
env('DD_CELERY_BROKER_HOST'),
env('DD_CELERY_BROKER_PORT'),
env('DD_CELERY_BROKER_PATH'),
env('DD_CELERY_BROKER_PARAMS'),
scheme=env('DD_CELERY_BROKER_SCHEME'),
double_slashes=True,
user=env('DD_CELERY_BROKER_USER'),
password=env('DD_CELERY_BROKER_PASSWORD'),
host=env('DD_CELERY_BROKER_HOST'),
port=env('DD_CELERY_BROKER_PORT'),
path=env('DD_CELERY_BROKER_PATH'),
params=env('DD_CELERY_BROKER_PARAMS'),
)
CELERY_TASK_IGNORE_RESULT = env('DD_CELERY_TASK_IGNORE_RESULT')
CELERY_RESULT_BACKEND = env('DD_CELERY_RESULT_BACKEND')
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/blackduck_component_risk/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def ingest_findings(self, components, securities, sources, test):
title = "Review " + self.license_title(component)
description = self.license_description(component, source)
severity = self.license_severity(component)
mitigation = self.license_mitigation(component, False)
mitigation = self.license_mitigation(component, violation=False)
impact = "N/A"
references = self.license_references(component)
finding = Finding(
Expand Down
16 changes: 8 additions & 8 deletions dojo/tools/qualys_webapp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,22 +351,22 @@ def get_unique_items(
findings = {}

for unique_id, finding in get_unique_vulnerabilities(
vulnerabilities, test, False, is_app_report,
vulnerabilities, test, is_info=False, is_app_report=is_app_report,
).items():
qid = int(finding.vuln_id_from_tool)
if qid in g_qid_list:
index = g_qid_list.index(qid)
findings[unique_id] = get_glossary_item(
glossary[index], finding, enable_weakness=enable_weakness,
glossary[index], finding, is_info=False, enable_weakness=enable_weakness,
)
for unique_id, finding in get_unique_vulnerabilities(
info_gathered, test, True, is_app_report,
info_gathered, test, is_info=True, is_app_report=is_app_report,
).items():
qid = int(finding.vuln_id_from_tool)
if qid in g_qid_list:
index = g_qid_list.index(qid)
finding = get_glossary_item(
glossary[index], finding, True, enable_weakness=enable_weakness,
glossary[index], finding, is_info=True, enable_weakness=enable_weakness,
)
if qid in ig_qid_list:
index = ig_qid_list.index(qid)
Expand All @@ -390,20 +390,20 @@ def get_items(
findings = {}

for qid, finding in get_vulnerabilities(
vulnerabilities, test, False, is_app_report,
vulnerabilities, test, is_info=False, is_app_report=is_app_report,
).items():
if qid in g_qid_list:
index = g_qid_list.index(qid)
findings[qid] = get_glossary_item(
glossary[index], finding, enable_weakness=enable_weakness,
glossary[index], finding, is_info=False, enable_weakness=enable_weakness,
)
for qid, finding in get_vulnerabilities(
info_gathered, test, True, is_app_report,
info_gathered, test, is_info=True, is_app_report=is_app_report,
).items():
if qid in g_qid_list:
index = g_qid_list.index(qid)
finding = get_glossary_item(
glossary[index], finding, True, enable_weakness=enable_weakness,
glossary[index], finding, is_info=True, enable_weakness=enable_weakness,
)
if qid in ig_qid_list:
index = ig_qid_list.index(qid)
Expand Down
6 changes: 3 additions & 3 deletions dojo/tools/xanitizer/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def generate_description(self, finding):
description = "{}\n**Starting at:** {} - **Line** {}".format(
description, startnode.get("classFQN"), startnode.get("lineNo"),
)
description = self.add_code(startnode, False, description)
description = self.add_code(startnode, showline=False, description=description)
description = "{}\n\n**Ending at:** {} - **Line** {}".format(
description, endnode.get("classFQN"), endnode.get("lineNo"),
)
description = self.add_code(endnode, True, description)
description = self.add_code(endnode, showline=True, description=description)
elif finding.find("node") is not None:
node = finding.find("node")
description = f"{description}\n-----\n"
Expand All @@ -126,7 +126,7 @@ def generate_description(self, finding):
description = f"{description}\n**Finding at:** {location} - **Line** {line}"
else:
description = f"{description}\n**Finding at:** {location}"
description = self.add_code(node, True, description)
description = self.add_code(node, showline=True, description=description)

return description

Expand Down
6 changes: 5 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ select = [
"ASYNC",
"TRIO",
"S2", "S5", "S7",
"FBT001", "FBT003",
"COM",
"C4",
"T10",
Expand Down Expand Up @@ -72,4 +73,7 @@ fixable = ["ALL"]
unfixable = []
preview = true

per-file-ignores = {}
per-file-ignores = {}

[lint.flake8-boolean-trap]
extend-allowed-calls = ["dojo.utils.get_system_setting"]
12 changes: 6 additions & 6 deletions tests/announcement_banner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_create_announcement(self):
self.assertFalse(self.is_element_by_css_selector_present('.announcement-banner'))

text = 'Big important announcement, definitely pay attention!'
self.enable_announcement(text, False, self.type)
self.enable_announcement(text, dismissable=False, style=self.type)
self.assertTrue(self.is_success_message_present('Announcement updated successfully.'))

self.assertTrue(self.is_element_by_css_selector_present(f'.announcement-banner.alert-{self.type.lower()}', text=text))
Expand All @@ -59,7 +59,7 @@ def test_create_dismissable_announcement(self):
self.assertFalse(self.is_element_by_css_selector_present('.announcement-banner'))

text = 'Big important announcement, definitely pay don\'t dismiss this one.'
self.enable_announcement(text, True, self.type)
self.enable_announcement(text, dismissable=True, style=self.type)
self.assertTrue(self.is_success_message_present('Announcement updated successfully.'))

self.assertTrue(self.is_element_by_css_selector_present(f'.announcement-banner.alert-{self.type.lower()}', text=text))
Expand All @@ -80,7 +80,7 @@ def test_dismissing_announcement_does_not_dismiss_for_others(self):
self.assertFalse(self.is_element_by_css_selector_present('.announcement-banner'))

text = 'Everyone sees this, right?'
self.enable_announcement(text, True, self.type)
self.enable_announcement(text, dismissable=True, style=self.type)
self.assertTrue(self.is_success_message_present('Announcement updated successfully.'))

self.assertTrue(self.is_element_by_css_selector_present(f'.announcement-banner.alert-{self.type.lower()}', text=text))
Expand All @@ -106,7 +106,7 @@ def test_announcement_ui_disabled_when_set(self):
self.assertFalse(self.is_element_by_css_selector_present('.announcement-banner'))

text = 'The most important announcement of the year.'
self.enable_announcement(text, False, self.type)
self.enable_announcement(text, dismissable=False, style=self.type)
self.assertTrue(self.is_success_message_present('Announcement updated successfully.'))

self.assertTrue(self.is_element_by_css_selector_present(f'.announcement-banner.alert-{self.type.lower()}', text=text))
Expand All @@ -124,7 +124,7 @@ def test_announcement_empty_after_removal(self):
self.assertFalse(self.is_element_by_css_selector_present('.announcement-banner'))

text = 'Surely no-one would delete this announcement quickly'
self.enable_announcement(text, False, self.type)
self.enable_announcement(text, dismissable=False, style=self.type)
self.assertTrue(self.is_success_message_present('Announcement updated successfully.'))

self.assertTrue(self.is_element_by_css_selector_present(f'.announcement-banner.alert-{self.type.lower()}', text=text))
Expand All @@ -142,7 +142,7 @@ def test_html_announcement(self):
self.assertFalse(self.is_element_by_css_selector_present('.announcement-banner'))

text = "Links in announcements? <a href='https://github.com/DefectDojo/django-DefectDojo' style='color: #224477;' target='_blank'>you bet!</a>"
self.enable_announcement(text, False, self.type)
self.enable_announcement(text, dismissable=False, style=self.type)
self.assertTrue(self.is_success_message_present('Announcement updated successfully.'))

driver.find_element(By.XPATH, "//div[contains(@class, 'announcement-banner')]/a[@href='https://github.com/DefectDojo/django-DefectDojo' and @style='color: #224477;' and @target='_blank']")
Expand Down
2 changes: 1 addition & 1 deletion tests/base_test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def setUpClass(cls):
dd_driver_options.add_argument("--window-size=1280,1024")
# dd_driver_options.add_argument("--start-maximized")

dd_driver_options.set_capability("acceptInsecureCerts", True)
dd_driver_options.set_capability(name="acceptInsecureCerts", value=True)

# some extra logging can be turned on if you want to query the browser javascripe console in your tests
desired = webdriver.DesiredCapabilities.CHROME
Expand Down
Loading

0 comments on commit 585face

Please sign in to comment.