返回 last30days-skill
test_scorecard_workflow.py
根目录 / tests / test_scorecard_workflow.py
1 from pathlib import Path
2
3
4 ROOT = Path(__file__).resolve().parents[1]
5 WORKFLOW = ROOT / ".github" / "workflows" / "scorecard.yml"
6
7
8 def _workflow_text() -> str:
9 return WORKFLOW.read_text(encoding="utf-8")
10
11
12 def test_scorecard_workflow_exists() -> None:
13 assert WORKFLOW.is_file()
14
15
16 def test_scorecard_runs_ossf_action_and_uploads_sarif() -> None:
17 text = _workflow_text()
18
19 assert "ossf/scorecard-action" in text
20 assert "github/codeql-action/upload-sarif" in text
21 assert "results_format: sarif" in text
22
23
24 def test_scorecard_runs_on_schedule_and_default_branch() -> None:
25 text = _workflow_text()
26
27 # A weekly schedule surfaces security-health regressions even with no code
28 # changes; push-to-main keeps the score fresh on every merge.
29 assert "schedule:" in text
30 assert "cron:" in text
31 assert "branches:" in text
32 assert "- main" in text
33
34
35 def test_scorecard_requests_minimal_permissions() -> None:
36 text = _workflow_text()
37
38 # Top-level is read-only; only the analysis job widens what it needs.
39 assert "permissions: read-all" in text
40 # Job-level permissions fully replace the top-level block, so the reads
41 # checkout and Scorecard require must be listed explicitly or they default
42 # to none and every run fails.
43 assert "contents: read" in text
44 assert "actions: read" in text
45 assert "security-events: write" in text
46 assert "id-token: write" in text
47
48
49 def test_scorecard_documents_advisory_policy() -> None:
50 text = _workflow_text()
51
52 assert "advisory-first" in text.lower()
53 assert "never blocks merges" in text.lower()
54
54 lines PYTHON