Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions
CMFCore.tests.test_PortalFolder.PortalFolderCopySupportTests Class Reference
Inheritance diagram for CMFCore.tests.test_PortalFolder.PortalFolderCopySupportTests:
Inheritance graph
[legend]
Collaboration diagram for CMFCore.tests.test_PortalFolder.PortalFolderCopySupportTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_copy_baseline
def test_copy_cant_read_source
def test_copy_cant_create_target_metatype_not_supported
def test_move_baseline
def test_move_cant_read_source
def test_move_cant_create_target_metatype_not_supported
def test_move_cant_create_target_metatype_not_allowed
def test_move_cant_delete_source
def test_paste_with_restricted_item_content_type_not_allowed
def test_paste_with_restricted_item_content_type_allowed
def test_paste_with_restricted_container_content_type

Static Public Attributes

 layer = FunctionalZCMLLayer

Private Member Functions

def _initFolders
def _assertCopyErrorUnauth
def _initPolicyAndUser

Detailed Description

Definition at line 848 of file test_PortalFolder.py.


Member Function Documentation

def CMFCore.tests.test_PortalFolder.PortalFolderCopySupportTests._assertCopyErrorUnauth (   self,
  callable,
  args,
  kw 
) [private]

Definition at line 867 of file test_PortalFolder.py.

00867 
00868     def _assertCopyErrorUnauth( self, callable, *args, **kw ):
00869 
00870         import re
00871         from zExceptions import Unauthorized
00872         from OFS.CopySupport import CopyError
00873 
00874         ce_regex = kw.get( 'ce_regex' )
00875         if ce_regex is not None:
00876             del kw[ 'ce_regex' ]
00877 
00878         try:
00879             callable( *args, **kw )
00880 
00881         except CopyError, e:
00882 
00883             if ce_regex is not None:
00884 
00885                 pattern = re.compile( ce_regex, re.DOTALL )
00886                 if pattern.search( e ) is None:
00887                     self.fail( "Paste failed; didn't match pattern:\n%s" % e )
00888 
00889             else:
00890                 self.fail( "Paste failed; no pattern:\n%s" % e )
00891 
00892         except Unauthorized, e:
00893             pass
00894 
00895         else:
00896             self.fail( "Paste allowed unexpectedly." )

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 852 of file test_PortalFolder.py.

00852 
00853     def _initFolders(self):
00854         from Products.CMFCore.PortalFolder import PortalFolder
00855 
00856         self.app._setObject( 'folder1', PortalFolder( 'folder1' ) )
00857         self.app._setObject( 'folder2', PortalFolder( 'folder2' ) )
00858         folder1 = getattr( self.app, 'folder1' )
00859         folder2 = getattr( self.app, 'folder2' )
00860         manage_addFile(folder1, 'file', file='', content_type='text/plain')
00861 
00862         # Hack, we need a _p_mtime for the file, so we make sure that it
00863         # has one. We use a subtransaction, which means we can rollback
00864         # later and pretend we didn't touch the ZODB.
00865         transaction.savepoint(optimistic=True)
00866         return self.app._getOb( 'folder1' ), self.app._getOb( 'folder2' )

Here is the caller graph for this function:

def CMFCore.tests.test_PortalFolder.PortalFolderCopySupportTests._initPolicyAndUser (   self,
  a_lambda = None,
  v_lambda = None,
  c_lambda = None 
) [private]

Definition at line 901 of file test_PortalFolder.py.

00901 
00902                           ):
00903         def _promiscuous( *args, **kw ):
00904             return 1
00905 
00906         if a_lambda is None:
00907             a_lambda = _promiscuous
00908 
00909         if v_lambda is None:
00910             v_lambda = _promiscuous
00911 
00912         if c_lambda is None:
00913             c_lambda = _promiscuous
00914 
00915         scp = _SensitiveSecurityPolicy( v_lambda, c_lambda )
00916         SecurityManager.setSecurityPolicy( scp )
00917 
00918         newSecurityManager( None
00919                           , _AllowedUser(a_lambda).__of__(self.app.acl_users))

Here is the caller graph for this function:

Definition at line 920 of file test_PortalFolder.py.

00920 
00921     def test_copy_baseline( self ):
00922 
00923         folder1, folder2 = self._initFolders()
00924         folder2.all_meta_types = FILE_META_TYPES
00925 
00926         self._initPolicyAndUser()
00927 
00928         self.failUnless( 'file' in folder1.objectIds() )
00929         self.failIf( 'file' in folder2.objectIds() )
00930 
00931         cookie = folder1.manage_copyObjects( ids=( 'file', ) )
00932         folder2.manage_pasteObjects( cookie )
00933 
00934         self.failUnless( 'file' in folder1.objectIds() )
00935         self.failUnless( 'file' in folder2.objectIds() )

