Sha256: b0a6da13b0235ad5e0f81f37462a803817ce76b8d09796dd826ec6c823ec06ee

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 KB

Contents

require 'test_helper'

class SecretsTest < Minitest::Test
  def setup
    @subject = Instana::Secrets.new
  end
  
  def test_equals_ignore_case
    sample_config = {
      "matcher"=>"equals-ignore-case", 
      "list"=>["key"]
    }
    
    url = url_for(%w(key Str kEy KEY))
    assert_redacted @subject.remove_from_query(url, sample_config), %w(key kEy KEY)
  end
  
  def test_equals
    sample_config = {
      "matcher"=>"equals", 
      "list"=>["key", "kEy"]
    }
    
    url = url_for(%w(key Str kEy KEY))
    assert_redacted @subject.remove_from_query(url, sample_config), %w(key kEy)
  end
  
  def test_contains_ignore_case
    sample_config = {
      "matcher"=>"contains-ignore-case", 
      "list"=>["stan"]
    }
    
    url = url_for(%w(instantiate conTESTant sample))
    assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate conTESTant)
  end
  
  def test_contains
    sample_config = {
      "matcher"=>"contains", 
      "list"=>["stan"]
    }
    
    url = url_for(%w(instantiate conTESTant sample))
    assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate)
  
  end
  
  def test_regexp
    sample_config = {
      "matcher"=>"regex", 
      "list"=>["l{2}"]
    }
    
    url = url_for(%w(ball foot move))
    assert_redacted @subject.remove_from_query(url, sample_config), %w(ball) 
  end
  
  private
  
  def url_for(keys)
    url = URI('http://example.com')
    url.query = URI.encode_www_form(keys.map { |k| [k, rand(1..100)]})
    url.to_s
  end
  
  def assert_redacted(str, keys)
    url = URI(str)
    params = CGI.parse(url.query)
    
    assert_equal keys, params.select { |_, v| v == %w(<redacted>) }.keys, 'to be redacted'
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
instana-1.193.4 test/secrets_test.rb
instana-1.193.3 test/secrets_test.rb
instana-1.193.3.pre1 test/secrets_test.rb
instana-1.193.2 test/secrets_test.rb
instana-1.192.1 test/secrets_test.rb
instana-1.192.0 test/secrets_test.rb
instana-1.13.0 test/secrets_test.rb