Commit ad3b49c2 authored by Jérome Perrin's avatar Jérome Perrin

Merge remote-tracking branch 'origin/master' into zope4py2

parents b9d9c26a 9405ec7d
...@@ -770,6 +770,41 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase): ...@@ -770,6 +770,41 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
'''.format(malicous_input) '''.format(malicous_input)
) )
def testIpAddressModuleAllowance(self):
# Test ipaddress usability
self.createAndRunScript('import ipaddress')
self.createAndRunScript('''
from ipaddress import ip_address
return ip_address(u'90.4.85.17').is_global
''')
self.createAndRunScript('''
from ipaddress import ip_network
return ip_network(u'90.4.0.0/16').is_private
''')
self.createAndRunScript('''
from ipaddress import ip_address, ip_network
return ip_address(u'90.4.85.17') in ip_network(u'90.4.0.0/16')
''')
self.createAndRunScript('''
from ipaddress import ip_interface
return ip_interface(u'90.4.85.17').with_prefixlen
''')
self.createAndRunScript('''
from ipaddress import ip_address
return ip_address(u'2a01:cb14:818:0:7312:e251:f251:ffbe').is_global
''')
self.createAndRunScript('''
from ipaddress import ip_network
return ip_network(u'2a01:cb14:818:0:7312:e251:f251::/112').is_private
''')
self.createAndRunScript('''
from ipaddress import ip_address, ip_network
return ip_address(u'2a01:cb14:818:0:7312:e251:f251:ffbe') in ip_network(u'2a01:cb14:818:0:7312:e251:f251::/112')
''')
self.createAndRunScript('''
from ipaddress import ip_interface
return ip_interface(u'2a01:cb14:818:0:7312:e251:f251:ffbe').with_prefixlen
''')
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
...@@ -92,11 +92,11 @@ class Session(UserDict): ...@@ -92,11 +92,11 @@ class Session(UserDict):
# used to set duration of session # used to set duration of session
session_duration = None session_duration = None
# a handle to current aquisition context # a handle to current acquisition context
_aq_context = None _aq_context = None
def __getstate__(self): def __getstate__(self):
"""filter out acqusition wrappers when serializing. """filter out acquisition wrappers when serializing.
""" """
state = { state = {
'session_duration': self.session_duration, 'session_duration': self.session_duration,
...@@ -107,12 +107,12 @@ class Session(UserDict): ...@@ -107,12 +107,12 @@ class Session(UserDict):
return state return state
def _updatecontext(self, aq_context): def _updatecontext(self, aq_context):
""" Update current aquisition context. """ """ Update current acquisition context. """
self._aq_context = aq_context self._aq_context = aq_context
def __getitem__(self, key): def __getitem__(self, key):
if key in self.data: if key in self.data:
# returned it wrapped in aquisition context # returned it wrapped in acquisition context
return restore_acquisition_wrapper(self.data[key], self._aq_context) return restore_acquisition_wrapper(self.data[key], self._aq_context)
raise KeyError(key) raise KeyError(key)
...@@ -213,10 +213,10 @@ class SessionTool(BaseTool): ...@@ -213,10 +213,10 @@ class SessionTool(BaseTool):
shopping_cart = session['shopping_cart'] shopping_cart = session['shopping_cart']
Please note that: Please note that:
- developer is responsible for handling an unique sessiond_id (using cookies for example). - developer is responsible for handling an unique session_id (using cookies for example).
- it's not recommended to store in portal_sessions ZODB persistent objects because in order - it's not recommended to store in portal_sessions ZODB persistent objects because in order
to store them in Local RAM portal_sessions tool will remove aquisition wrapper. At "get" to store them in Local RAM portal_sessions tool will remove acquisition wrapper. At "get"
request they'll be returend wrapped. request they'll be returned wrapped.
- developer can store temporary ERP5 documents like 'TempOrder', but keep - developer can store temporary ERP5 documents like 'TempOrder', but keep
in mind that after making changes to temporary documents they need to be in mind that after making changes to temporary documents they need to be
saved again in portal_sessions, so: saved again in portal_sessions, so:
......
...@@ -201,7 +201,7 @@ class SkinDataCleanup: ...@@ -201,7 +201,7 @@ class SkinDataCleanup:
if skindata is not None: if skindata is not None:
if self.hashSkinData(skindata) == self.skindata_id: if self.hashSkinData(skindata) == self.skindata_id:
try: try:
# Entry might have already disapeared. Ignore. # Entry might have already disappeared. Ignore.
del SKINDATA[tid] del SKINDATA[tid]
except KeyError: except KeyError:
pass pass
......
...@@ -574,3 +574,12 @@ else: ...@@ -574,3 +574,12 @@ else:
allow_full_write(pd.core.indexing._LocIndexer) allow_full_write(pd.core.indexing._LocIndexer)
allow_full_write(pd.MultiIndex) allow_full_write(pd.MultiIndex)
allow_full_write(pd.Index) allow_full_write(pd.Index)
import ipaddress
allow_module('ipaddress')
allow_type(ipaddress.IPv4Address)
allow_type(ipaddress.IPv6Address)
allow_type(ipaddress.IPv4Network)
allow_type(ipaddress.IPv6Network)
allow_type(ipaddress.IPv4Interface)
allow_type(ipaddress.IPv6Interface)
...@@ -80,14 +80,14 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -80,14 +80,14 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
def getPortal(self): def getPortal(self):
"""Returns the portal object, i.e. the "fixture root". """Returns the portal object, i.e. the "fixture root".
Rewrap the portal in an independant request for this test. Rewrap the portal in an independent request for this test.
""" """
if self.portal is not None: if self.portal is not None:
return self.portal return self.portal
from Products.ERP5.ERP5Site import getSite from Products.ERP5.ERP5Site import getSite
site = getSite() site = getSite()
# reconstruct the acquistion chain with an independant request. # reconstruct the acquisition chain with an independent request.
# RequestContainer -> Application -> Site # RequestContainer -> Application -> Site
from Testing.makerequest import makerequest from Testing.makerequest import makerequest
environ = {} environ = {}
......
...@@ -550,7 +550,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -550,7 +550,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
User password is the reference. User password is the reference.
""" """
user = self.createUser(reference, person_kw=dict(title=title)) user = self.createUser(reference, person_kw=dict(title=title))
assignment = self.createUserAssignement(user, assignment_kw=dict(function=function)) assignment = self.createUserAssignment(user, assignment_kw=dict(function=function))
return user return user
def createUser(self, reference, password=None, person_kw=None): def createUser(self, reference, password=None, person_kw=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment