From f124cf96b681afc390a08ddc57e7aac118a9e0cc Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Wed, 1 Feb 2017 15:30:25 +0100 Subject: [PATCH] Port weird lambda test. --- src/RestrictedPython/tests/security_in_syntax.py | 5 ----- tests/test_transformer.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/RestrictedPython/tests/security_in_syntax.py b/src/RestrictedPython/tests/security_in_syntax.py index 2b80239..d7f905c 100644 --- a/src/RestrictedPython/tests/security_in_syntax.py +++ b/src/RestrictedPython/tests/security_in_syntax.py @@ -3,11 +3,6 @@ # Each function in this module is compiled using compile_restricted(). -def check_getattr_in_lambda(arg=lambda _getattr=(lambda ob, name: name): - _getattr): - 42 - - def except_using_bad_name(): try: foo diff --git a/tests/test_transformer.py b/tests/test_transformer.py index 11ec7c4..bdb90de 100644 --- a/tests/test_transformer.py +++ b/tests/test_transformer.py @@ -988,6 +988,22 @@ def test_transformer__RestrictingNodeTransformer__visit_Lambda__7(compile): assert code is None +BAD_ARG_IN_LAMBDA = """\ +def check_getattr_in_lambda(arg=lambda _bad=(lambda ob, name: name): _bad2): + 42 +""" + + +@pytest.mark.parametrize(*compile) +def test_transformer__RestrictingNodeTransformer__visit_Lambda__8(compile): + """It prevents arguments starting with `_` in weird lambdas.""" + code, errors = compile(BAD_ARG_IN_LAMBDA)[:2] + # RestrictedPython.compile.compile_restricted_exec finds both invalid + # names, while the old implementation seems to abort after the first. + assert lambda_err_msg in errors + assert code is None + + @pytest.mark.skipif( IS_PY3, reason="tuple parameter unpacking is gone in python 3")