Skip to content

Commit

Permalink
Fix wrong usage of safe_builtins in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Oct 26, 2018
1 parent bb93cd6 commit 29be63f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions tests/test_compile_restricted_function.py
Expand Up @@ -30,9 +30,9 @@ def test_compile_restricted_function(c_function):
safe_globals = {
'__name__': 'script',
'_getattr_': getattr,
'_print_': PrintCollector
'_print_': PrintCollector,
'__builtins__': safe_builtins,
}
safe_globals.update(safe_builtins)
safe_locals = {}
exec(result.code, safe_globals, safe_locals)
hello_world = safe_locals['hello_world']
Expand Down Expand Up @@ -64,8 +64,8 @@ def test_compile_restricted_function_func_wrapped(c_function):
'__name__': 'script',
'_getattr_': getattr,
'_print_': PrintCollector,
'__builtins__': safe_builtins,
}
safe_globals.update(safe_builtins)

func = FunctionType(result.code, safe_globals)
func()
Expand Down Expand Up @@ -98,9 +98,9 @@ def test_compile_restricted_function_with_arguments(c_function):
safe_globals = {
'__name__': 'script',
'_getattr_': getattr,
'_print_': PrintCollector
'_print_': PrintCollector,
'__builtins__': safe_builtins,
}
safe_globals.update(safe_builtins)
safe_locals = {}
exec(result.code, safe_globals, safe_locals)
hello_world = safe_locals['hello_world']
Expand Down Expand Up @@ -133,9 +133,9 @@ def test_compile_restricted_function_can_access_global_variables(c_function):
'__name__': 'script',
'_getattr_': getattr,
'input': 'Hello World!',
'_print_': PrintCollector
'_print_': PrintCollector,
'__builtins__': safe_builtins,
}
safe_globals.update(safe_builtins)
safe_locals = {}
exec(result.code, safe_globals, safe_locals)
hello_world = safe_locals['hello_world']
Expand Down Expand Up @@ -164,8 +164,8 @@ def test_compile_restricted_function_pretends_the_code_is_executed_in_a_global_s
safe_globals = {
'__name__': 'script',
'output': 'foo',
'__builtins__': {},
}
# safe_globals.update(safe_builtins)
safe_locals = {}
exec(result.code, safe_globals, safe_locals)
hello_world = safe_locals['hello_world']
Expand Down Expand Up @@ -195,8 +195,8 @@ def test_compile_restricted_function_allows_invalid_python_identifiers_as_functi
safe_globals = {
'__name__': 'script',
'output': 'foo',
'__builtins__': {},
}
# safe_globals.update(safe_builtins)
safe_locals = {}
exec(result.code, safe_globals, safe_locals)
generated_function = tuple(safe_locals.values())[0]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_iterating_over_dict_items.py
@@ -1,4 +1,4 @@
from RestrictedPython import safe_builtins
from RestrictedPython import safe_globals
from RestrictedPython.Eval import default_guarded_getiter
from RestrictedPython.Guards import guarded_iter_unpack_sequence
from tests import c_exec
Expand Down Expand Up @@ -26,7 +26,7 @@ def test_iterate_over_dict_items_plain(c_exec):

@pytest.mark.parametrize(*c_exec)
def test_iterate_over_dict_items_safe(c_exec):
glb = safe_builtins.copy()
glb = safe_globals.copy()
glb['_getiter_'] = default_guarded_getiter
glb['_iter_unpack_sequence_'] = guarded_iter_unpack_sequence
result = c_exec(ITERATE_OVER_DICT_ITEMS)
Expand Down

0 comments on commit 29be63f

Please sign in to comment.