launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #33181
[Merge] ~pelpsi/lp-archive:archive-ruff-security-checks into lp-archive:main
Simone Pelosi has proposed merging ~pelpsi/lp-archive:archive-ruff-security-checks into lp-archive:main.
Commit message:
Added ruff configuration for security
Replaced assertion usage in the codebase with if-else statement.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~pelpsi/lp-archive/+git/lp-archive/+merge/494899
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/lp-archive:archive-ruff-security-checks into lp-archive:main.
diff --git a/lp_archive/archive.py b/lp_archive/archive.py
index 0941ffb..abc0851 100644
--- a/lp_archive/archive.py
+++ b/lp_archive/archive.py
@@ -95,7 +95,11 @@ def translate_path_get_http_response(
else:
current_app.logger.info("%s %s: %s", archive, path, f.faultString)
return "Internal server error", 500, {"Content-Type": "text/plain"}
- assert isinstance(url, str)
+ if not isinstance(url, str):
+ current_app.logger.error(
+ "%s %s: translatePath returned non-string: %r", archive, path, url
+ )
+ return "Internal server error", 500, {"Content-Type": "text/plain"}
headers = {"Location": url}
headers.update(get_extra_headers(path, live_at))
return "", 307, headers
diff --git a/pyproject.toml b/pyproject.toml
index a8f43fe..f0d5882 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,2 +1,24 @@
[tool.black]
line-length = 79
+
+[tool.ruff]
+line-length = 79
+target-version = "py38"
+
+[tool.ruff.lint]
+select = [
+ "S", # flake8-bandit - Security testing
+]
+
+# Exclude test files and other directories
+exclude = [
+ "tests/",
+ "test_*.py",
+ "*_test.py",
+ ".git",
+ ".venv",
+ "__pycache__",
+ ".tox",
+ "build/",
+ "dist/",
+]