[Zope-Checkins] CVS: Zope/lib/python/RestrictedPython/tests - restricted_module.py:1.7.2.2 security_in_syntax.py:1.3.2.1 testRestrictions.py:1.8.2.2
Shane Hathaway
shane@digicool.com
Fri, 21 Dec 2001 14:13:11 -0500
Update of /cvs-repository/Zope/lib/python/RestrictedPython/tests
In directory cvs.zope.org:/tmp/cvs-serv5071/tests
Modified Files:
Tag: Zope-2_4-branch
restricted_module.py security_in_syntax.py testRestrictions.py
Log Message:
Backported stacksize and other compiler bugfixes.
=== Zope/lib/python/RestrictedPython/tests/restricted_module.py 1.7.2.1 => 1.7.2.2 ===
return printed
+def allowed_default_args(ob):
+ def f(a=ob.allowed, s=ob.s):
+ return a, s
+
+
def allowed_simple():
q = {'x':'a'}
q['y'] = 'b'
@@ -71,6 +76,10 @@
#ob.disallowed += 1
ob.disallowed = 1
return ob.disallowed
+
+def denied_default_args(ob):
+ def f(d=ob.disallowed):
+ return d
def denied_setattr(ob):
ob.allowed = -1
=== Zope/lib/python/RestrictedPython/tests/security_in_syntax.py 1.3 => 1.3.2.1 ===
def no_exec():
exec 'q = 1'
+
+def bad_default_args(ob):
+ def f(a=ob._name_starting_with_underscore):
+ return a
+
=== Zope/lib/python/RestrictedPython/tests/testRestrictions.py 1.8.2.1 => 1.8.2.2 ===
from RestrictedPython import compile_restricted, PrintCollector
from RestrictedPython.Eval import RestrictionCapableEval
-import security_in_syntax
+from RestrictedPython.tests import restricted_module, security_in_syntax
from types import FunctionType
if __name__=='__main__':
@@ -204,6 +204,9 @@
def checkAllowedWrite(self):
self.execFunc('allowed_write', RestrictedObject())
+ def checkAllowedArgs(self):
+ self.execFunc('allowed_default_args', RestrictedObject())
+
def checkDenied(self):
for k in rmodule.keys():
if k[:6] == 'denied':
@@ -264,6 +267,16 @@
v = [12, 34]
res = expr(m=v)
assert res == expect
+
+ def checkStackSize(self):
+ for k, rfunc in rmodule.items():
+ if not k.startswith('_') and hasattr(rfunc, 'func_code'):
+ rss = rfunc.func_code.co_stacksize
+ ss = getattr(restricted_module, k).func_code.co_stacksize
+ self.failUnless(
+ rss >= ss, 'The stack size estimate for %s() '
+ 'should have been at least %d, but was only %d'
+ % (k, ss, rss))
def test_suite():
return unittest.makeSuite(RestrictionTests, 'check')