Ejemplo n.º 1
0
def main(global_config, **settings):
    """
    This function returns a Pyramid WSGI application.
    """
    del global_config  # Unused

    config = Configurator(
        root_factory=Root,
        settings=settings,
        locale_negotiator=locale_negotiator,
        authentication_policy=create_authentication(settings))

    # Workaround to not have the error: distutils.errors.DistutilsArgError: no commands supplied
    distutils.core._setup_stop_after = 'config'
    config.include('c2cgeoportal_geoportal')
    distutils.core._setup_stop_after = None

    config.add_translation_dirs('testgeomapfish_geoportal:locale/')

    # scan view decorator for adding routes
    config.scan()

    # add the interfaces
    add_interface(config, 'desktop', INTERFACE_TYPE_NGEO, default=True)
    add_interface(config, 'mobile', INTERFACE_TYPE_NGEO)

    return config.make_wsgi_app()
Ejemplo n.º 2
0
def create_dummy_request(additional_settings=None,
                         authentication=True,
                         user=None,
                         *args,
                         **kargs):
    if additional_settings is None:
        additional_settings = {}
    from c2cgeoportal_geoportal import default_user_validator
    from c2cgeoportal_geoportal import create_get_user_from_request
    from c2cgeoportal_geoportal.lib.authentication import create_authentication

    request = tests.create_dummy_request(
        {
            "host_forward_host": [],
            "functionalities": {
                "available_in_templates": []
            },
            "layers": {
                "geometry_validation": True
            },
            "admin_interface": {
                "available_functionalities": [{
                    "name": "mapserver_substitution",
                    "single": False
                }]
            },
        },
        *args,
        **kargs,
    )
    request.accept_language = webob.acceptparse.create_accept_language_header(
        "fr-CH,fr;q=0.8,en;q=0.5,en-US;q=0.3")
    request.registry.settings.update(additional_settings)
    request.referer = "http://example.com/app"
    request.path_info_peek = lambda: "main"
    request.interface_name = "main"
    request.get_user = _get_user
    request.registry.validate_user = default_user_validator
    request.c2c_request_id = "test"
    if authentication and user is None:
        authentication_settings = {
            "authtkt_cookie_name":
            "__test",
            "authtkt_secret":
            "long enough secret!!  00000000000000000000000000000000000000000000000",
        }
        authentication_settings.update(additional_settings)
        request._get_authentication_policy = lambda: create_authentication(
            authentication_settings)
    elif user is not None:
        config.testing_securitypolicy(user)
    request.set_property(create_get_user_from_request(
        {"authorized_referers": [request.referer]}),
                         name="user",
                         reify=True)
    return request
Ejemplo n.º 3
0
def create_dummy_request(additional_settings=None,
                         authentication=True,
                         user=None,
                         *args,
                         **kargs):
    if additional_settings is None:
        additional_settings = {}
    from c2cgeoportal_geoportal import default_user_validator
    from c2cgeoportal_geoportal import create_get_user_from_request
    from c2cgeoportal_geoportal.lib.authentication import create_authentication
    request = tests.create_dummy_request(
        {
            "host_forward_host": [],
            "mapserverproxy": {
                "default_ogc_server": "__test_ogc_server",
                "external_ogc_server": "__test_external_ogc_server",
            },
            "functionalities": {
                "registered": {},
                "anonymous": {},
                "available_in_templates": []
            },
            "layers": {
                "geometry_validation": True
            }
        }, *args, **kargs)
    request.accept_language = Accept("fr-CH,fr;q=0.8,en;q=0.5,en-US;q=0.3")
    request.registry.settings.update(additional_settings)
    request.referer = "http://example.com/app"
    request.path_info_peek = lambda: "main"
    request.interface_name = "main"
    request.get_user = _get_user
    request.registry.validate_user = default_user_validator
    request.client_addr = None
    request.c2c_request_id = 'test'
    if authentication and user is None:
        request._get_authentication_policy = lambda: create_authentication(
            {
                "authtkt_cookie_name": "__test",
                "authtkt_secret": "123",
            })
    elif user is not None:
        config.testing_securitypolicy(user)
    request.set_property(create_get_user_from_request(
        {"authorized_referers": [request.referer]}),
                         name="user",
                         reify=True)
    return request
Ejemplo n.º 4
0
def main(global_config, **settings):
    """
    This function returns a Pyramid WSGI application.
    """
    del global_config  # Unused

    config = Configurator(
        root_factory=Root, settings=settings,
        locale_negotiator=locale_negotiator,
        authentication_policy=create_authentication(settings)
    )

    # Workaround to not have the error: distutils.errors.DistutilsArgError: no commands supplied
    distutils.core._setup_stop_after = 'config'
    config.include('c2cgeoportal_geoportal')
    distutils.core._setup_stop_after = None

    config.add_translation_dirs('package_gmf_geoportal:locale/')

    # Scan view decorator for adding routes
    config.scan()

    # Add the interfaces
    for interface in config.get_settings().get("interfaces", []):
        add_interface(
            config,
            interface['name'],
            interface.get('type', INTERFACE_TYPE_NGEO),
            default=interface.get('default', False)
        )

    try:
        import ptvsd
        ptvsd.enable_attach(address=('172.17.0.1', 5678))
        # ptvsd.wait_for_attach()
    except ModuleNotFoundError as e:
        pass

    return config.make_wsgi_app()
Ejemplo n.º 5
0
def includeme(config: Configurator) -> None:
    """Initialize the authentication( for a Pyramid app."""
    config.set_authorization_policy(ACLAuthorizationPolicy())
    config.set_authentication_policy(create_authentication(config.get_settings()))
Ejemplo n.º 6
0
def create_dummy_request(additional_settings=None, authentication=True, user=None, *args, **kargs):
    from pyramid.interfaces import IAuthenticationPolicy

    from c2cgeoportal_geoportal import create_get_user_from_request
    from c2cgeoportal_geoportal.lib.authentication import create_authentication

    if additional_settings is None:
        additional_settings = {}

    pyramid.testing.tearDown()

    request = tests.create_dummy_request(
        {
            "functionalities": {"available_in_templates": []},
            "layers": {"geometry_validation": True},
            "admin_interface": {
                "available_functionalities": [{"name": "mapserver_substitution", "single": False}],
                "available_metadata": [{"name": "lastUpdateDateColumn"}, {"name": "lastUpdateUserColumn"}],
            },
        },
        *args,
        **kargs,
    )

    global config
    config = pyramid.testing.setUp(
        request=request,
        registry=request.registry,
        settings=get_settings(),
    )

    request.accept_language = webob.acceptparse.create_accept_language_header(
        "fr-CH,fr;q=0.8,en;q=0.5,en-US;q=0.3"
    )
    request.registry.settings.update(additional_settings)
    request.referer = "http://example.com/app"
    request.path_info_peek = lambda: "main"
    request.interface_name = "main"
    request.get_user = _get_user
    request.c2c_request_id = "test"
    request.matched_route = DummyRoute()
    init_registry(request.registry)

    if authentication and user is None:
        authentication_settings = {
            "authtkt_cookie_name": "__test",
            "authtkt_secret": "long enough secret!!  00000000000000000000000000000000000000000000000",
            "authentication": {},
        }
        authentication_settings.update(additional_settings)

        testing_legacySecurityPolicy(config)
        config.registry.registerUtility(create_authentication(authentication_settings), IAuthenticationPolicy)

    elif user is not None:
        config.testing_securitypolicy(user)
    request.set_property(
        create_get_user_from_request({"authorized_referers": [request.referer]}), name="user", reify=True
    )

    return request