blinkist-airbrake-scrubber 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42384200d89830615e9c495963632bc2d83f0a07
4
+ data.tar.gz: 2bf61a3d16cb60926ebbefa781bdcaefb5867cd4
5
+ SHA512:
6
+ metadata.gz: 6d47e6602c6612562666687d8e6357c7cf42a7f48060a46ccbdbfec6f19e0e206602678c260b6411f58dc129d9a725292de87441536fa849c5dc2abca60ac5cd
7
+ data.tar.gz: 9d541b33a0883dbe45398f032e943da7414d487c54f4cbb51e54d02cc4504bef1353d6917667b561df4a5cd776bfe156bebdd2efd90be34b13ddd0cd663bc762
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ ruby "2.3.6"
2
+
3
+ source "https://rubygems.org"
4
+ git_source(:github) { |repo| "https://github.com/blinkist/#{repo}.git" }
5
+
6
+ group :test do
7
+ gem "rake"
8
+ gem "rack"
9
+ gem "rspec"
10
+ gem "forgery"
11
+ gem "simplecov"
12
+ gem "dotenv"
13
+ end
14
+
15
+ group :development, :test do
16
+ gem 'awesome_print'
17
+ gem "byebug"
18
+ gem 'memory_profiler'
19
+ gem "ruby-prof"
20
+ end
21
+
22
+ # Specify your gem"s dependencies in blinkist-core.gemspec
23
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Blinkist::Airbrake::Scrubber
2
+
3
+ Blinkist::Airbrake::Scrubber provides an Airbrake scrubbing service to remove various sensitive informations from the notifications, e.g. emails. It does *not* replace Airbrake configuration, but provides some seamless functionality.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem "blinkist-airbrake-scrubber", "0.0.1", github: "blinkist-airbrake-scrubber", tag: "v0.0.1"
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ ## Information
16
+
17
+ ### Extending the functionality
18
+
19
+ To extend the functionality, create a new scrubber file in `lib/blinkist-airbrake-scrubber/scrubbers` folder, like the template:
20
+
21
+ ```ruby
22
+ module Blinkist::Airbrake::Scrubber
23
+ class WubbaLubba
24
+ REGEXP = /[\S]+@[\S]+/i
25
+
26
+ def self.scrub!
27
+ ::Airbrake.add_filter do |notice|
28
+ # Rainbows and unicorns come here:
29
+ notice[:errors].each { |error| error[:message].gsub!(REGEXP, FILTERED) }
30
+ end
31
+ end # def self.scrub!
32
+
33
+ end
34
+ end
35
+ ```
36
+
37
+ Then, add the class to Blinkist::Airbrake::Scrubber's SCRUBBERS list to have it ran after Airbrake.configure
38
+
39
+ ### Applications using this gem
40
+
41
+ There are a few applications available on GitHub that use this gem. For usage see:
42
+
43
+ * blinkist-messenger
44
+
45
+ ### Dependencies
46
+
47
+ This gem has dependency on airbrake (~> 5), it will automatically add it unless already bundled.
48
+
49
+ ## Maintainers
50
+
51
+ * Paweł Komarnicki (https://github.com/pawelkomarnicki)
52
+
53
+ ## Special thanks
54
+
55
+ * Tomek Przedmojski (https://github.com/tprzedmojski) for providing a brilliant way to use Module#prepend :-)
56
+
57
+ ## License
58
+
59
+ Copyright 2018 Blinks Labs GmbH. http://blinkist.com
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task(:default).clear
7
+ task default: [ :spec ]
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
3
+
4
+ require_relative "lib/blinkist-airbrake-scrubber/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "blinkist-airbrake-scrubber"
8
+ gem.version = Blinkist::Airbrake::Scrubber::VERSION
9
+ gem.authors = ["Paweł Komarnicki", "Dinesh Vasudevan"]
10
+ gem.email = ["pawel@blinkist.com", "dinesh@blinkist.com"]
11
+ gem.description = %q{Email scrubbing configuration for Airbrake at Blinkist}
12
+ gem.summary = %q{With this, Airbrake will not leak emails via exception notifications}
13
+ gem.homepage = "https://github.com/blinkist/blinkist-airbrake-scrubber"
14
+ gem.license = "MIT"
15
+
16
+ # Airbrake
17
+ gem.add_dependency "airbrake", "~> 5"
18
+
19
+ gem.files = Dir["{lib,spec}/**/*", "README.md", "Rakefile", "Gemfile", "*.gemspec"]
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ end
@@ -0,0 +1,33 @@
1
+ require 'airbrake'
2
+ Dir[File.expand_path('../../lib/**/*.rb', __FILE__)].each do |f|
3
+ require f
4
+ end
5
+
6
+ # Prepend the original Airbrake module
7
+ module Airbrake
8
+ class << self
9
+ prepend Blinkist::Airbrake::Scrubber
10
+ end
11
+ end
12
+
13
+ # Set up the namespace and run every scrubber listed in SCRUBBERS
14
+ module Blinkist
15
+ module Airbrake
16
+ module Scrubber
17
+ FILTERED = '[Filtered]'
18
+ SCRUBBERS = [ MessageEmail, ParamsEmail, ParamsPassword ]
19
+
20
+ # Override original Airbrake.configure
21
+ def configure(*args, &block)
22
+ super
23
+ ensure
24
+ Blinkist::Airbrake::Scrubber.run!
25
+ end
26
+
27
+ # Run scrubbers
28
+ def self.run!
29
+ SCRUBBERS.each { |scrubber| scrubber::scrub! }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ module Blinkist
2
+ module Airbrake
3
+ module Scrubber
4
+ class MessageEmail
5
+ REGEXP = /[\S]+@[\S]+/i
6
+
7
+ def self.scrub!
8
+ ::Airbrake.add_filter do |notice|
9
+ notice[:errors].each { |error| error[:message].gsub!(REGEXP, FILTERED) }
10
+ end
11
+ end # def self.scrub!
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Blinkist
2
+ module Airbrake
3
+ module Scrubber
4
+ class ParamsEmail
5
+
6
+ def self.scrub!
7
+ ::Airbrake.add_filter do |notice|
8
+ if notice[:params] && notice[:params][:email]
9
+ notice[:params][:email] = FILTERED
10
+ end
11
+ notice
12
+ end
13
+ end # def self.scrub!
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Blinkist
2
+ module Airbrake
3
+ module Scrubber
4
+ class ParamsPassword
5
+
6
+ def self.scrub!
7
+ ::Airbrake.add_filter do |notice|
8
+ if notice[:params] && notice[:params][:password]
9
+ notice[:params][:password] = FILTERED
10
+ end
11
+ notice
12
+ end
13
+ end # def self.scrub!
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module Blinkist
2
+ module Airbrake
3
+ module Scrubber
4
+ VERSION = "1.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'awesome_print'
4
+ require 'byebug'
5
+ require 'securerandom'
6
+
7
+ require 'blinkist-airbrake-scrubber'
8
+
9
+ # This file was generated by the `rspec --init` command. Conventionally, all
10
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
11
+ # Require this file using `require 'spec_helper'` to ensure that it is only
12
+ # loaded once.
13
+ #
14
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
15
+ RSpec.configure do |config|
16
+ config.color = true
17
+ config.full_backtrace=true
18
+
19
+ config.expect_with :rspec do |expectations|
20
+ expectations.syntax = :expect
21
+ end
22
+
23
+ # Run specs in random order to surface order dependencies. If you find an
24
+ # order dependency and want to debug it, you can fix the order by providing
25
+ # the seed, which is printed after each run.
26
+ # --seed 1234
27
+ config.order = 'random'
28
+
29
+ # Configure shared airbrake so it doesn't freak out somewhere else
30
+ Airbrake.configure do |c|
31
+ c.project_id = 1
32
+ c.project_key = 'whatever'
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'blinkist-airbrake-scrubber'
3
+
4
+ describe Airbrake do
5
+ let(:instantiate_airbrake) {
6
+ Airbrake.configure :"notifier_#{ SecureRandom.uuid }" do |c|
7
+ c.project_id = 1
8
+ c.project_key = 'whatever'
9
+ end
10
+ }
11
+
12
+ describe "Module#prepend" do
13
+ it "does have Blinkist::Airbrake::Scrubber as one of the ancestors" do
14
+ expect(described_class.ancestors).to include(Blinkist::Airbrake::Scrubber)
15
+ end
16
+ end
17
+
18
+ describe '.configure' do
19
+ it "does call Blinkist::Airbrake::Scrubber.configure" do
20
+ expect_any_instance_of(Blinkist::Airbrake::Scrubber).to receive(:configure)
21
+ instantiate_airbrake
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blinkist::Airbrake::Scrubber::MessageEmail do
4
+
5
+ describe "Structure" do
6
+ it "has REGEXP constant" do
7
+ expect(described_class.constants).to include(:REGEXP)
8
+ end
9
+
10
+ it "has scrub! method" do
11
+ expect(described_class).to respond_to(:scrub!)
12
+ end
13
+ end
14
+
15
+ describe "self.scrub!" do
16
+ subject { described_class::scrub! }
17
+
18
+ it "adds the filter" do
19
+ expect(Airbrake).to receive(:add_filter)
20
+ subject
21
+ end
22
+ end
23
+
24
+ # It's ridiculously hard to peek into Airbrake::Notice
25
+ # Instead verify the functionality here
26
+ describe "scrubber functionality" do
27
+ let(:filtered) { Blinkist::Airbrake::Scrubber::FILTERED }
28
+ let(:regexp) { described_class::REGEXP }
29
+
30
+ let(:valid_domains) { %w{ example.org exam-ple.org exam.ple.org e-xam.ple.org e-xam.p-le.org e.x.a.m.p.l.e.co.uk } }
31
+ let(:valid_usernames) { %w{ username user.name user+name user-name user_name } }
32
+ let(:valid_emails) { valid_usernames.product(valid_domains).map { |row| row.join '@' } }
33
+ let(:invalid_emails) { %w{ user@example user@example. user!@example.org us@r@example.org us&r@example.com } }
34
+
35
+ context "Pure email content" do
36
+ it "filters out valid emails" do
37
+ puts "Verifying: #{ valid_emails.join ', ' }"
38
+ valid_emails.each do |email|
39
+ expect(email.gsub(regexp, filtered)).to eq(filtered)
40
+ end
41
+ end
42
+
43
+ it "filters out invalid emails" do
44
+ puts "Verifying: #{ invalid_emails.join ', ' }"
45
+ invalid_emails.each do |email|
46
+ expect(email.gsub(regexp, filtered)).to eq(filtered)
47
+ end
48
+ end
49
+ end
50
+
51
+ context "Email inside a text" do
52
+ let(:text) { "Erorr bla bla EMAIL bla bla bla" }
53
+
54
+ it "filters out valid emails" do
55
+ puts "Verifying: #{ valid_emails.join ', ' }"
56
+ valid_emails.each do |email|
57
+ content = text.gsub('EMAIL', email)
58
+ expect(content.gsub(regexp, filtered)).to eq(text.gsub('EMAIL', filtered))
59
+ end
60
+ end
61
+
62
+ it "filters out invalid emails" do
63
+ puts "Verifying: #{ invalid_emails.join ', ' }"
64
+ invalid_emails.each do |email|
65
+ content = text.gsub('EMAIL', email)
66
+ expect(content.gsub(regexp, filtered)).to eq(text.gsub('EMAIL', filtered))
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blinkist::Airbrake::Scrubber::ParamsEmail do
4
+ let(:notifier) { Airbrake[:default] }
5
+ let(:notice) {
6
+ Airbrake[:default].build_notice(
7
+ Exception.new('whatever'),
8
+ { email: 'user@example.org', password: 'whatever', param: 'whatever' }
9
+ )
10
+ }
11
+
12
+ describe "Structure" do
13
+ it "has scrub! method" do
14
+ expect(described_class).to respond_to(:scrub!)
15
+ end
16
+ end
17
+
18
+ describe "self.scrub!" do
19
+ it "adds the filter" do
20
+ expect(Airbrake).to receive(:add_filter)
21
+ described_class::scrub!
22
+ end
23
+
24
+ it "scrubs the email from the params hash" do
25
+ notifier.instance_variable_get(:@filter_chain).refine(notice)
26
+ expect(notice[:params][:email]).to eq(Blinkist::Airbrake::Scrubber::FILTERED)
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Blinkist::Airbrake::Scrubber::ParamsPassword do
4
+ let(:notifier) { Airbrake[:default] }
5
+ let(:notice) {
6
+ Airbrake[:default].build_notice(
7
+ Exception.new('whatever'),
8
+ { email: 'user@example.org', password: 'whatever', param: 'whatever' }
9
+ )
10
+ }
11
+
12
+ describe "Structure" do
13
+ it "has scrub! method" do
14
+ expect(described_class).to respond_to(:scrub!)
15
+ end
16
+ end
17
+
18
+ describe "self.scrub!" do
19
+ it "adds the filter" do
20
+ expect(Airbrake).to receive(:add_filter)
21
+ described_class::scrub!
22
+ end
23
+
24
+ it "scrubs the password from the params hash" do
25
+ notifier.instance_variable_get(:@filter_chain).refine(notice)
26
+ expect(notice[:params][:password]).to eq(Blinkist::Airbrake::Scrubber::FILTERED)
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'securerandom'
3
+ require 'blinkist-airbrake-scrubber'
4
+
5
+ describe Blinkist::Airbrake::Scrubber do
6
+ let(:instantiate_airbrake) {
7
+ Airbrake.configure :"notifier_#{ SecureRandom.uuid }" do |c|
8
+ c.project_id = 1
9
+ c.project_key = 'whatever'
10
+ end
11
+ }
12
+
13
+ describe "Constants" do
14
+ it "has FILTERED constant" do
15
+ expect(Blinkist::Airbrake::Scrubber.constants).to include(:FILTERED)
16
+ end
17
+
18
+ it "has explicit FILTERED constant content" do
19
+ expect(Blinkist::Airbrake::Scrubber::FILTERED).to eq('[Filtered]')
20
+ end
21
+
22
+ it "has SCRUBBERS constant" do
23
+ expect(Blinkist::Airbrake::Scrubber.constants).to include(:SCRUBBERS)
24
+ end
25
+
26
+ it "has list of scrubbers in SCRUBBERS" do
27
+ expect(Blinkist::Airbrake::Scrubber::SCRUBBERS.is_a?(Array)).to be true
28
+ end
29
+ end
30
+
31
+ describe ".configure(*args, &block)" do
32
+ it "calls super Airbrake.configure(*args, &block)" do
33
+ expect(Airbrake).to receive(:configure)
34
+ instantiate_airbrake
35
+ end
36
+
37
+ it "calls Blinkist::Airbrake::Scrubber.run!" do
38
+ expect(Blinkist::Airbrake::Scrubber).to receive(:run!)
39
+ instantiate_airbrake
40
+ end
41
+ end
42
+
43
+ describe "self.run!" do
44
+ it "runs ::scrub! for every scrubber declared in SCRUBBERS" do
45
+ Blinkist::Airbrake::Scrubber::SCRUBBERS.each do |scrubber|
46
+ expect(scrubber).to receive(:scrub!)
47
+ end
48
+ instantiate_airbrake
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,18 @@
1
+
2
+ require 'spec_helper'
3
+ require 'blinkist-airbrake-scrubber/version'
4
+
5
+ describe Blinkist::Airbrake::Scrubber::VERSION do
6
+
7
+ it 'provides the current version' do
8
+ version = Blinkist::Airbrake::Scrubber::VERSION
9
+ expect(version).to_not be nil
10
+ expect(version.instance_of?(String)).to be true
11
+ end
12
+
13
+ it 'equals 1.0.1 for auto-check purposes' do
14
+ version = Blinkist::Airbrake::Scrubber::VERSION
15
+ expect(version).to eq '1.1.0'
16
+ end
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blinkist-airbrake-scrubber
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paweł Komarnicki
8
+ - Dinesh Vasudevan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-05-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: airbrake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '5'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '5'
28
+ description: Email scrubbing configuration for Airbrake at Blinkist
29
+ email:
30
+ - pawel@blinkist.com
31
+ - dinesh@blinkist.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - blinkist-airbrake-scrubber.gemspec
40
+ - lib/blinkist-airbrake-scrubber.rb
41
+ - lib/blinkist-airbrake-scrubber/scrubbers/message_email.rb
42
+ - lib/blinkist-airbrake-scrubber/scrubbers/params_email.rb
43
+ - lib/blinkist-airbrake-scrubber/scrubbers/params_password.rb
44
+ - lib/blinkist-airbrake-scrubber/version.rb
45
+ - spec/spec_helper.rb
46
+ - spec/specs/lib/airbrake_spec.rb
47
+ - spec/specs/lib/blinkist-airbrake-scrubber/scrubbers/message_email_spec.rb
48
+ - spec/specs/lib/blinkist-airbrake-scrubber/scrubbers/params_email_spec.rb
49
+ - spec/specs/lib/blinkist-airbrake-scrubber/scrubbers/params_password_spec.rb
50
+ - spec/specs/lib/blinkist_airbrake_scrubber_spec.rb
51
+ - spec/specs/version_spec.rb
52
+ homepage: https://github.com/blinkist/blinkist-airbrake-scrubber
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.5.2.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: With this, Airbrake will not leak emails via exception notifications
76
+ test_files:
77
+ - spec/spec_helper.rb
78
+ - spec/specs/lib/airbrake_spec.rb
79
+ - spec/specs/lib/blinkist-airbrake-scrubber/scrubbers/message_email_spec.rb
80
+ - spec/specs/lib/blinkist-airbrake-scrubber/scrubbers/params_email_spec.rb
81
+ - spec/specs/lib/blinkist-airbrake-scrubber/scrubbers/params_password_spec.rb
82
+ - spec/specs/lib/blinkist_airbrake_scrubber_spec.rb
83
+ - spec/specs/version_spec.rb