Skip to content

Commit

Permalink
Sandbox Process Creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeebot committed Jan 2, 2024
1 parent bf7d7cb commit 37a0fc0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
7 changes: 3 additions & 4 deletions integration_tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from codemodder import __version__
from codemodder import registry
from tests.validations import execute_code
from security import safe_command

SAMPLES_DIR = "tests/samples"
# Enable import of test modules from test directory
Expand Down Expand Up @@ -154,8 +155,7 @@ def test_file_rewritten(self):
self.check_code_before()
self.check_dependencies_before()

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

def _run_idempotency_chec(self, command):
# idempotency test, run it again and assert no files changed
completed_process = subprocess.run(
command,
completed_process = safe_command.run(subprocess.run, command,
check=False,
)
assert completed_process.returncode == 0
Expand Down
13 changes: 5 additions & 8 deletions integration_tests/test_dependency_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from integration_tests.base_test import SAMPLES_DIR, CleanRepoMixin
from textwrap import dedent
from security import safe_command


class TestDependencyManager(CleanRepoMixin):
Expand Down Expand Up @@ -60,8 +61,7 @@ def test_add_to_pyproject_toml(self, tmp_repo):
"--codemod-include=url-sandbox",
"--verbose",
]
completed_process = subprocess.run(
command,
completed_process = safe_command.run(subprocess.run, command,
check=False,
shell=False,
capture_output=True,
Expand All @@ -83,8 +83,7 @@ def test_add_to_requirements_txt(self, tmp_repo):
"--codemod-include=url-sandbox",
"--verbose",
]
completed_process = subprocess.run(
command,
completed_process = safe_command.run(subprocess.run, command,
check=False,
shell=False,
capture_output=True,
Expand All @@ -108,8 +107,7 @@ def test_add_to_setup(self, tmp_repo):
"--codemod-include=url-sandbox",
"--verbose",
]
completed_process = subprocess.run(
command,
completed_process = safe_command.run(subprocess.run, command,
check=False,
shell=False,
capture_output=True,
Expand All @@ -133,8 +131,7 @@ def test_fail_to_add(self, tmp_repo):
"--codemod-include=url-sandbox",
"--verbose",
]
completed_process = subprocess.run(
command,
completed_process = safe_command.run(subprocess.run, command,
check=False,
shell=False,
capture_output=True,
Expand Down
4 changes: 2 additions & 2 deletions 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 .base_test import SAMPLES_DIR
from security import safe_command


class TestMultipleCodemods:
Expand All @@ -31,8 +32,7 @@ def test_two_codemods(self, codemods, tmpdir):
f"**/{source_file_name}",
]

completed_process = subprocess.run(
command,
completed_process = safe_command.run(subprocess.run, command,
check=False,
shell=False,
)
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/test_program.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import subprocess
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/",
"--output",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies = [
"tomlkit~=0.12.0",
"wrapt~=1.16.0",
"chardet~=5.2.0",
"security~=1.2.0",
]
keywords = ["codemod", "codemods", "security", "fix", "fixes"]
classifiers = [
Expand Down
4 changes: 2 additions & 2 deletions src/codemodder/semgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from codemodder.context import CodemodExecutionContext
from codemodder.sarifs import SarifResultSet
from codemodder.logging import logger
from security import safe_command


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

0 comments on commit 37a0fc0

Please sign in to comment.