Back to index

plone3  3.1.7
pastc.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2006 Zope Corporation and Contributors. All Rights
00004 # Reserved.
00005 #
00006 # This software is subject to the provisions of the Zope Public License,
00007 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this
00008 # distribution.
00009 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00010 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00011 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00012 # FOR A PARTICULAR PURPOSE.
00013 #
00014 ##############################################################################
00015 
00016 from Testing import ZopeTestCase
00017 
00018 ZopeTestCase.installProduct('PluginRegistry')
00019 ZopeTestCase.installProduct('PluggableAuthService')
00020 ZopeTestCase.installProduct('StandardCacheManagers')
00021 ZopeTestCase.installProduct('GenericSetup')
00022 
00023 from Testing.ZopeTestCase import user_name
00024 from Testing.ZopeTestCase import user_password
00025 from Testing.ZopeTestCase import user_role
00026 
00027 from base64 import encodestring
00028 user_auth = encodestring('%s:%s' % (user_name, user_password)).rstrip()
00029 
00030 from Products.PluggableAuthService.interfaces.plugins import \
00031     IAuthenticationPlugin, IUserEnumerationPlugin, IRolesPlugin, \
00032     IRoleEnumerationPlugin, IRoleAssignerPlugin, \
00033     IChallengePlugin, IExtractionPlugin, IUserAdderPlugin
00034 
00035 
00036 class PASTestCase(ZopeTestCase.ZopeTestCase):
00037     """ZopeTestCase with a PAS instead of the default user folder
00038     """
00039 
00040     def _setupUserFolder(self):
00041         """Creates a Pluggable Auth Service."""
00042         factory = self.folder.manage_addProduct['PluggableAuthService']
00043         factory.addPluggableAuthService()
00044         pas = self.folder.acl_users
00045         factory = pas.manage_addProduct['PluggableAuthService']
00046         factory.addHTTPBasicAuthHelper('http_auth')
00047         factory.addZODBUserManager('users')
00048         factory.addZODBRoleManager('roles')
00049         plugins = pas.plugins
00050         plugins.activatePlugin(IChallengePlugin, 'http_auth')
00051         plugins.activatePlugin(IExtractionPlugin, 'http_auth')
00052         plugins.activatePlugin(IUserAdderPlugin, 'users')
00053         plugins.activatePlugin(IAuthenticationPlugin, 'users')
00054         plugins.activatePlugin(IUserEnumerationPlugin, 'users')
00055         plugins.activatePlugin(IRolesPlugin, 'roles')
00056         plugins.activatePlugin(IRoleAssignerPlugin, 'roles')
00057         plugins.activatePlugin(IRoleEnumerationPlugin, 'roles')
00058 
00059     def _setupUser(self):
00060         """Creates the default user."""
00061         # OMFG, why doesn't PAS support userFolderAddUser?
00062         uf = self.folder.acl_users
00063         uf._doAddUser(user_name, user_password, [user_role], [])
00064