Here is the call graph for this function:

Definition at line 954 of file test_PortalFolder.py.

00954 
00955     def test_copy_cant_create_target_metatype_not_supported( self ):
00956         folder1, folder2 = self._initFolders()
00957         folder2.all_meta_types = ()
00958 
00959         self._initPolicyAndUser()
00960 
00961         cookie = folder1.manage_copyObjects( ids=( 'file', ) )
00962         self._assertCopyErrorUnauth( folder2.manage_pasteObjects
00963                                    , cookie
00964                                    , ce_regex='Not Supported'
00965                                    )

Here is the call graph for this function:

Definition at line 936 of file test_PortalFolder.py.

00936 
00937     def test_copy_cant_read_source( self ):
00938 
00939         folder1, folder2 = self._initFolders()
00940         folder2.all_meta_types = FILE_META_TYPES
00941 
00942         a_file = folder1._getOb( 'file' )
00943 
00944         def _validate( a, c, n, v, *args, **kw ):
00945             return aq_base( v ) is not aq_base( a_file )
00946 
00947         self._initPolicyAndUser( v_lambda=_validate )
00948 
00949         cookie = folder1.manage_copyObjects( ids=( 'file', ) )
00950         self._assertCopyErrorUnauth( folder2.manage_pasteObjects
00951                                    , cookie
00952                                    , ce_regex='Insufficient privileges'
00953                                    )

Here is the call graph for this function:

Definition at line 966 of file test_PortalFolder.py.

00966 
00967     def test_move_baseline( self ):
00968 
00969         folder1, folder2 = self._initFolders()
00970         folder2.all_meta_types = FILE_META_TYPES
00971 
00972         self.failUnless( 'file' in folder1.objectIds() )
00973         self.failIf( 'file' in folder2.objectIds() )
00974 
00975         self._initPolicyAndUser()
00976 
00977         cookie = folder1.manage_cutObjects( ids=( 'file', ) )
00978         folder2.manage_pasteObjects( cookie )
00979 
00980         self.failIf( 'file' in folder1.objectIds() )
00981         self.failUnless( 'file' in folder2.objectIds() )

Here is the call graph for this function:

Definition at line 1011 of file test_PortalFolder.py.

01011 
01012     def test_move_cant_create_target_metatype_not_allowed( self ):
01013 
01014         #
01015         #   This test can't succeed on Zope's earlier than 2.7.3 because
01016         #   of the DWIM'y behavior of 'guarded_getattr', which tries to
01017         #   filter acquired-but-inaccessible objects, rather than raising
01018         #   Unauthorized.
01019         #
01020         #   If you are running with such a Zope, this test will error out
01021         #   with an AttributeError (instead of the expected Unauthorized).
01022         #
01023         folder1, folder2 = self._initFolders()
01024         folder2.all_meta_types = FILE_META_TYPES
01025 
01026         def _no_manage_addFile( a, c, n, v, *args, **kw ):
01027             return n != 'manage_addFile'
01028 
01029         def _no_add_images_and_files(permission, object, context):
01030             return permission != ADD_IMAGES_AND_FILES
01031 
01032         self._initPolicyAndUser( v_lambda=_no_manage_addFile,
01033                                  c_lambda=_no_add_images_and_files )
01034 
01035         cookie = folder1.manage_cutObjects( ids=( 'file', ) )
01036         self._assertCopyErrorUnauth( folder2.manage_pasteObjects
01037                                    , cookie
01038                                    , ce_regex='Insufficient Privileges'
01039                                              + '.*%s' % ADD_IMAGES_AND_FILES
01040                                    )

Here is the call graph for this function:

Definition at line 999 of file test_PortalFolder.py.

00999 
01000     def test_move_cant_create_target_metatype_not_supported( self ):
01001         folder1, folder2 = self._initFolders()
01002         folder2.all_meta_types = ()
01003 
01004         self._initPolicyAndUser()
01005 
01006         cookie = folder1.manage_cutObjects( ids=( 'file', ) )
01007         self._assertCopyErrorUnauth( folder2.manage_pasteObjects
01008                                    , cookie
01009                                    , ce_regex='Not Supported'
01010                                    )

Here is the call graph for this function:

