-
Notifications
You must be signed in to change notification settings - Fork 0
chore: add additional test pip-audit #40
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
5 commits
Select commit
Hold shift + click to select a range
0836552
chore: add additional test pip-audit
lhoupert 1791bce
fix: make poetry self add non-fatal (plugin bundled in Poetry 1.8+)
lhoupert 649f973
fix: secure executable and files paths
lhoupert 4e77eea
chore: add branch validation name
lhoupert 14cd094
test: fix test issue when running on gha
lhoupert 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
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,65 @@ | ||
| """Tests for __main__.py orchestrator.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import subprocess | ||
| from pathlib import Path | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
| from python_security_auditing.__main__ import main | ||
|
|
||
| FIXTURES = Path(__file__).parent / "fixtures" | ||
|
|
||
|
|
||
| def test_main_succeeds_when_uv_lockfile_missing_and_no_bandit_issues( | ||
| monkeypatch: pytest.MonkeyPatch, tmp_path: Path | ||
| ) -> None: | ||
| sarif_path = tmp_path / "results.sarif" | ||
| sarif_path.write_text((FIXTURES / "bandit_clean.sarif").read_text()) | ||
| monkeypatch.setenv("PACKAGE_MANAGER", "uv") | ||
| monkeypatch.setenv("TOOLS", "bandit,pip-audit") | ||
| monkeypatch.setenv("BANDIT_SARIF_PATH", str(sarif_path)) | ||
| monkeypatch.setenv("POST_PR_COMMENT", "false") | ||
| monkeypatch.chdir(tmp_path) | ||
|
|
||
| uv_exc = subprocess.CalledProcessError(2, "uv", stderr="No uv.lock found") | ||
|
|
||
| def mock_subprocess(cmd: list[str], **kwargs: object) -> MagicMock: | ||
| if cmd[0] == "uv": | ||
| raise uv_exc | ||
| return MagicMock(returncode=0, stderr="", stdout="[]") | ||
|
|
||
| with ( | ||
| patch("python_security_auditing.runners.shutil.which", side_effect=lambda exe: exe), | ||
| patch("python_security_auditing.runners.subprocess.run", side_effect=mock_subprocess), | ||
| ): | ||
| main() # should return normally without calling sys.exit(1) | ||
|
|
||
|
|
||
| def test_main_fails_when_bandit_blocks_despite_missing_lockfile( | ||
| monkeypatch: pytest.MonkeyPatch, tmp_path: Path | ||
| ) -> None: | ||
| sarif_path = tmp_path / "results.sarif" | ||
| sarif_path.write_text((FIXTURES / "bandit_issues.sarif").read_text()) | ||
| monkeypatch.setenv("PACKAGE_MANAGER", "uv") | ||
| monkeypatch.setenv("TOOLS", "bandit,pip-audit") | ||
| monkeypatch.setenv("BANDIT_SARIF_PATH", str(sarif_path)) | ||
| monkeypatch.setenv("BANDIT_SEVERITY_THRESHOLD", "high") | ||
| monkeypatch.setenv("POST_PR_COMMENT", "false") | ||
| monkeypatch.chdir(tmp_path) | ||
|
|
||
| uv_exc = subprocess.CalledProcessError(2, "uv", stderr="No uv.lock found") | ||
|
|
||
| def mock_subprocess(cmd: list[str], **kwargs: object) -> MagicMock: | ||
| if cmd[0] == "uv": | ||
| raise uv_exc | ||
| return MagicMock(returncode=0, stderr="", stdout="[]") | ||
|
|
||
| with ( | ||
| patch("python_security_auditing.runners.shutil.which", side_effect=lambda exe: exe), | ||
| patch("python_security_auditing.runners.subprocess.run", side_effect=mock_subprocess), | ||
| ): | ||
| with pytest.raises(SystemExit) as exc_info: | ||
| main() | ||
| assert exc_info.value.code == 1 |
Oops, something went wrong.
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.