Example #1
0
def make_app(global_conf, full_stack=True, **app_conf):
    """
    Set Erebot up with the settings found in the PasteDeploy configuration
    file used.

    :param global_conf: The global settings for Erebot (those
        defined under the ``[DEFAULT]`` section).
    :type global_conf: dict
    :param full_stack: Should the whole TG2 stack be set up?
    :type full_stack: str or bool
    :return: The Erebot application with all the relevant middleware
        loaded.

    This is the PasteDeploy factory for the Erebot application.

    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.


    """
    app = make_base_app(global_conf, full_stack=True, **app_conf)
    app = make_middleware_with_config(
            app,
            global_conf,
            app_conf.get('who.config_file'),
            None,
            None,
            skip_authentication=app_conf.get('skip_authentication'))
    app.logger = logging.getLogger('auth')
    return app
Example #2
0
 def test_without_authentication(self):
     """
     The middleware must be replaced if ``skip_authentication`` is True.
     
     """
     config = self._parse_config('config.ini')
     local_conf = config.local_conf
     mw = make_middleware_with_config(None, config.global_conf,
                                      local_conf['who.config_file'],
                                      local_conf['who.log_file'],
                                      local_conf['who.log_level'],
                                      skip_authentication=True)
     assert isinstance(mw, AuthenticationForgerMiddleware)
     # Checking the identifiers:
     final_identifiers = mw.registry[IIdentifier]
     self.assertEqual(3, len(final_identifiers))
     assert isinstance(final_identifiers[0], AuthenticationForgerPlugin)
     assert isinstance(final_identifiers[1], RedirectingFormPlugin)
     assert isinstance(final_identifiers[2], AuthTktCookiePlugin)
     # Checking the other plugins:
     auth_forger = final_identifiers[0]
     self.assertEqual([auth_forger], mw.registry[IAuthenticator])
     self.assertEqual([auth_forger], mw.registry[IChallenger])
     assert IMetadataProvider not in mw.registry
     # Checking REMOTE_USER keys:
     self.assertEqual(mw.remote_user_key, 'repoze.who.testutil.userid')
     self.assertEqual(mw.actual_remote_user_key, 'REMOTE_USER')
     # Finally, let's check the AuthenticationForgerPlugin in detail:
     self.assertEqual(auth_forger.fake_user_key, 'REMOTE_USER')
     self.assertEqual(auth_forger.remote_user_key,
                      'repoze.who.testutil.userid')
Example #3
0
 def test_skip_authentication_is_not_boolean(self):
     config = self._parse_config('config.ini')
     local_conf = config.local_conf
     # skip_authentication == 'True'
     mw = make_middleware_with_config(None, config.global_conf,
                                      local_conf['who.config_file'],
                                      local_conf['who.log_file'],
                                      local_conf['who.log_level'],
                                      skip_authentication='True')
     assert isinstance(mw, AuthenticationForgerMiddleware)
     # skip_authentication == 'False'
     mw = make_middleware_with_config(None, config.global_conf,
                                      local_conf['who.config_file'],
                                      local_conf['who.log_file'],
                                      local_conf['who.log_level'],
                                      skip_authentication='False')
     assert isinstance(mw, PluggableAuthenticationMiddleware)
Example #4
0
 def test_with_authentication(self):
     """
     The middleware must not be replaced if ``skip_authentication`` is False
     
     """
     config = self._parse_config('config.ini')
     local_conf = config.local_conf
     mw = make_middleware_with_config(None, config.global_conf,
                                      local_conf['who.config_file'],
                                      local_conf['who.log_file'],
                                      local_conf['who.log_level'],
                                      skip_authentication=False)
     assert isinstance(mw, PluggableAuthenticationMiddleware)