-
Notifications
You must be signed in to change notification settings - Fork 2
Add test to ensure tbx security cve works #799
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
ArBridgeman
merged 2 commits into
main
from
bugfix/798_ensure_tbx_security_works_as_packaged
Apr 21, 2026
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import os | ||
| import shutil | ||
| import site | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| from noxconfig import PROJECT_CONFIG | ||
|
|
||
|
|
||
| def set_venv_env(monkeypatch, test_path: Path) -> None: | ||
| venv_bin = test_path / "venv" / "bin" | ||
| monkeypatch.setenv("VIRTUAL_ENV", str(test_path / "venv")) | ||
| monkeypatch.setenv("PATH", f"{venv_bin}{os.pathsep}{os.environ['PATH']}") | ||
| monkeypatch.setenv("PYTHONPATH", os.pathsep.join(site.getsitepackages())) | ||
|
|
||
|
|
||
| def test_security_issues_works(tmp_path, monkeypatch): | ||
| """ | ||
| To ensure that the `tbx security cve` CLI commands work for Java and | ||
| other non-Python projects, this test was created which: | ||
| - builds a wheel of the python-toolbox | ||
| - installs the wheel in a temporary directory | ||
| - executes `tbx security cve -- help` to ensure that no errors occur | ||
|
|
||
| This issue primarily arises when one of the modules in `tools` imports something | ||
| from `noxconfig`, which is used in the Python projects using the toolbox, but it | ||
| is not needed nor used in the non-Python projects. | ||
| """ | ||
| build_output = subprocess.run(["poetry", "build", "--output", tmp_path]) | ||
| assert build_output.returncode == 0 | ||
|
|
||
| venv_output = subprocess.run(["python", "-m", "venv", "venv"], cwd=tmp_path) | ||
| assert venv_output.returncode == 0 | ||
|
|
||
| set_venv_env(monkeypatch, tmp_path) | ||
| wheel = min(tmp_path.glob("exasol_toolbox-*.whl")) | ||
| pip_output = subprocess.run( | ||
| ["pip", "install", "--no-deps", str(wheel)], cwd=tmp_path | ||
| ) | ||
| assert pip_output.returncode == 0 | ||
|
|
||
| tbx_output = subprocess.run(["tbx", "security", "cve", "--help"], cwd=tmp_path) | ||
| assert tbx_output.returncode == 0 | ||
|
ArBridgeman marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def test_security_issues_fails_when_imports_noxconfig(tmp_path, monkeypatch): | ||
| """ | ||
| Reproduces the failure mode where a toolbox runtime module imports | ||
| `noxconfig`, which is not available in non-Python projects. | ||
| """ | ||
| source_root = PROJECT_CONFIG.root_path | ||
| project_copy = tmp_path / "python-toolbox-copy" | ||
| shutil.copytree( | ||
| source_root, | ||
| project_copy, | ||
| ignore=shutil.ignore_patterns( | ||
| ".git", ".venv", "dist", "__pycache__", ".pytest_cache" | ||
| ), | ||
| ) | ||
|
|
||
| security_py = project_copy / "exasol" / "toolbox" / "tools" / "security.py" | ||
| security_text = security_py.read_text() | ||
| security_py.write_text( | ||
| security_text.replace( | ||
| "from __future__ import annotations\n", | ||
| "from __future__ import annotations\n\nfrom noxconfig import PROJECT_CONFIG\n", | ||
| 1, | ||
| ) | ||
| ) | ||
|
|
||
| build_output = subprocess.run( | ||
| ["poetry", "build", "--output", tmp_path], cwd=project_copy | ||
| ) | ||
| assert build_output.returncode == 0 | ||
|
|
||
| venv_output = subprocess.run(["python", "-m", "venv", "venv"], cwd=tmp_path) | ||
| assert venv_output.returncode == 0 | ||
|
|
||
| set_venv_env(monkeypatch, tmp_path) | ||
| wheel = min(tmp_path.glob("exasol_toolbox-*.whl")) | ||
| pip_output = subprocess.run( | ||
| ["pip", "install", "--no-deps", str(wheel)], cwd=tmp_path | ||
| ) | ||
| assert pip_output.returncode == 0 | ||
|
|
||
| tbx_output = subprocess.run( | ||
| ["tbx", "security", "cve", "--help"], | ||
| cwd=tmp_path, | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| assert tbx_output.returncode != 0 | ||
| assert "No module named 'noxconfig'" in tbx_output.stderr | ||
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.