Skip to content
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
21 changes: 18 additions & 3 deletions src/secfoo/web/routes/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@

router = APIRouter()


def _project_id(value: str | None) -> int | None:
"""The findings lists' "All projects" option submits project_id=
(empty). Declared as `int | None`, FastAPI rejected that with a 422, so
picking "All projects" -- or pressing Search with it selected, the
default -- showed a JSON error. Take the raw string instead; empty or
non-numeric means "all projects"."""
try:
return int((value or "").strip())
except ValueError:
return None

_GATE_MIX_COLORS = {
"approve": "var(--color-success)",
"conditions": "var(--color-warning)",
Expand Down Expand Up @@ -176,14 +188,15 @@ def sast_findings_list(
request: Request,
status: str = "open",
q: str | None = None,
project_id: int | None = None,
project_id: str | None = None,
):
"""The full, filterable SAST findings register -- the program
dashboard itself only ever shows a short "Top findings" preview (see
sast_dashboard.html); this is where "View all findings" lands, with a
project filter the dashboard preview deliberately doesn't have (it's
already cross-project by design).
"""
project_id = _project_id(project_id)
with RunRepository() as repo:
projects = repo.activity_summary_by_project(sast_dashboard.SKILL_ID)
findings = repo.list_sast_findings(project_id=project_id, status=status, search=q or None)
Expand Down Expand Up @@ -219,7 +232,7 @@ def sast_finding_detail(request: Request, fingerprint: str):


@router.get("/activities/{skill_id}/vulnerabilities")
def sca_vulnerabilities_list(request: Request, skill_id: str, project_id: int | None = None):
def sca_vulnerabilities_list(request: Request, skill_id: str, project_id: str | None = None):
"""The full SCA vulnerability register, filterable by project -- what
the program dashboard's "Top vulnerabilities" preview links out to.
Filtering happens post-aggregation, over sca_dashboard.build()'s
Expand All @@ -230,6 +243,7 @@ def sca_vulnerabilities_list(request: Request, skill_id: str, project_id: int |
"""
if skill_id != sca_dashboard.SKILL_ID:
raise HTTPException(status_code=404, detail="Not found")
project_id = _project_id(project_id)

with RunRepository() as repo:
projects = repo.activity_summary_by_project(sca_dashboard.SKILL_ID)
Expand Down Expand Up @@ -273,11 +287,12 @@ def sca_vulnerability_detail(request: Request, skill_id: str, key: str):


@router.get("/activities/secret-scanning/findings")
def secret_scanning_findings_list(request: Request, project_id: int | None = None):
def secret_scanning_findings_list(request: Request, project_id: str | None = None):
"""The full secret findings register, filterable by project -- what
the program dashboard's "Top findings" preview links out to, same
pattern as SAST's and SCA's findings-list pages.
"""
project_id = _project_id(project_id)
with RunRepository() as repo:
projects = repo.activity_summary_by_project(secret_scanning_dashboard.SKILL_ID)
dash = secret_scanning_dashboard.build(repo)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_web/test_sast_finding_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@ def test_sast_finding_detail_renders_for_a_real_finding(client):
def test_sast_finding_detail_404s_for_unknown_fingerprint(client):
resp = client.get("/activities/sast/findings/does-not-exist")
assert resp.status_code == 404


def test_sast_findings_list_accepts_the_all_projects_option(client):
# The "All projects" option submits project_id= (empty); this used to 422.
_seed_finding(fingerprint="fp-sqli", title="SQL Injection")
resp = client.get("/activities/sast/findings?status=open&project_id=&q=")
assert resp.status_code == 200
assert "SQL Injection" in resp.text
7 changes: 7 additions & 0 deletions tests/test_web/test_sca_vulnerability_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,10 @@ def test_arch_and_tm_dashboards_unaffected_by_sca_dashboard_addition(client, tmp
tm_resp = client.get("/activities/threat-modeling")
assert tm_resp.status_code == 200
assert "Program dashboard" in tm_resp.text


def test_sca_vulnerabilities_list_accepts_the_all_projects_option(client, tmp_path):
_seed(tmp_path)
resp = client.get("/activities/sca-reachability/vulnerabilities?project_id=")
assert resp.status_code == 200
assert "aiohttp" in resp.text
7 changes: 7 additions & 0 deletions tests/test_web/test_secret_scanning_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,10 @@ def test_secret_scanning_finding_detail_renders_for_a_real_finding(client, tmp_p
def test_secret_scanning_finding_detail_404s_for_unknown_key(client, tmp_path):
resp = client.get("/activities/secret-scanning/findings/deadbeefdeadbeef")
assert resp.status_code == 404


def test_secret_scanning_findings_list_accepts_the_all_projects_option(client, tmp_path):
_seed(tmp_path)
resp = client.get("/activities/secret-scanning/findings?project_id=")
assert resp.status_code == 200
assert "AWS access key" in resp.text
Loading