def test_authenticate_success(request_context, monkeypatch, user_id): monkeypatch.setattr(login, "_check_auth", lambda r: user_id) assert user.id is None with login.authenticate(request) as authenticated: assert authenticated is True assert user.id == user_id assert user.id is None
def test_authenticate_fails(request_context, monkeypatch, user_id): monkeypatch.setattr(login, "_check_auth", lambda r: None) assert user.id is None with login.authenticate(request) as authenticated: assert authenticated is False assert user.id is None assert user.id is None
def _call_auth(): with login.authenticate(request) as authenticated: if not authenticated: return _handle_not_authenticated() # When displaying the crash report message, the user authentication context # has already been left. We need to preserve this information to be able to # show the correct message for the current user. g.may_see_crash_reports = config.user.may( "general.see_crash_reports") # This may raise an exception with error messages, which will then be displayed to the user. _ensure_general_access() # Initialize the multisite cmk.gui.i18n. This will be replaced by # language settings stored in the user profile after the user # has been initialized _localize_request() # Update the UI theme with the attribute configured by the user. # Returns None on first load assert config.user.id is not None theme = cmk.gui.userdb.load_custom_attr(config.user.id, 'ui_theme', lambda x: x) html.set_theme(theme) func() return html.response
def test_web_server_auth_session(user_id): environ = dict(create_environ(), REMOTE_USER=str(user_id)) with application_and_request_context(environ): assert user.id is None with login.authenticate(request) as authenticated: assert authenticated is True assert user.id == user_id assert session.user_id == user.id assert user.id is None
def test_web_server_auth_session(user_id): environ = dict(create_environ(), REMOTE_USER=str(user_id)) with AppContext(DummyApplication(environ, None)), \ RequestContext(htmllib.html(http.Request(environ))): assert user.id is None with login.authenticate(request) as authenticated: assert authenticated is True assert user.id == user_id assert session.user_id == user.id assert user.id is None
def _call_auth(): if not login.authenticate(request): _handle_not_authenticated() return # This may raise an exception with error messages, which will then be displayed to the user. _ensure_general_access() # Initialize the multisite cmk.gui.i18n. This will be replaced by # language settings stored in the user profile after the user # has been initialized _localize_request() # Update the UI theme with the attribute configured by the user html.set_theme(config.user.get_attribute("ui_theme")) func()
def _call_auth(): if not login.authenticate(request): return _handle_not_authenticated() # This may raise an exception with error messages, which will then be displayed to the user. _ensure_general_access() # Initialize the multisite cmk.gui.i18n. This will be replaced by # language settings stored in the user profile after the user # has been initialized _localize_request() # Update the UI theme with the attribute configured by the user. # Returns None on first load assert config.user.id is not None theme = cmk.gui.userdb.load_custom_attr(config.user.id, 'ui_theme', lambda x: x) html.set_theme(theme) func() return html.response