Definition at line 1041 of file test_PortalFolder.py.

01041 
01042     def test_move_cant_delete_source( self ):
01043 
01044         #
01045         #   This test fails on Zope's earlier than 2.7.3 because of the
01046         #   changes required to 'OFS.CopytSupport.manage_pasteObjects'
01047         #   which must pass 'validate_src' of 2 to '_verifyObjectPaste'
01048         #   to indicate that the object is being moved, rather than
01049         #   simply copied.
01050         #
01051         #   If you are running with such a Zope, this test will fail,
01052         #   because the move (which should raise Unauthorized) will be
01053         #   allowed.
01054         #
01055         from AccessControl.Permissions import delete_objects as DeleteObjects
01056         from Products.CMFCore.PortalFolder import PortalFolder
01057 
01058         folder1, folder2 = self._initFolders()
01059         folder1.manage_permission( DeleteObjects, roles=(), acquire=0 )
01060 
01061         folder1._setObject( 'sub', PortalFolder( 'sub' ) )
01062         transaction.savepoint(optimistic=True) # get a _p_jar for 'sub'
01063 
01064         self.app.portal_types = DummyTypesTool()
01065 
01066         def _no_delete_objects(permission, object, context):
01067             return permission != DeleteObjects
01068 
01069         self._initPolicyAndUser( c_lambda=_no_delete_objects )
01070 
01071         cookie = folder1.manage_cutObjects( ids=( 'sub', ) )
01072         self._assertCopyErrorUnauth( folder2.manage_pasteObjects
01073                                    , cookie
01074                                    , ce_regex='Insufficient Privileges'
01075                                              + '.*%s' % DeleteObjects
01076                                    )

Here is the call graph for this function:

Definition at line 982 of file test_PortalFolder.py.

00982 
00983     def test_move_cant_read_source( self ):
00984         folder1, folder2 = self._initFolders()
00985         folder2.all_meta_types = FILE_META_TYPES
00986 
00987         a_file = folder1._getOb( 'file' )
00988 
00989         def _validate( a, c, n, v, *args, **kw ):
00990             return aq_base( v ) is not aq_base( a_file )
00991 
00992         self._initPolicyAndUser( v_lambda=_validate )
00993 
00994         cookie = folder1.manage_cutObjects( ids=( 'file', ) )
00995         self._assertCopyErrorUnauth( folder2.manage_pasteObjects
00996                                    , cookie
00997                                    , ce_regex='Insufficient privileges'
00998                                    )

Here is the call graph for this function:

Definition at line 1166 of file test_PortalFolder.py.

01166 
01167     def test_paste_with_restricted_container_content_type(self):
01168 
01169         #   Test from CMF Collector #216 (Plone #2186), for the case
01170         #   in which the container does not allow adding items of the
01171         #   type being pasted.
01172         from Products.CMFCore.PortalFolder import PortalFolder
01173 
01174         RESTRICTED_TYPE = 'Restricted Container'
01175         UNRESTRICTED_TYPE = 'Unrestricted Item'
01176 
01177         folder1, folder2 = self._initFolders()
01178         folder1.portal_type = RESTRICTED_TYPE
01179         folder2.portal_type = UNRESTRICTED_TYPE
01180 
01181         self._initPolicyAndUser() # ensure that sec. machinery allows paste
01182 
01183         self.app._setObject( 'portal_types', TypesTool() )
01184         types_tool = self.app.portal_types
01185         types_tool._setObject( RESTRICTED_TYPE
01186                              , FTI( id=RESTRICTED_TYPE
01187                                   , title=RESTRICTED_TYPE
01188                                   , meta_type=PortalFolder.meta_type
01189                                   , product='CMFCore'
01190                                   , factory='manage_addPortalFolder'
01191                                   , filter_content_types=1
01192                                   , allowed_content_types=()
01193                                   )
01194                              )
01195         types_tool._setObject( UNRESTRICTED_TYPE
01196                              , FTI( id=UNRESTRICTED_TYPE
01197                                   , title=UNRESTRICTED_TYPE
01198                                   , meta_type=PortalFolder.meta_type
01199                                   , product='CMFCore'
01200                                   , factory='manage_addPortalFolder'
01201                                   , global_allow=1
01202                                   )
01203                              )
01204 
01205         # copy and pasting the object into the folder should raise
01206         # an exception
01207         copy_cookie = self.app.manage_copyObjects( ids=[ 'folder2' ] )
01208         self.assertRaises( ValueError
01209                          , folder1.manage_pasteObjects
01210                          , copy_cookie
01211                          )

