Skip to content
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

Sandbox Process Creation #431

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions integration_tests/test_dependency_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest

from codemodder.codemods.test.integration_utils import SAMPLES_DIR
from security import safe_command


class TestDependencyManager:
Expand Down Expand Up @@ -70,7 +71,8 @@ def test_add_to_pyproject_toml(self, tmp_repo):
"--codemod-include=url-sandbox",
"--verbose",
]
completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
command,
check=False,
shell=False,
Expand All @@ -93,7 +95,8 @@ def test_add_to_requirements_txt(self, tmp_repo):
"--codemod-include=url-sandbox",
"--verbose",
]
completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
command,
check=False,
shell=False,
Expand All @@ -118,7 +121,8 @@ def test_add_to_setup(self, tmp_repo):
"--codemod-include=url-sandbox",
"--verbose",
]
completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
command,
check=False,
shell=False,
Expand All @@ -143,7 +147,8 @@ def test_fail_to_add(self, tmp_repo):
"--codemod-include=url-sandbox",
"--verbose",
]
completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
command,
check=False,
shell=False,
Expand Down
4 changes: 3 additions & 1 deletion integration_tests/test_multiple_codemods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from codemodder.codemods.test.integration_utils import SAMPLES_DIR
from security import safe_command


class TestMultipleCodemods:
Expand All @@ -32,7 +33,8 @@ def test_two_codemods(self, codemods, tmpdir):
'--path-exclude=""',
]

completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
command,
check=False,
shell=False,
Expand Down
11 changes: 8 additions & 3 deletions integration_tests/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
from core_codemods.remove_assertion_in_pytest_raises import (
RemoveAssertionInPytestRaises,
)
from security import safe_command


class TestProgramFails:
def test_no_project_dir_provided(self):
completed_process = subprocess.run(["codemodder"], check=False)
completed_process = safe_command.run(
subprocess.run, ["codemodder"], check=False
)
assert completed_process.returncode == 3

def test_codemods_include_exclude_conflict(self):
completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
[
"codemodder",
"tests/samples/",
Expand All @@ -29,7 +33,8 @@ def test_codemods_include_exclude_conflict(self):
def test_load_sast_only_by_flag(self, tmp_path):
tmp_file_path = tmp_path / "sonar.json"
tmp_file_path.touch()
completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
[
"codemodder",
"tests/samples/",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"tomlkit~=0.12.0",
"wrapt~=1.16.0",
"chardet~=5.2.0",
"security==1.2.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library holds security tools for protecting Python API calls.

License: MITOpen SourceMore facts

]
keywords = ["codemod", "codemods", "security", "fix", "fixes"]
classifiers = [
Expand Down
7 changes: 5 additions & 2 deletions src/codemodder/codemods/test/integration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from codemodder import __version__, registry

from .validations import execute_code
from security import safe_command


class DependencyTestMixin:
Expand Down Expand Up @@ -218,7 +219,8 @@ def test_file_rewritten(self, codetf_schema):
self.write_original_code()
self.write_original_dependencies()

completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
command,
check=False,
shell=False,
Expand All @@ -232,7 +234,8 @@ def test_file_rewritten(self, codetf_schema):

def _run_idempotency_check(self, command):
# idempotency test, run it again and assert no files changed
completed_process = subprocess.run(
completed_process = safe_command.run(
subprocess.run,
command,
check=False,
)
Expand Down
4 changes: 3 additions & 1 deletion src/codemodder/semgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from codemodder.context import CodemodExecutionContext
from codemodder.logging import logger
from codemodder.sarifs import SarifResultSet
from security import safe_command


def run(
Expand Down Expand Up @@ -38,7 +39,8 @@ def run(
)
command.extend(map(str, files_to_analyze or [execution_context.directory]))
logger.debug("semgrep command: `%s`", " ".join(command))
call = subprocess.run(
call = safe_command.run(
subprocess.run,
command,
shell=False,
check=False,
Expand Down