Repository navigation
ci(codeql): skip py/log-injection on full Python scans #44001
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
Closed
pylaterreur
wants to merge
1
commit into
BerriAI:main
from
pylaterreur:fix-codeql-full-scan-log-injection
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| """Regression tests for the CodeQL workflow's py/log-injection exclusion. | ||
|
|
||
| On a full Python scan, run for pushes to main and nightly, py/log-injection passes | ||
| CodeQL's 2 GiB result-set limit and fails the whole analysis. The workflow drops that | ||
| one query from full scans with a yq step that edits `.github/codeql/codeql-config.yml`. | ||
| Pull request scans are diff-informed and finish the query, so they keep it. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import shutil | ||
| import subprocess | ||
| from pathlib import Path | ||
| from typing import Final | ||
|
|
||
| import pytest | ||
| import yaml | ||
|
|
||
| ROOT: Final = Path(__file__).resolve().parents[2] | ||
| WORKFLOW: Final = ROOT / ".github" / "workflows" / "codeql.yml" | ||
| CONFIG: Final = ROOT / ".github" / "codeql" / "codeql-config.yml" | ||
| EXCLUSION: Final = {"exclude": {"id": "py/log-injection"}} | ||
|
|
||
|
|
||
| def _exclusion_step() -> dict[str, str]: | ||
| steps: Final = [ | ||
| step | ||
| for job in yaml.safe_load(WORKFLOW.read_text())["jobs"].values() | ||
| for step in job.get("steps", []) | ||
| if "py/log-injection" in step.get("run", "") | ||
| ] | ||
| assert len(steps) == 1, steps | ||
| return steps[0] | ||
|
|
||
|
|
||
| def test_full_python_scans_skip_log_injection_and_pull_request_scans_keep_it() -> None: | ||
| condition: Final = _exclusion_step()["if"] | ||
| assert "matrix.language == 'python'" in condition | ||
| assert "github.event_name != 'pull_request'" in condition | ||
|
|
||
|
|
||
| @pytest.mark.skipif(shutil.which("yq") is None, reason="needs yq, which GitHub's Ubuntu runners ship") | ||
| def test_exclusion_step_drops_only_log_injection(tmp_path: Path) -> None: | ||
| copy: Final = tmp_path / ".github" / "codeql" / "codeql-config.yml" | ||
| copy.parent.mkdir(parents=True) | ||
| copy.write_text(CONFIG.read_text()) | ||
|
|
||
| subprocess.run(["bash", "-c", _exclusion_step()["run"]], cwd=tmp_path, check=True) | ||
|
|
||
| before: Final = yaml.safe_load(CONFIG.read_text()) | ||
| after: Final = yaml.safe_load(copy.read_text()) | ||
| assert after["query-filters"] == [*before["query-filters"], EXCLUSION] | ||
| assert {key: value for key, value in after.items() if key != "query-filters"} == { | ||
| key: value for key, value in before.items() if key != "query-filters" | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.