Skip to content

Commit

Permalink
Test vulnerability import does not raise if authorized
Browse files Browse the repository at this point in the history
  • Loading branch information
albertvillanova committed Mar 3, 2025
1 parent 339b40f commit a29268b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/test_local_python_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ast
import types
import unittest
from contextlib import nullcontext as does_not_raise
from textwrap import dedent

import numpy as np
Expand Down Expand Up @@ -1419,9 +1420,13 @@ def test_call_from_dict(self, code):


class TestLocalPythonExecutorSecurity:
def test_vulnerability(self):
executor = LocalPythonExecutor([])
with pytest.raises(InterpreterError):
@pytest.mark.parametrize(
"additional_authorized_imports, expectation",
[([], pytest.raises(InterpreterError)), (["os"], does_not_raise())],
)
def test_vulnerability_import(self, additional_authorized_imports, expectation):
executor = LocalPythonExecutor(additional_authorized_imports)
with expectation:
executor("import os")

def test_vulnerability_builtins(self):
Expand Down

0 comments on commit a29268b

Please sign in to comment.