Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Paul Graydon
erp5
Commits
0e26185c
Commit
0e26185c
authored
Nov 08, 2019
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
58144924
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
0 deletions
+79
-0
product/ERP5Type/dynamic/component_package.py
product/ERP5Type/dynamic/component_package.py
+4
-0
product/ERP5Type/tests/testDynamicClassGeneration.py
product/ERP5Type/tests/testDynamicClassGeneration.py
+75
-0
No files found.
product/ERP5Type/dynamic/component_package.py
View file @
0e26185c
...
@@ -35,6 +35,7 @@ import imp
...
@@ -35,6 +35,7 @@ import imp
import
collections
import
collections
from
Products.ERP5.ERP5Site
import
getSite
from
Products.ERP5.ERP5Site
import
getSite
from
AccessControl.SecurityInfo
import
_moduleSecurity
from
.
import
aq_method_lock
from
.
import
aq_method_lock
from
types
import
ModuleType
from
types
import
ModuleType
from
zLOG
import
LOG
,
BLATHER
,
WARNING
from
zLOG
import
LOG
,
BLATHER
,
WARNING
...
@@ -314,6 +315,9 @@ class ComponentDynamicPackage(ModuleType):
...
@@ -314,6 +315,9 @@ class ComponentDynamicPackage(ModuleType):
setattr
(
version_package
,
name
,
module
)
setattr
(
version_package
,
name
,
module
)
if
module_fullname_alias
:
if
module_fullname_alias
:
setattr
(
self
,
name
,
module
)
setattr
(
self
,
name
,
module
)
modsec
=
_moduleSecurity
.
get
(
module_fullname
)
if
modsec
is
not
None
:
_moduleSecurity
[
module_fullname_alias
]
=
modsec
import
erp5.component
import
erp5.component
erp5
.
component
.
ref_manager
.
add_module
(
module
)
erp5
.
component
.
ref_manager
.
add_module
(
module
)
...
...
product/ERP5Type/tests/testDynamicClassGeneration.py
View file @
0e26185c
...
@@ -2308,6 +2308,81 @@ undefined()
...
@@ -2308,6 +2308,81 @@ undefined()
imported_module2_with_version
])
imported_module2_with_version
])
self
.
assertEqual
(
component
.
getTextContentWarningMessageList
(),
[])
self
.
assertEqual
(
component
.
getTextContentWarningMessageList
(),
[])
def
testModuleSecurityInfo
(
self
):
"""AccessControl.SecurityInfo.ModuleSecurityInfo() function allows to declare
public/private classes and functions at Module level.
When called, an entry is added to AccessControl.SecurityInfo._moduleSecurity
dict (mapping module name to _ModuleSecurityInfo class instance). Later on,
when this module is imported from 'Restricted Code', securities will be
applied to the Module and then be moved to from _moduleSecurity to
AccessControl.SecurityInfo._appliedModuleSecurity dict.
For ZODB Components, we have the versioned Module and its alias. This test
ensures that securities are also properly defined for the alias to be
importable (and thus not raising an 'Unauthorized' exception.
"""
reference
=
self
.
_generateReference
(
'TestModuleSecurityInfo'
)
component
=
self
.
_newComponent
(
reference
)
component
.
setTextContent
(
"""
class TestModuleSecurityInfoException(Exception):
pass
from AccessControl.SecurityInfo import ModuleSecurityInfo
ModuleSecurityInfo(__name__).declarePublic('TestModuleSecurityInfoException')
"""
+
component
.
getTextContent
())
self
.
portal
.
portal_workflow
.
doActionFor
(
component
,
'validate_action'
)
self
.
tic
()
self
.
assertEqual
(
component
.
getValidationState
(),
'validated'
)
self
.
assertEqual
(
component
.
getTextContentErrorMessageList
(),
[])
self
.
assertEqual
(
component
.
getTextContentWarningMessageList
(),
[])
module
=
self
.
_getComponentFullModuleName
(
reference
)
module_versioned
=
self
.
_getComponentFullModuleName
(
reference
,
version
=
'erp5'
)
## This will import both erp5.component.XXX.TestModuleSecurityInfo and
## erp5.component.XXX.erp5_version.TestModuleSecurityInfo
self
.
assertModuleImportable
(
reference
,
expected_default_version
=
'erp5_version'
)
from
AccessControl.SecurityInfo
import
_moduleSecurity
# __name__ == erp5.component.XXX.erp5_version.TestModuleSecurityInfo
# (erp5.component.XXX.TestModuleSecurityInfo is just an alias) so this
# will always be non-None
module_versioned_security_obj
=
_moduleSecurity
.
get
(
module_versioned
)
self
.
assertNotEqual
(
module_versioned_security_obj
,
None
)
self
.
assertEqual
(
module_versioned_security_obj
,
_moduleSecurity
.
get
(
module
))
## As the Module has not been imported yet from 'Restricted Code',
## securities should have been applied yet.
from
AccessControl.SecurityInfo
import
_appliedModuleSecurity
self
.
assertEqual
(
_appliedModuleSecurity
.
get
(
module_versioned
),
None
)
self
.
assertEqual
(
_appliedModuleSecurity
.
get
(
module
),
None
)
createZODBPythonScript
(
self
.
portal
.
portal_skins
.
custom
,
'TestModuleSecurityInfoPythonScript'
,
''
,
"""
from %s import TestModuleSecurityInfoException
from %s import TestModuleSecurityInfoException
return 'OK'
"""
%
(
module_versioned
,
module
))
self
.
assertEqual
(
self
.
portal
.
TestModuleSecurityInfoPythonScript
(),
'OK'
)
self
.
assertEqual
(
_moduleSecurity
.
get
(
module_versioned
),
None
)
self
.
assertEqual
(
_moduleSecurity
.
get
(
module
),
None
)
applied_module_security_obj
=
_appliedModuleSecurity
.
get
(
module_versioned
)
self
.
assertNotEqual
(
applied_module_security_obj
,
None
)
self
.
assertEqual
(
applied_module_security_obj
,
_appliedModuleSecurity
.
get
(
module
))
## Reset must clear everything...
self
.
_component_tool
.
reset
(
force
=
True
,
reset_portal_type_at_transaction_boundary
=
True
)
self
.
assertEqual
(
_moduleSecurity
.
get
(
module_versioned
),
None
)
self
.
assertEqual
(
_moduleSecurity
.
get
(
module
),
None
)
self
.
assertEqual
(
_appliedModuleSecurity
.
get
(
module_versioned
),
None
)
self
.
assertEqual
(
_appliedModuleSecurity
.
get
(
module
),
None
)
import
pdb
;
pdb
.
set_trace
()
from
Products.ERP5Type.Core.ExtensionComponent
import
ExtensionComponent
from
Products.ERP5Type.Core.ExtensionComponent
import
ExtensionComponent
class
TestZodbExtensionComponent
(
_TestZodbComponent
):
class
TestZodbExtensionComponent
(
_TestZodbComponent
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment