Exemplo n.º 1
0
def setup_product():
    """Set up additional products and ZCML required to test this product.
    """

    # Load the ZCML configuration for this package and its dependencies

    fiveconfigure.debug_mode = True
    zcml.load_config('configure.zcml', collective.rope)
    fiveconfigure.debug_mode = False

    # We need to tell the testing framework that these products
    # should be available. This can't happen until after we have loaded
    # the ZCML.

    installPackage('collective.rope')
    def afterSetUp(self):
        # Upgrade the UserFolder to a PAS
        from Products.PluggableAuthService.Extensions.upgrade import replace_acl_users
        replace_acl_users(self.app.test_folder_1_)
        from Products.PluggableAuthService.interfaces.plugins import IGroupsPlugin, IGroupEnumerationPlugin, IUserEnumerationPlugin, IAuthenticationPlugin, IRolesPlugin
        from Products.PluggableAuthService.interfaces.plugins import ICredentialsUpdatePlugin, ICredentialsResetPlugin, IExtractionPlugin, IChallengePlugin
        self.uf = self.app.test_folder_1_.acl_users
        self.uf.roles.assignRoleToPrincipal('Manager', user_name)
        plugins = self.uf.plugins
        factory = self.uf.manage_addProduct['PluggableAuthService']
        if not self.uf.hasObject('groups'):
            factory.addZODBGroupManager('groups')
            plugins.activatePlugin(IGroupsPlugin, 'groups')
            plugins.activatePlugin(IGroupEnumerationPlugin, 'groups')
        if not self.uf.hasObject('cookies'):
            factory.addCookieAuthHelper('cookies')
            #plugins.activatePlugin(ICredentialsUpdatePlugin, 'cookies')
            #plugins.activatePlugin(ICredentialsResetPlugin, 'cookies')
            plugins.activatePlugin(IExtractionPlugin, 'cookies')
        if not self.uf.hasObject('basic_auth'):
            factory.addHTTPBasicAuthHelper('basic_auth')
            #plugins.activatePlugin(ICredentialsUpdatePlugin, 'cookies')
            #plugins.activatePlugin(ICredentialsResetPlugin, 'cookies')
            plugins.activatePlugin(IExtractionPlugin, 'basic_auth')
            plugins.activatePlugin(IChallengePlugin, 'basic_auth')

        zcml.load_site()
        zcml.load_config('configure.zcml', jcu.shibboleth.pas)
        installPackage('jcu.shibboleth.pas')

        # Add the session objects
        ZopeTestCase.utils.setupCoreSessions(self.app)

        from jcu.shibboleth.pas.plugin import ShibbolethHelper
        shib = ShibbolethHelper('shib', 'Shibboleth Helper')
        self.app.test_folder_1_.acl_users['shib'] = shib
        plugins.activatePlugin(IExtractionPlugin, 'shib')
        plugins.activatePlugin(IAuthenticationPlugin, 'shib')
        plugins.activatePlugin(IChallengePlugin, 'shib')
        plugins.activatePlugin(IRolesPlugin, 'shib')
        plugins.activatePlugin(IUserEnumerationPlugin, 'shib')
        #plugins.activatePlugin(IChallengePlugin, 'basic_auth')

        # Setup attribute map resolver
        path = os.path.dirname(jcu.shibboleth.pas.__file__)
        self.app.test_folder_1_.acl_users.shib.shibboleth_config_dir = os.path.join(path, 'tests', 'shib2')
    def afterSetUp(self):
        # Upgrade the UserFolder to a PAS
        from Products.PluggableAuthService.Extensions.upgrade import replace_acl_users
        replace_acl_users(self.app.test_folder_1_)
        from Products.PluggableAuthService.interfaces.plugins import IGroupsPlugin, IGroupEnumerationPlugin
        self.uf = self.app.test_folder_1_.acl_users
        self.uf.roles.assignRoleToPrincipal('Manager', user_name)
        if not self.uf.hasObject('groups'):
            factory = self.uf.manage_addProduct['PluggableAuthService']
            factory.addZODBGroupManager('groups')
            plugins = self.uf.plugins
            plugins.activatePlugin(IGroupsPlugin, 'groups')
            plugins.activatePlugin(IGroupEnumerationPlugin, 'groups')

        zcml.load_site()
        installPackage('jcu.shibboleth.pas')

        # Add the session objects
        ZopeTestCase.utils.setupCoreSessions(self.app)