Skip to content

Instantly share code, notes, and snippets.

@thbar
Created October 26, 2011 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thbar/1317815 to your computer and use it in GitHub Desktop.
Save thbar/1317815 to your computer and use it in GitHub Desktop.
Removing sensitive resque args from airbrake notifications
Resque::Failure::SensitiveAirbrake.configure do |config|
config.api_key = @config['airbrake']['api_key']
config.params_filters << 'my_sensitive_job_arg'
config.secure = @config['airbrake']['secure']
config.proxy_host = @config['airbrake']['proxy_host']
config.proxy_port = @config['airbrake']['proxy_port']
config.host = @config['airbrake']['host']
config.logger = Logger.new(STDOUT)
end
require 'resque/failure'
require 'resque/failure/base'
require 'resque/failure/airbrake'
module Resque
module Failure
class SensitiveAirbrake < Airbrake
@klass = ::Airbrake
def payload
args = super['args'].first.dup
::Airbrake.configuration.params_filters.each do |filtered_param|
args[filtered_param] = '[SENSITIVE-FILTERED]' if args[filtered_param]
end
super.dup.merge('args' => [args])
end
end
end
end
require File.dirname(__FILE__) + '/../test_helper'
require 'sensitive_airbrake'
describe Resque::Failure::SensitiveAirbrake do
before(:each) do
@worker = mock('worker')
@exception = Exception.new('something bad occurred')
@exception.set_backtrace []
@queue = 'some-queue'
@payload = {}
@payload['class'] = 'SomeJob'
@payload['args'] = [{ 'sensitive' => 'this is sensitive information', 'safe' => 'this is safe information' }]
end
it 'should keep all the payload_args by default' do
payload = Resque::Failure::SensitiveAirbrake.new(@exception, @worker, @queue, @payload).payload.inspect
payload.should include 'sensitive information'
payload.should include 'safe information'
end
it 'should NOT keep sensitive information from the payload_args' do
Resque::Failure::SensitiveAirbrake.configure do |config|
config.params_filters << 'sensitive'
end
payload = Resque::Failure::SensitiveAirbrake.new(@exception, @worker, @queue, @payload).payload.inspect
payload.should_not include 'sensitive information'
payload.should include 'safe information'
end
it 'should not add password (default params filters)' do
Resque::Failure::SensitiveAirbrake.configure do |config|
config.params_filters << 'sensitive'
end
payload = Resque::Failure::SensitiveAirbrake.new(@exception, @worker, @queue, @payload).payload.inspect
payload.should_not include 'password'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment