diff --git a/fuzz/fuzz_runtime_ingest.py b/fuzz/fuzz_runtime_ingest.py index 0f23ad7..c0382ca 100644 --- a/fuzz/fuzz_runtime_ingest.py +++ b/fuzz/fuzz_runtime_ingest.py @@ -40,7 +40,7 @@ def check(data: bytes) -> None: for table in _INGEST_TABLES: - _repo.connection.execute(f"DELETE FROM {table}") # noqa: S608 -- fixed table names + _repo.connection.execute(f"DELETE FROM {table}") # fixed table names, not input _repo.connection.commit() lines = data.decode("utf-8", errors="replace").splitlines() # exactly as post_events decodes lines = _with_app_env(lines, "fuzz-app", "fuzz-env") diff --git a/pyproject.toml b/pyproject.toml index 09918ae..6da24ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,6 +109,11 @@ packages = ["src/secfoo"] [tool.pytest.ini_options] testpaths = ["tests"] +[tool.ruff] +# Adversarial and fuzz fixtures are exact byte inputs, checked by SHA-256 +# (scripts/adversarial_eval.py corpus_digest); lint must never rewrite them. +extend-exclude = ["tests/fixtures"] + [tool.ruff.lint.flake8-bugbear] # typer.Option and FastAPI's Form are designed to be used as parameter # defaults (they describe the parameter, they aren't shared mutable state), diff --git a/src/secfoo/agents/__init__.py b/src/secfoo/agents/__init__.py index 0bf63df..97ddec7 100644 --- a/src/secfoo/agents/__init__.py +++ b/src/secfoo/agents/__init__.py @@ -1,4 +1,4 @@ from secfoo.agents.base import AgentAdapter, AgentResult from secfoo.agents.registry import ADAPTERS, get_adapter -__all__ = ["AgentAdapter", "AgentResult", "ADAPTERS", "get_adapter"] +__all__ = ["ADAPTERS", "AgentAdapter", "AgentResult", "get_adapter"] diff --git a/src/secfoo/agents/registry.py b/src/secfoo/agents/registry.py index 9303107..c285007 100644 --- a/src/secfoo/agents/registry.py +++ b/src/secfoo/agents/registry.py @@ -4,8 +4,8 @@ from secfoo.agents.api import ApiAdapter from secfoo.agents.base import AgentAdapter from secfoo.agents.claude import ClaudeAdapter -from secfoo.agents.copilot import CopilotAdapter from secfoo.agents.codex import CodexAdapter +from secfoo.agents.copilot import CopilotAdapter from secfoo.agents.cursor import CursorAdapter from secfoo.agents.devin import DevinAdapter from secfoo.agents.droid import DroidAdapter diff --git a/src/secfoo/cli.py b/src/secfoo/cli.py index fd0eb49..25cfbef 100644 --- a/src/secfoo/cli.py +++ b/src/secfoo/cli.py @@ -8,7 +8,7 @@ from datetime import date, datetime, timezone from enum import Enum from pathlib import Path -from typing import Annotated, Optional +from typing import Annotated import typer from rich.console import Console @@ -113,7 +113,7 @@ def _now_iso() -> str: return datetime.now(timezone.utc).isoformat() -def _validate_date(value: Optional[str]) -> Optional[str]: +def _validate_date(value: str | None) -> str | None: """Typer callback for the `--expires-at` / `--discovered-at` style options that are documented as YYYY-MM-DD: rejects anything that doesn't parse as that shape at input time. @@ -294,7 +294,7 @@ def run( help="Skip the confirmation before running a skill that isn't a built-in or a file under " "~/.secfoo/skills/ (a non-interactive run, e.g. --json or CI, always skips it).", )] = False, - target: Optional[str] = typer.Option( + target: str | None = typer.Option( None, "--target", "-t", help="GitHub URL or local directory. Defaults to the current directory." ), confluence: list[str] = typer.Option( @@ -306,7 +306,7 @@ def run( "SharePoint, Notion, Google Docs) or a local Markdown, text, PDF, DOCX or PPTX file or " "folder. Repeatable, and added on top of [defaults].context in ~/.secfoo/config.toml.", )] = None, - agent: Optional[AgentId] = typer.Option( + agent: AgentId | None = typer.Option( None, "--agent", "-a", @@ -314,7 +314,7 @@ def run( "~/.secfoo/config.toml, then to claude.", ), model: str | None = typer.Option(None, "--model", help="Model for this run; overrides [agents.].model."), - depth: Optional[DepthId] = typer.Option( + depth: DepthId | None = typer.Option( None, "--depth", "-d", @@ -322,19 +322,19 @@ def run( "standard: thorough, full checklist coverage, takes longer. Falls back to " "[defaults].depth in ~/.secfoo/config.toml, then to quick.", ), - timeout: Optional[int] = typer.Option( + timeout: int | None = typer.Option( None, "--timeout", help="Per-skill timeout in seconds. Falls back to [defaults].timeout in " "~/.secfoo/config.toml, then to the agent's own default.", ), - assessment: Optional[int] = typer.Option( + assessment: int | None = typer.Option( None, "--assessment", help="Attach this run to an existing assessment case file. " "See `secfoo assessment create`.", ), - project_name: Optional[str] = typer.Option( + project_name: str | None = typer.Option( None, "--project-name", help="Friendly name for this project, shown across the dashboard instead " @@ -342,7 +342,7 @@ def run( "assessment is being auto-created); prompted for interactively if left " "unset on a terminal.", ), - app_id: Optional[str] = typer.Option( + app_id: str | None = typer.Option( None, "--app-id", help="Application ID to record on the auto-created assessment (e.g. from " @@ -357,14 +357,14 @@ def run( "checked-out repo). Repeatable, and added on top of [defaults].exclude " "in ~/.secfoo/config.toml and the built-in exclusions.", ), - fail_on: Optional[FailOn] = typer.Option( + fail_on: FailOn | None = typer.Option( None, "--fail-on", help="Exit 2 if any run reports a finding at this severity or worse " "(critical|high|medium|low). Falls back to [defaults].fail_on in " "~/.secfoo/config.toml; unset means findings never fail the command.", ), - max_cost: Optional[float] = typer.Option( + max_cost: float | None = typer.Option( None, "--max-cost", min=0.0, @@ -742,9 +742,9 @@ def _runtime_summary_line(outcomes) -> str | None: @app.command(name="list") def list_runs( - project: Optional[str] = typer.Option(None, "--project", "-p", help="Filter by project name/URL substring."), + project: str | None = typer.Option(None, "--project", "-p", help="Filter by project name/URL substring."), limit: int = typer.Option(50, "--limit", help="Maximum runs to show."), - status: Optional[str] = typer.Option(None, "--status", help="Filter by run status."), + status: str | None = typer.Option(None, "--status", help="Filter by run status."), ) -> None: """List past assessment runs.""" with RunRepository() as repo: @@ -873,7 +873,7 @@ def serve( "--runtime-recheck-hours", help="Re-check running package versions against OSV this often (#68). 0 disables.", )] = 6.0, - allow_host: Annotated[Optional[list[str]], typer.Option( + allow_host: Annotated[list[str] | None, typer.Option( "--allow-host", help="Also answer to this host name (repeatable), e.g. a port-forwarding or reverse-proxy name. " "Requests naming any other host are refused, which blocks DNS rebinding.", @@ -1000,10 +1000,10 @@ class CostGroup(str, Enum): @app.command() def cost( by: CostGroup = typer.Option(CostGroup.AGENT, "--by", help="Group spend by agent, skill, or project."), - since: Optional[str] = typer.Option( + since: str | None = typer.Option( None, "--since", help="Only count runs started on or after this date, YYYY-MM-DD.", callback=_validate_date ), - project: Optional[str] = typer.Option( + project: str | None = typer.Option( None, "--project", "-p", help="Only count one project (name/URL substring)." ), ) -> None: @@ -1064,22 +1064,22 @@ def cost( @assessment_app.command(name="create") def assessment_create( - project: Optional[str] = typer.Option( + project: str | None = typer.Option( None, "--project", "-p", help="Public GitHub repo URL or local directory. Defaults to the current directory.", ), - name: Optional[str] = typer.Option( + name: str | None = typer.Option( None, "--name", help="Friendly project name to display. Defaults to the name derived from --project." ), assessment_type: AssessmentTypeId = typer.Option(..., "--type", help="internal or third-party."), status: AssessmentStatusId = typer.Option(AssessmentStatusId.READY.value, "--status"), - app_id: Optional[str] = typer.Option(None, "--app-id", help="Application ID."), - sar: Optional[str] = typer.Option(None, "--sar", help="Security Assessment Request number."), - reviewer: Optional[str] = typer.Option(None, "--reviewer"), - review_date: Optional[str] = typer.Option(None, "--review-date"), - notes: Optional[str] = typer.Option(None, "--notes"), + app_id: str | None = typer.Option(None, "--app-id", help="Application ID."), + sar: str | None = typer.Option(None, "--sar", help="Security Assessment Request number."), + reviewer: str | None = typer.Option(None, "--reviewer"), + review_date: str | None = typer.Option(None, "--review-date"), + notes: str | None = typer.Option(None, "--notes"), ) -> None: """Create a new assessment case file that runs (and file attachments) can attach to.""" try: @@ -1105,9 +1105,9 @@ def assessment_create( @assessment_app.command(name="list") def assessment_list( - assessment_type: Optional[AssessmentTypeId] = typer.Option(None, "--type"), - status: Optional[AssessmentStatusId] = typer.Option(None, "--status"), - search: Optional[str] = typer.Option(None, "--search"), + assessment_type: AssessmentTypeId | None = typer.Option(None, "--type"), + status: AssessmentStatusId | None = typer.Option(None, "--status"), + search: str | None = typer.Option(None, "--search"), ) -> None: """List assessment case files.""" with RunRepository() as repo: @@ -1196,12 +1196,12 @@ def assessment_show(assessment_id: int) -> None: @assessment_app.command(name="update") def assessment_update( assessment_id: int, - status: Optional[AssessmentStatusId] = typer.Option(None, "--status"), - app_id: Optional[str] = typer.Option(None, "--app-id"), - sar: Optional[str] = typer.Option(None, "--sar"), - reviewer: Optional[str] = typer.Option(None, "--reviewer"), - review_date: Optional[str] = typer.Option(None, "--review-date"), - notes: Optional[str] = typer.Option(None, "--notes"), + status: AssessmentStatusId | None = typer.Option(None, "--status"), + app_id: str | None = typer.Option(None, "--app-id"), + sar: str | None = typer.Option(None, "--sar"), + reviewer: str | None = typer.Option(None, "--reviewer"), + review_date: str | None = typer.Option(None, "--review-date"), + notes: str | None = typer.Option(None, "--notes"), ) -> None: """Update fields on an existing assessment.""" fields: dict[str, object] = {} @@ -1286,7 +1286,7 @@ def assessment_delete(assessment_id: int) -> None: @exception_app.command(name="create") def exception_create( - project: Optional[str] = typer.Option( + project: str | None = typer.Option( None, "--project", "-p", help="Public GitHub repo URL or local directory. Defaults to the current directory." ), title: str = typer.Option(..., "--title", help="Short description of what's being accepted."), @@ -1295,10 +1295,10 @@ def exception_create( expires_at: str = typer.Option( ..., "--expires-at", help="Expiry date, YYYY-MM-DD.", callback=_validate_date ), - standard_or_control: Optional[str] = typer.Option( + standard_or_control: str | None = typer.Option( None, "--control", help="CCM domain code or standard clause this exception covers, e.g. IAM or 'SOC 2 CC6.1'." ), - assessment_id: Optional[int] = typer.Option(None, "--assessment", help="Optionally scope to one assessment."), + assessment_id: int | None = typer.Option(None, "--assessment", help="Optionally scope to one assessment."), ) -> None: """Grant a risk acceptance / waiver against a project.""" try: @@ -1321,7 +1321,7 @@ def exception_create( @exception_app.command(name="list") def exception_list( - status: Optional[str] = typer.Option(None, "--status", help="active or revoked."), + status: str | None = typer.Option(None, "--status", help="active or revoked."), ) -> None: """List exceptions, soonest-expiring first.""" with RunRepository() as repo: @@ -1373,11 +1373,11 @@ def exception_show(exception_id: int) -> None: @exception_app.command(name="update") def exception_update( exception_id: int, - status: Optional[str] = typer.Option(None, "--status", help="active or revoked."), - expires_at: Optional[str] = typer.Option( + status: str | None = typer.Option(None, "--status", help="active or revoked."), + expires_at: str | None = typer.Option( None, "--expires-at", help="Expiry date, YYYY-MM-DD.", callback=_validate_date ), - justification: Optional[str] = typer.Option(None, "--justification"), + justification: str | None = typer.Option(None, "--justification"), ) -> None: """Update an exception -- e.g. revoke it, or extend its expiry.""" fields: dict[str, object] = {} @@ -1413,16 +1413,16 @@ def exception_delete(exception_id: int) -> None: @miss_app.command(name="create") def miss_create( - project: Optional[str] = typer.Option( + project: str | None = typer.Option( None, "--project", "-p", help="Public GitHub repo URL or local directory. Defaults to the current directory." ), title: str = typer.Option(..., "--title", help="What was found."), discovered_at: str = typer.Option( ..., "--discovered-at", help="When it was found, YYYY-MM-DD.", callback=_validate_date ), - description: Optional[str] = typer.Option(None, "--description"), - discovered_by: Optional[str] = typer.Option(None, "--discovered-by", help="Who/what found it (incident, pen test, ...)."), - run: Optional[str] = typer.Option(None, "--run", help="Run UUID of the threat model that should have caught this, if known."), + description: str | None = typer.Option(None, "--description"), + discovered_by: str | None = typer.Option(None, "--discovered-by", help="Who/what found it (incident, pen test, ...)."), + run: str | None = typer.Option(None, "--run", help="Run UUID of the threat model that should have caught this, if known."), ) -> None: """Record a threat found after build that an earlier threat model missed. @@ -1503,17 +1503,17 @@ def miss_delete(finding_id: int) -> None: @accept_app.command(name="create") def accept_create( - project: Optional[str] = typer.Option( + project: str | None = typer.Option( None, "--project", "-p", help="Public GitHub repo URL or local directory. Defaults to the current directory." ), threat_id: str = typer.Option(..., "--threat-id", help="The Threat Register row ID from the report, e.g. T4."), title: str = typer.Option(..., "--title", help="Short description of the threat being accepted."), justification: str = typer.Option(..., "--justification", help="Why this risk is being accepted."), accepted_by: str = typer.Option(..., "--accepted-by", help="Who is accepting this risk."), - expires_at: Optional[str] = typer.Option( + expires_at: str | None = typer.Option( None, "--expires-at", help="Optional review-by date, YYYY-MM-DD.", callback=_validate_date ), - run: Optional[str] = typer.Option(None, "--run", help="Run UUID this threat came from, if known."), + run: str | None = typer.Option(None, "--run", help="Run UUID this threat came from, if known."), ) -> None: """Record a human risk acceptance for one threat from a Threat Register. @@ -1544,7 +1544,7 @@ def accept_create( @accept_app.command(name="list") def accept_list( - status: Optional[str] = typer.Option(None, "--status", help="active or revoked."), + status: str | None = typer.Option(None, "--status", help="active or revoked."), ) -> None: """List recorded threat acceptances, most recent first.""" with RunRepository() as repo: @@ -1588,11 +1588,11 @@ def accept_show(acceptance_id: int) -> None: @accept_app.command(name="update") def accept_update( acceptance_id: int, - status: Optional[str] = typer.Option(None, "--status", help="active or revoked."), - expires_at: Optional[str] = typer.Option( + status: str | None = typer.Option(None, "--status", help="active or revoked."), + expires_at: str | None = typer.Option( None, "--expires-at", help="Review-by date, YYYY-MM-DD.", callback=_validate_date ), - justification: Optional[str] = typer.Option(None, "--justification"), + justification: str | None = typer.Option(None, "--justification"), ) -> None: """Update a threat acceptance -- e.g. revoke it, or extend its review date.""" fields: dict[str, object] = {} @@ -1740,8 +1740,8 @@ def _memory_whoami_line(info: dict) -> str: @memory_app.command(name="signup") def memory_signup( - email: Optional[str] = typer.Option(None, "--email", help="Where to send the one-time verification code."), - code: Optional[str] = typer.Option( + email: str | None = typer.Option(None, "--email", help="Where to send the one-time verification code."), + code: str | None = typer.Option( None, "--code", help="The emailed code, for a non-interactive second step (skips sending a new one)." ), url: str = typer.Option( @@ -1881,9 +1881,9 @@ def _decoded_locations(value: object) -> list | None: @findings_app.command(name="export") def findings_export( skill: list[FindingsSkill] = typer.Option([], "--skill", "-s", help="Limit to these skills. Repeatable."), - project: Optional[int] = typer.Option(None, "--project", help="Limit to one project id."), + project: int | None = typer.Option(None, "--project", help="Limit to one project id."), status: FindingsStatus = typer.Option(FindingsStatus.OPEN, "--status", help="open, closed, or all."), - output: Optional[Path] = typer.Option(None, "--output", "-o", help="Write the export here instead of stdout."), + output: Path | None = typer.Option(None, "--output", "-o", help="Write the export here instead of stdout."), format: Annotated[FindingsFormat, typer.Option("--format", help="Export format: jsonl or sarif.")] = FindingsFormat.JSONL, no_locations: bool = typer.Option( False, "--no-locations", @@ -2600,7 +2600,7 @@ def vendor_mermaid( url = MERMAID_CDN_URL console.print(f"Downloading {url} ...") try: - with urllib.request.urlopen(url, timeout=60) as response: # noqa: S310 # nosec B310 -- pinned https CDN URL for mermaid bundle + with urllib.request.urlopen(url, timeout=60) as response: # nosec B310 -- pinned https CDN URL for mermaid bundle payload = response.read() except (urllib.error.URLError, TimeoutError) as exc: err_console.print(f"[red]Download failed:[/] {exc}") diff --git a/src/secfoo/cloud.py b/src/secfoo/cloud.py index e0be59b..403103f 100644 --- a/src/secfoo/cloud.py +++ b/src/secfoo/cloud.py @@ -133,7 +133,7 @@ def _request(url: str, *, api_key: str, payload: dict | None = None) -> dict: headers["Content-Type"] = "application/json" request = urllib.request.Request(url, data=data, headers=headers) try: - with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # noqa: S310 # nosec B310 -- user-configured portal URL, same trust as MCP settings + with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # nosec B310 -- user-configured portal URL, same trust as MCP settings return json.loads(response.read().decode("utf-8")) except urllib.error.HTTPError as exc: detail = exc.read().decode("utf-8", errors="replace") diff --git a/src/secfoo/memory.py b/src/secfoo/memory.py index a1c6d61..63e1d02 100644 --- a/src/secfoo/memory.py +++ b/src/secfoo/memory.py @@ -175,7 +175,7 @@ def _request(url: str, *, payload: dict | None = None, api_key: str | None = Non headers["Content-Type"] = "application/json" request = urllib.request.Request(url, data=data, headers=headers) try: - with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # noqa: S310 # nosec B310 -- user-configured memory URL, same trust as MCP settings + with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # nosec B310 -- user-configured memory URL, same trust as MCP settings return json.loads(response.read().decode("utf-8") or "{}") except urllib.error.HTTPError as exc: detail = exc.read().decode("utf-8", errors="replace") diff --git a/src/secfoo/osv.py b/src/secfoo/osv.py index a6876f9..ca22026 100644 --- a/src/secfoo/osv.py +++ b/src/secfoo/osv.py @@ -77,7 +77,7 @@ def query_osv(ecosystem: str, package: str, version: str) -> list[dict]: OSV_API_URL, data=body, headers={"Content-Type": "application/json"}, method="POST" ) try: - with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # noqa: S310 # nosec B310 -- hardcoded public OSV.dev API URL + with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: # nosec B310 -- hardcoded public OSV.dev API URL data = json.loads(response.read().decode("utf-8")) except urllib.error.HTTPError as exc: detail = exc.read().decode("utf-8", errors="replace") diff --git a/src/secfoo/runner.py b/src/secfoo/runner.py index 8b09b09..907c818 100644 --- a/src/secfoo/runner.py +++ b/src/secfoo/runner.py @@ -139,8 +139,7 @@ class RunOutcome: def _project_display_name(resolved: ResolvedTarget) -> str: if resolved.is_temporary: cleaned = resolved.display_name.rstrip("/") - if cleaned.endswith(".git"): - cleaned = cleaned[: -len(".git")] + cleaned = cleaned.removesuffix(".git") match = re.search(r"(?:https?://[^/]+/|git@[^:]+:)(.+)$", cleaned) return match.group(1) if match else cleaned return Path(resolved.display_name).name or resolved.display_name diff --git a/src/secfoo/skills/__init__.py b/src/secfoo/skills/__init__.py index af7d04a..8776faf 100644 --- a/src/secfoo/skills/__init__.py +++ b/src/secfoo/skills/__init__.py @@ -4,8 +4,8 @@ __all__ = [ "Skill", "SkillLoadError", + "TargetContext", "load_all_skills", "load_skill", - "TargetContext", "render_prompt", ] diff --git a/src/secfoo/targets/__init__.py b/src/secfoo/targets/__init__.py index 6879709..9979a1a 100644 --- a/src/secfoo/targets/__init__.py +++ b/src/secfoo/targets/__init__.py @@ -12,8 +12,8 @@ "ResolvedTarget", "TargetKind", "TargetResolutionError", + "clone_shallow", "is_github_url", "looks_like_url", "resolve_target", - "clone_shallow", ] diff --git a/src/secfoo/web/architecture_dashboard.py b/src/secfoo/web/architecture_dashboard.py index f351f76..576ede1 100644 --- a/src/secfoo/web/architecture_dashboard.py +++ b/src/secfoo/web/architecture_dashboard.py @@ -29,7 +29,11 @@ extract_verdict_counts, ) from secfoo.storage.repository import RunRepository -from secfoo.web.dashboard_common import append_boundary_changed_projects, percentile, read_report +from secfoo.web.dashboard_common import ( + append_boundary_changed_projects, + percentile, + read_report, +) SKILL_ID = "security-architecture-review" diff --git a/src/secfoo/web/routes/activities.py b/src/secfoo/web/routes/activities.py index 8adc07f..34f0ea4 100644 --- a/src/secfoo/web/routes/activities.py +++ b/src/secfoo/web/routes/activities.py @@ -30,10 +30,12 @@ from secfoo.skills.loader import SkillLoadError, load_skill from secfoo.storage.repository import RunRepository from secfoo.web import architecture_dashboard as arch_dashboard -from secfoo.web import finding_filters -from secfoo.web import sast_dashboard -from secfoo.web import sca_dashboard -from secfoo.web import secret_scanning_dashboard +from secfoo.web import ( + finding_filters, + sast_dashboard, + sca_dashboard, + secret_scanning_dashboard, +) from secfoo.web import threat_modeling_dashboard as tm_dashboard from secfoo.web.templating import severity_rows, templates diff --git a/src/secfoo/web/routes/assessments.py b/src/secfoo/web/routes/assessments.py index 1ad8932..77f2f58 100644 --- a/src/secfoo/web/routes/assessments.py +++ b/src/secfoo/web/routes/assessments.py @@ -5,7 +5,6 @@ import tempfile import threading from pathlib import Path -from typing import Optional from urllib.parse import urlencode from fastapi import APIRouter, Form, HTTPException, Request, UploadFile @@ -167,12 +166,12 @@ def _list_query(**params: object) -> str: @router.get("/assessments") def assessments_list( request: Request, - type: Optional[str] = None, # noqa: A002 -- matches the query param name - status: Optional[str] = None, - q: Optional[str] = None, - sort: Optional[str] = None, - updated: Optional[int] = None, - updated_to: Optional[str] = None, + type: str | None = None, # matches the query param name + status: str | None = None, + q: str | None = None, + sort: str | None = None, + updated: int | None = None, + updated_to: str | None = None, ): """Sorting happens in Python over the rows the page already shows (list_assessments' most-recently-updated cap), which keeps the @@ -211,7 +210,7 @@ def assessments_list( def assessments_bulk_status( ids: list[int] = Form(default_factory=list), new_status: str = Form(...), - type: str = Form(""), # noqa: A002 -- the list's current filters, to return to the same view + type: str = Form(""), # the list's current filters, to return to the same view status: str = Form(""), q: str = Form(""), sort: str = Form(""), diff --git a/src/secfoo/web/routes/runs.py b/src/secfoo/web/routes/runs.py index 08043d6..cbe60e2 100644 --- a/src/secfoo/web/routes/runs.py +++ b/src/secfoo/web/routes/runs.py @@ -8,7 +8,12 @@ from secfoo.config import STORE_DIR from secfoo.report.markdown import render_report_html from secfoo.storage.repository import RunRepository -from secfoo.web.run_status import ACTIVE_STATUSES, blocked_hint, elapsed_seconds, run_steps +from secfoo.web.run_status import ( + ACTIVE_STATUSES, + blocked_hint, + elapsed_seconds, + run_steps, +) from secfoo.web.templating import templates router = APIRouter() diff --git a/src/secfoo/web/sast_dashboard.py b/src/secfoo/web/sast_dashboard.py index 294336e..2fd6b02 100644 --- a/src/secfoo/web/sast_dashboard.py +++ b/src/secfoo/web/sast_dashboard.py @@ -13,7 +13,7 @@ from collections import Counter from dataclasses import dataclass, field -from secfoo.report.sast import SKILL_ID +from secfoo.report.sast import SKILL_ID # noqa: F401 -- re-exported: routes/activities.py uses sast_dashboard.SKILL_ID from secfoo.storage.models import SastFindingRecord from secfoo.storage.repository import RunRepository diff --git a/src/secfoo/web/third_party_dashboard.py b/src/secfoo/web/third_party_dashboard.py index d06747e..f37827c 100644 --- a/src/secfoo/web/third_party_dashboard.py +++ b/src/secfoo/web/third_party_dashboard.py @@ -15,7 +15,11 @@ from dataclasses import dataclass, field -from secfoo.report.architecture import CCM_DOMAINS, conformance_to_score, extract_ccm_conformance +from secfoo.report.architecture import ( + CCM_DOMAINS, + conformance_to_score, + extract_ccm_conformance, +) from secfoo.storage.repository import RunRepository from secfoo.web.dashboard_common import read_report diff --git a/src/secfoo/web/threat_modeling_dashboard.py b/src/secfoo/web/threat_modeling_dashboard.py index d90f529..0c41c9c 100644 --- a/src/secfoo/web/threat_modeling_dashboard.py +++ b/src/secfoo/web/threat_modeling_dashboard.py @@ -24,7 +24,11 @@ extract_threat_register_rows, ) from secfoo.storage.repository import RunRepository -from secfoo.web.dashboard_common import append_boundary_changed_projects, percentile, read_report +from secfoo.web.dashboard_common import ( + append_boundary_changed_projects, + percentile, + read_report, +) SKILL_ID = "threat-modeling" diff --git a/tests/test_cli_assessment.py b/tests/test_cli_assessment.py index b092061..70a1150 100644 --- a/tests/test_cli_assessment.py +++ b/tests/test_cli_assessment.py @@ -1,8 +1,9 @@ from __future__ import annotations -from secfoo.cli import app from typer.testing import CliRunner +from secfoo.cli import app + runner = CliRunner() diff --git a/tests/test_responsible_ai_end_to_end.py b/tests/test_responsible_ai_end_to_end.py index f5b823f..c8e84f0 100644 --- a/tests/test_responsible_ai_end_to_end.py +++ b/tests/test_responsible_ai_end_to_end.py @@ -19,10 +19,11 @@ import pytest from fastapi.testclient import TestClient +from typer.testing import CliRunner + from secfoo.cli import app from secfoo.storage.repository import RunRepository from secfoo.web.app import create_app -from typer.testing import CliRunner FIXTURE_DIR = Path(__file__).parent / "fixtures" / "reports" SKILL_ID = "responsible-ai-compliance" diff --git a/tests/test_web/test_activity_routes.py b/tests/test_web/test_activity_routes.py index 66a92ea..f6b16ac 100644 --- a/tests/test_web/test_activity_routes.py +++ b/tests/test_web/test_activity_routes.py @@ -108,7 +108,7 @@ def test_sidebar_marks_exactly_the_active_activity(client): resp = client.get("/activities/sast") # Links lead with an inline icon, so match through to . - links = re.findall(r'', resp.text, re.S) + links = re.findall(r'', resp.text, re.DOTALL) active = [re.sub(r"\s+", " ", link) for link in links if "aria-current" in link] assert len(active) == 1, f"expected exactly one active link, got {active}" assert 'href="/activities/sast"' in active[0] diff --git a/tests/test_web/test_architecture_review_status.py b/tests/test_web/test_architecture_review_status.py index a96133a..d881590 100644 --- a/tests/test_web/test_architecture_review_status.py +++ b/tests/test_web/test_architecture_review_status.py @@ -75,8 +75,8 @@ def test_by_project_ends_with_each_projects_review_status(client, tmp_path): assert header[-1] == "Review status" def status_of(name: str) -> str: - row = re.search(rf"]*>(?:(?!).)*{re.escape(name)}(?:(?!).)*", table, re.S).group(0) - cells = re.findall(r"]*>(.*?)", row, re.S) + row = re.search(rf"]*>(?:(?!).)*{re.escape(name)}(?:(?!).)*", table, re.DOTALL).group(0) + cells = re.findall(r"]*>(.*?)", row, re.DOTALL) return re.sub(r"<[^>]+>", "", cells[-1]).strip() assert status_of("acme/current") == "Current" diff --git a/tests/test_web/test_widget_info_tips.py b/tests/test_web/test_widget_info_tips.py index 57d14b4..373fda7 100644 --- a/tests/test_web/test_widget_info_tips.py +++ b/tests/test_web/test_widget_info_tips.py @@ -60,7 +60,7 @@ def _seed(tmp_path, project: str, depth: str) -> None: def test_every_threat_modeling_widget_has_an_info_tip(client, tmp_path): _seed(tmp_path, "acme/app", "Lightweight") html = client.get("/activities/threat-modeling").text - tips = re.findall(r'
.*?
', html, re.S) + tips = re.findall(r'
.*?
', html, re.DOTALL) titles = [re.search(r'

([^<]*)

', t).group(1) for t in tips] # The activity page also shows the generic severity card under the # program dashboard. Architecture, SAST, SCA, and secret scanning hide it. @@ -119,7 +119,7 @@ def test_long_lists_scroll_after_ten_rows(): def _assert_titled_tips(page: str, expected: list[str]) -> None: - tips = re.findall(r'
.*?
', page, re.S) + tips = re.findall(r'
.*?
', page, re.DOTALL) titles = [ html.unescape(re.search(r'

([^<]*)

', tip).group(1)) for tip in tips