-
Notifications
You must be signed in to change notification settings - Fork 1
test: lock dependency bot condition hardening #2440
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import pathlib | ||
|
|
||
| import yaml | ||
|
|
||
| WORKFLOW_ROOT = pathlib.Path(".github/workflows") | ||
| SYNC_MANIFEST = pathlib.Path(".github/sync-manifest.yml") | ||
| ACTIVE_DEPENDENCY_BOT_WORKFLOWS = ( | ||
| WORKFLOW_ROOT / "maint-auto-label-dep-prs.yml", | ||
| WORKFLOW_ROOT / "maint-auto-lock-deps.yml", | ||
| ) | ||
| RETIRED_CONSUMER_AUTOMERGE = pathlib.Path( | ||
| "templates/consumer-repo/.github/workflows/dependabot-automerge.yml" | ||
| ) | ||
|
|
||
|
|
||
| def _workflow_source(path: pathlib.Path) -> str: | ||
| assert path.exists(), f"Expected workflow file to exist: {path}" | ||
| return path.read_text(encoding="utf-8") | ||
|
|
||
|
|
||
| def test_dependency_bot_workflows_gate_on_pr_author_not_trigger_actor(): | ||
| for workflow in ACTIVE_DEPENDENCY_BOT_WORKFLOWS: | ||
| source = _workflow_source(workflow) | ||
| assert "github.event.pull_request.user.login" in source | ||
| assert "github.actor == 'dependabot[bot]'" not in source | ||
| assert "github.actor == 'renovate[bot]'" not in source | ||
|
|
||
|
|
||
| def test_auto_lock_documents_pull_request_head_ref_trust_boundary(): | ||
| source = _workflow_source(WORKFLOW_ROOT / "maint-auto-lock-deps.yml") | ||
| assert "pull_request, not pull_request_target" in source | ||
| assert "github.head_ref is not an untrusted-code privileged checkout" in source | ||
|
|
||
|
|
||
| def test_retired_consumer_dependabot_automerge_template_stays_removed(): | ||
| assert not RETIRED_CONSUMER_AUTOMERGE.exists() | ||
|
|
||
| manifest = yaml.safe_load(SYNC_MANIFEST.read_text(encoding="utf-8")) or {} | ||
| removal_targets = {entry.get("target") for entry in manifest.get("removals", [])} | ||
| assert ".github/workflows/dependabot-automerge.yml" in removal_targets | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Harden the actor-regression assertions against equivalent syntax variants.
These negatives only block one exact string form (
== 'bot'). An unsafe gate likegithub.actor == "dependabot[bot]"(or spacing variants) would pass this test and reintroduce spoofable-actor logic undetected.Suggested fix
As per coding guidelines, “Flag ... spoofable bot-actor checks — this workflow YAML is synced to 9 consumer repos, so one bug replicates fleet-wide.”
🤖 Prompt for AI Agents
Source: Coding guidelines