class Pentest::BaseChecker
  class << self
    attr_reader :description
  end

  def initialize(endpoint, params)
    @params = params
    @warnings = []
    @endpoint = endpoint
    @route = endpoint.route
    @app_path = endpoint.app_path
  end

  private

  def dispatch(payload)
    @endpoint.dispatch(payload)
  end

  def get_status(err)
    if err.nil?
      nil
    elsif err.respond_to?(:status)
      err.status
    elsif ActiveRecord::RecordNotFound === err || ActionController::UrlGenerationError === err
      404
    else
      500
    end
  end

  def normalize_error(err, payload)
    return if err.nil?

    status = get_status(err)

    return if status.nil? || status / 100 != 5
    
    message = err.message.lines.first.strip
    payload.params_hash.values.sort_by(&:size).reverse.each do |param|
      message = message.gsub(param.inspect, '"[parameter]"')
      if param.size >= 4
        message = message.gsub(param, '[parameter]')
      end
    end

    message
  end
end
