Sha256: f07b8b6379a7c7a35face7f686e045b44dc83ac604c7742d4324df59233e4cff

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

class LHC::HeadersScrubber < LHC::Scrubber
  def initialize(data, auth_options)
    super(data)
    @auth_options = auth_options
    scrub!
    scrub_auth_headers!
  end

  private

  attr_reader :auth_options

  def scrub_elements
    LHC.config.scrubs[:headers]
  end

  def scrub_auth_headers!
    return if scrub_auth_elements.blank?
    return if auth_options.blank?

    scrub_basic_authentication_headers! if scrub_auth_elements.include?(:basic)
    scrub_bearer_authentication_headers! if scrub_auth_elements.include?(:bearer)
  end

  def scrub_basic_authentication_headers!
    return if !scrub_basic_authentication_headers?

    scrubbed['Authorization'].gsub!(auth_options[:basic][:base_64_encoded_credentials], SCRUB_DISPLAY)
  end

  def scrub_bearer_authentication_headers!
    return if !scrub_bearer_authentication_headers?

    scrubbed['Authorization'].gsub!(auth_options[:bearer_token], SCRUB_DISPLAY)
  end

  def scrub_basic_authentication_headers?
    auth_options[:basic].present? &&
      scrubbed['Authorization'].present? &&
      scrubbed['Authorization'].include?(auth_options[:basic][:base_64_encoded_credentials])
  end

  def scrub_bearer_authentication_headers?
    auth_options[:bearer].present? &&
      scrubbed['Authorization'].present? &&
      scrubbed['Authorization'].include?(auth_options[:bearer_token])
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lhc-15.2.0 lib/lhc/scrubbers/headers_scrubber.rb
lhc-15.1.3 lib/lhc/scrubbers/headers_scrubber.rb
lhc-15.1.2 lib/lhc/scrubbers/headers_scrubber.rb
lhc-15.1.1 lib/lhc/scrubbers/headers_scrubber.rb
lhc-15.1.0 lib/lhc/scrubbers/headers_scrubber.rb
lhc-16.0.0.pre.pro2162.2 lib/lhc/scrubbers/headers_scrubber.rb
lhc-16.0.0.pre.pro2162 lib/lhc/scrubbers/headers_scrubber.rb
lhc-15.0.1 lib/lhc/scrubbers/headers_scrubber.rb