Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ruff): Fix RUF039 for v0.8.0 #11326

Merged
merged 1 commit into from
Dec 4, 2024
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/management/commands/rename_mend_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def rename_mend_finding():
logger.info("######## Updating Hashcodes - deduplication is done in the background upon finding save ########")
for finding in findings:
logger.info("Updating Mend Finding with id: %d", finding.id)
lib_name_begin = re.search("\\*\\*Library Filename\\*\\* : ", finding.description).span(0)[1]
lib_name_end = re.search("\\*\\*Library Description\\*\\*", finding.description).span(0)[0]
lib_name_begin = re.search(r"\*\*Library Filename\*\* : ", finding.description).span(0)[1]
lib_name_end = re.search(r"\*\*Library Description\*\*", finding.description).span(0)[0]
lib_name = finding.description[lib_name_begin:lib_name_end - 1]
if finding.cve is None:
finding.title = "CVE-None | " + lib_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def parse_initial_date(self, finding: Finding, value: str) -> None:
#####
# For parsing CVEs
#####
CVE_PATTERN = re.compile("CVE-[0-9]+-[0-9]+", re.IGNORECASE)
CVE_PATTERN = re.compile(r"CVE-[0-9]+-[0-9]+", re.IGNORECASE)

def is_cve(self, c: str) -> bool:
return bool(c and isinstance(c, str) and self.CVE_PATTERN.fullmatch(c))
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/burp_enterprise/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _set_or_append_content(self, finding_details: dict, header: str, div_element
cleaned_item = item.split(":")[0]
if (
finding_details["cwe"] is None
and (cwe_search := re.search("CWE-([0-9]*)", cleaned_item, re.IGNORECASE))
and (cwe_search := re.search(r"CWE-([0-9]*)", cleaned_item, re.IGNORECASE))
):
finding_details["cwe"] = int(cwe_search.group(1))
if "vulnerability_ids" not in finding_details:
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/burp_graphql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def parse_evidence(self, evidence):

def get_cwe(self, cwe_html):
# Match only the first CWE!
cweSearch = re.search("CWE-([0-9]*)", cwe_html, re.IGNORECASE)
cweSearch = re.search(r"CWE-([0-9]*)", cwe_html, re.IGNORECASE)
if cweSearch:
return cweSearch.group(1)
return 0
2 changes: 1 addition & 1 deletion dojo/tools/microfocus_webinspect/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def convert_severity(val):
@staticmethod
def get_cwe(val):
# Match only the first CWE!
cweSearch = re.search("CWE-(\\d+)", val, re.IGNORECASE)
cweSearch = re.search(r"CWE-(\d+)", val, re.IGNORECASE)
if cweSearch:
return int(cweSearch.group(1))
return 0
2 changes: 1 addition & 1 deletion dojo/tools/nexpose/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def get_items(self, tree, vulns, test):
"severity": "Info",
"tags": [
re.sub(
"[^A-Za-z0-9]+",
r"[^A-Za-z0-9]+",
"-",
service.get("name").lower(),
).rstrip("-"),
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/npm_audit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def censor_path_hashes(path):
if not path:
return None

return re.sub("[a-f0-9]{64}", "censored_by_npm_audit", path)
return re.sub(r"[a-f0-9]{64}", "censored_by_npm_audit", path)


def get_item(item_node, test):
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/qualys_webapp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def truncate_str(value: str, maxlen: int):

# Parse 'CWE-XXXX' format to strip just the numbers
def get_cwe(cwe):
cweSearch = re.search("CWE-([0-9]*)", cwe, re.IGNORECASE)
cweSearch = re.search(r"CWE-([0-9]*)", cwe, re.IGNORECASE)
if cweSearch:
return cweSearch.group(1)
return 0
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/sarif/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_message_from_multiformatMessageString(data, rule):

def cve_try(val):
# Match only the first CVE!
cveSearch = re.search("(CVE-[0-9]+-[0-9]+)", val, re.IGNORECASE)
cveSearch = re.search(r"(CVE-[0-9]+-[0-9]+)", val, re.IGNORECASE)
if cveSearch:
return cveSearch.group(1).upper()
return None
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/sonarqube/soprasteria_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_references(self, rule_name, vuln_details):

def get_cwe(self, vuln_references):
# Match only the first CWE!
cweSearch = re.search("CWE-([0-9]*)", vuln_references, re.IGNORECASE)
cweSearch = re.search(r"CWE-([0-9]*)", vuln_references, re.IGNORECASE)
if cweSearch:
return cweSearch.group(1)
return 0
Expand Down
4 changes: 2 additions & 2 deletions dojo/tools/trivy_operator/uniform_vulnid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def return_uniformed_vulnid(self, vulnid):
if "cve" in vulnid.lower():
return vulnid
if "khv" in vulnid.lower():
temp = re.compile("([a-zA-Z-_]+)([0-9]+)")
temp = re.compile(r"([a-zA-Z-_]+)([0-9]+)")
number = str(temp.match(vulnid).groups()[1]).zfill(3)
avd_category = str(temp.match(vulnid.lower()).groups()[0])
return avd_category.upper() + number
if "ksv" in vulnid.lower() or "kcv" in vulnid.lower():
temp = re.compile("([a-zA-Z-_]+)([0-9]+)")
temp = re.compile(r"([a-zA-Z-_]+)([0-9]+)")
number = str(temp.match(vulnid).groups()[1]).zfill(4)
avd_category = str(temp.match(vulnid.lower().replace("_", "").replace("-", "")).groups()[0].replace("avd", ""))
return "AVD-" + avd_category.upper() + "-" + number
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/veracode/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def __xml_dynamic_flaw_to_finding(
@staticmethod
def _get_cwe(val):
# Match only the first CWE!
cweSearch = re.search("CWE-(\\d+)", val, re.IGNORECASE)
cweSearch = re.search(r"CWE-(\d+)", val, re.IGNORECASE)
if cweSearch:
return int(cweSearch.group(1))
return None
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/wapiti/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_findings(self, file, test):
@staticmethod
def get_cwe(val):
# Match only the first CWE!
cweSearch = re.search("CWE-(\\d+)", val, re.IGNORECASE)
cweSearch = re.search(r"CWE-(\d+)", val, re.IGNORECASE)
if cweSearch:
return int(cweSearch.group(1))
return None
4 changes: 2 additions & 2 deletions dojo/user/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_help_text(self):

class UppercaseValidator:
def validate(self, password, user=None):
if not re.findall("[A-Z]", password) and get_system_setting("uppercase_character_required"):
if not re.findall(r"[A-Z]", password) and get_system_setting("uppercase_character_required"):
raise ValidationError(
self.get_help_text(),
code="password_no_upper")
Expand All @@ -57,7 +57,7 @@ def get_help_text(self):

class LowercaseValidator:
def validate(self, password, user=None):
if not re.findall("[a-z]", password) and get_system_setting("lowercase_character_required"):
if not re.findall(r"[a-z]", password) and get_system_setting("lowercase_character_required"):
raise ValidationError(
self.get_help_text(),
code="password_no_lower")
Expand Down
2 changes: 1 addition & 1 deletion requirements-lint.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruff==0.7.4
ruff==0.8.0
6 changes: 3 additions & 3 deletions tests/Import_scanner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def test_engagement_import_scan_result(self):
options_text = [scan.strip() for scan in options_text]

mod_options = options_text
mod_options = [re.sub(" Scanner", "", scan) for scan in mod_options]
mod_options = [re.sub(" Scan", "", scan) for scan in mod_options]
mod_options = [re.sub(r" Scanner", "", scan) for scan in mod_options]
mod_options = [re.sub(r" Scan", "", scan) for scan in mod_options]
mod_options = [scan.lower().replace("-", " ").replace(".", "") for scan in mod_options]

acronyms = []
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_engagement_import_scan_result(self):
driver.find_element(By.ID, "id_file").send_keys(test_location)
driver.find_element(By.CSS_SELECTOR, "input.btn.btn-primary").click()
EngagementTXT = "".join(driver.find_element(By.TAG_NAME, "BODY").text).split("\n")
reg = re.compile("processed, a total of")
reg = re.compile(r"processed, a total of")
matches = list(filter(reg.search, EngagementTXT))
if len(matches) != 1:
failed_tests += [test.upper() + " - " + case + ": Not imported"]
Expand Down