Here is the call graph for this function:

Definition at line 1122 of file test_PortalFolder.py.

01122 
01123     def test_paste_with_restricted_item_content_type_allowed(self):
01124 
01125         #   Test from CMF Collector #216 (Plone #2186), for the case
01126         #   in which the item being pasted *does8 allow adding such
01127         #   objects to containers which *do* explicitly grant access.
01128         from Products.CMFCore.PortalFolder import PortalFolder
01129 
01130         RESTRICTED_TYPE = 'Restricted Item'
01131         UNRESTRICTED_TYPE = 'Unrestricted Container'
01132 
01133         folder1, folder2 = self._initFolders()
01134         folder1.portal_type = UNRESTRICTED_TYPE
01135         folder2.portal_type = RESTRICTED_TYPE
01136 
01137         self._initPolicyAndUser() # ensure that sec. machinery allows paste
01138 
01139         self.app._setObject( 'portal_types', TypesTool() )
01140         types_tool = self.app.portal_types
01141         types_tool._setObject( RESTRICTED_TYPE
01142                              , FTI( id=RESTRICTED_TYPE
01143                                   , title=RESTRICTED_TYPE
01144                                   , meta_type=PortalFolder.meta_type
01145                                   , product='CMFCore'
01146                                   , factory='manage_addPortalFolder'
01147                                   , global_allow=0
01148                                   )
01149                              )
01150         types_tool._setObject( UNRESTRICTED_TYPE
01151                              , FTI( id=UNRESTRICTED_TYPE
01152                                   , title=UNRESTRICTED_TYPE
01153                                   , meta_type=PortalFolder.meta_type
01154                                   , product='CMFCore'
01155                                   , factory='manage_addPortalFolder'
01156                                   , filter_content_types=1
01157                                   , allowed_content_types=[ RESTRICTED_TYPE ]
01158                                   )
01159                              )
01160 
01161         # copy and pasting the object into the folder should *not* raise
01162         # an exception, because the folder's type allows it.
01163         copy_cookie = self.app.manage_copyObjects( ids=[ 'folder2' ] )
01164         folder1.manage_pasteObjects( copy_cookie )
01165         self.failUnless( 'folder2' in folder1.objectIds() )

Here is the call graph for this function:

Definition at line 1077 of file test_PortalFolder.py.

01077 
01078     def test_paste_with_restricted_item_content_type_not_allowed(self):
01079 
01080         #   Test from CMF Collector #216 (Plone #2186), for the case
01081         #   in which the item being pasted does not allow adding such
01082         #   objects to containers which do not explicitly grant access.
01083         from Products.CMFCore.PortalFolder import PortalFolder
01084 
01085         RESTRICTED_TYPE = 'Restricted Item'
01086         UNRESTRICTED_TYPE = 'Unrestricted Container'
01087 
01088         folder1, folder2 = self._initFolders()
01089         folder1.portal_type = UNRESTRICTED_TYPE
01090         folder2.portal_type = RESTRICTED_TYPE
01091 
01092         self._initPolicyAndUser() # ensure that sec. machinery allows paste
01093 
01094         self.app._setObject( 'portal_types', TypesTool() )
01095         types_tool = self.app.portal_types
01096         types_tool._setObject( RESTRICTED_TYPE
01097                              , FTI( id=RESTRICTED_TYPE
01098                                   , title=RESTRICTED_TYPE
01099                                   , meta_type=PortalFolder.meta_type
01100                                   , product='CMFCore'
01101                                   , factory='manage_addPortalFolder'
01102                                   , global_allow=0
01103                                   )
01104                              )
01105         types_tool._setObject( UNRESTRICTED_TYPE
01106                              , FTI( id=UNRESTRICTED_TYPE
01107                                   , title=UNRESTRICTED_TYPE
01108                                   , meta_type=PortalFolder.meta_type
01109                                   , product='CMFCore'
01110                                   , factory='manage_addPortalFolder'
01111                                   , filter_content_types=0
01112                                   )
01113                              )
01114 
01115         # copy and pasting the object into the folder should raise
01116         # an exception
01117         copy_cookie = self.app.manage_copyObjects( ids=[ 'folder2' ] )
01118         self.assertRaises( ValueError
01119                          , folder1.manage_pasteObjects
01120                          , copy_cookie
01121                          )

Here is the call graph for this function:


Member Data Documentation

Definition at line 850 of file test_PortalFolder.py.


The documentation for this class was generated from the following file: