<commit_before>module ChecksAuthentication

  include LoadsSession

  private

  def app_session
    token = token_from_request
    raise AuthenticationFailure.no_token(t("session.no_token_in_header")) if token.blank?
    get_session
  end

  # a before filter requiring user to be logged in
  def check_authentication
    session = app_session
    handle_device_blacklisted(session) if session && session.device_blacklisted?
    raise AuthenticationFailure.bad_token(t("session.invalid_token")) if session.nil?
  end

  def handle_authentication_failure(auth_failure)
    if auth_failure.token_provided?
      Session.remove_from_cookies cookies
      render_error_response ErrorResponse.unauthorized(t("session.invalid_token"))
    else
      respond_to do |format|
        format.html { redirect_to(:login) }
        format.any(:xml,:json) { render_error_response ErrorResponse.unauthorized(t("session.no_token_provided")) }
      end
    end<commit_msg>[#1540] Faris : Fixed failing unit tests.<commit_after>module ChecksAuthentication

  include LoadsSession

  private

  def app_session
    token = token_from_request
    raise AuthenticationFailure.no_token(I18n.t("session.no_token_in_header")) if token.blank?
    get_session
  end

  # a before filter requiring user to be logged in
  def check_authentication
    session = app_session
    handle_device_blacklisted(session) if session && session.device_blacklisted?
    raise AuthenticationFailure.bad_token(I18n.t("session.invalid_token")) if session.nil?
  end

  def handle_authentication_failure(auth_failure)
    if auth_failure.token_provided?
      Session.remove_from_cookies cookies
      render_error_response ErrorResponse.unauthorized(I18n.t("session.invalid_token"))
    else
      respond_to do |format|
        format.html { redirect_to(:login) }
        format.any(:xml,:json) { render_error_response ErrorResponse.unauthorized(I18n.t("session.no_token_provided")) }
      end
    end
{'fraction_non_alphanumeric': 0.07492354740061162, 'fraction_numerical': 0.0061162079510703364, 'mean_word_length': 4.422651933701657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3386341', 'n_tokens_mistral': 585, 'n_tokens_neox': 562, 'n_words': 116}