Skip to content

Commit

Permalink
chore: use coveralls (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Jun 7, 2023
1 parent 4c43d79 commit 7cc1153
Show file tree
Hide file tree
Showing 21 changed files with 465 additions and 339 deletions.
26 changes: 6 additions & 20 deletions .github/workflows/ci.yml → .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: CI
name: CI linux
on:
push:
branches:
- master
pull_request:

jobs:
Expand All @@ -16,6 +14,7 @@ jobs:
- { ruby_version: 2.7 }
- { ruby_version: 3.0 }
- { ruby_version: 3.1 }
- { ruby_version: 3.2 }
- { ruby_version: jruby }
steps:
- uses: actions/checkout@v1
Expand All @@ -31,22 +30,9 @@ jobs:
bundle install --jobs 4 --retry 3 --no-cache
bundle exec rspec
- uses: coverallsapp/github-action@master
- uses: coverallsapp/github-action@v2
env:
COVERALLS_SERVICE_NUMBER: ${{ github.sha }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: ruby-${{ matrix.ruby_version }}
path-to-lcov: ./coverage/lcov/sentry-sanitizer.lcov
flag-name: ruby-${{ join(matrix.*, '-') }}
parallel: true

coverage:
needs: rspec
name: Unit tests
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
carryforward: "ruby-2.5,ruby-2.7,ruby-3.0,ruby-3.1,ruby-jruby"
parallel-finished: true

39 changes: 39 additions & 0 deletions .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI macos
on:
push:
pull_request:

jobs:
rspec:
name: Unit tests
runs-on: macos-latest
strategy:
matrix:
include:
- { ruby_version: 2.5 }
- { ruby_version: 2.7 }
- { ruby_version: 3.0 }
- { ruby_version: 3.1 }
- { ruby_version: 3.2 }
- { ruby_version: jruby }
steps:
- uses: actions/checkout@v1

- name: Set up Ruby ${{ matrix.ruby_version }}
uses: ruby/setup-ruby@v1
with:
bundler: 2
ruby-version: ${{ matrix.ruby_version }}

- name: Run specs
run: |
bundle install --jobs 4 --retry 3 --no-cache
bundle exec rspec
- uses: coverallsapp/github-action@v2
env:
COVERALLS_SERVICE_NUMBER: ${{ github.sha }}
with:
flag-name: ruby-${{ join(matrix.*, '-') }}
parallel: true

38 changes: 38 additions & 0 deletions .github/workflows/coveralls-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Coveralls
on:
push:
pull_request:

jobs:
coveralls:
name: Coveralls Report
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- uses: actions/checkout@v3

- name: Wait on tests (PR)
uses: lewagon/wait-on-check-action@v1.3.1
if: github.event_name == 'pull_request'
with:
ref: ${{ github.event.pull_request.head.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10 # seconds
running-workflow-name: Coveralls Report
allowed-conclusions: success,skipped,cancelled,failure

- name: Wait on tests
uses: lewagon/wait-on-check-action@v1.3.1
with:
ref: ${{ github.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10 # seconds
running-workflow-name: Coveralls Report
allowed-conclusions: success,skipped,cancelled,failure

- uses: coverallsapp/github-action@v2
env:
COVERALLS_SERVICE_NUMBER: ${{ github.sha }}
with:
carryforward: "ruby-2.5,ruby-2.6,ruby-2.7,ruby-3.0,ruby-3.1,ruby-jruby"
parallel-finished: true
36 changes: 36 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
AllCops:
NewCops: enable
SuggestExtensions: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Metrics/BlockLength:
Enabled: false

Style/Documentation:
Enabled: false

Layout/LineLength:
Enabled: false

Naming/FileName:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Gemspec/RequiredRubyVersion:
Enabled: false

Style/SelectByRegexp:
Enabled: false

Style/CaseLikeIf:
Enabled: false
13 changes: 10 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in sentry-sanitizer.gemspec
gemspec

gem 'simplecov', require: false, group: :test
gem 'simplecov-lcov', require: false, group: :test
gem "rubocop", "~> 1.28.2"
gem "simplecov", require: false, group: :test

gem "bundler", ">= 1.17"
gem "rack"
gem "rake", "~> 10.0"
gem "rspec", "~> 3.0"
26 changes: 21 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ PATH
GEM
remote: https://rubygems.org/
specs:
codecov (0.6.0)
simplecov (>= 0.15, < 0.22)
ast (2.4.2)
concurrent-ruby (1.1.10)
diff-lcs (1.5.0)
docile (1.4.0)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
rack (2.2.3.1)
rainbow (3.1.1)
rake (10.5.0)
regexp_parser (2.8.0)
rexml (3.2.5)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
Expand All @@ -27,26 +32,37 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.28.2)
parallel (~> 1.10)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.17.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
sentry-ruby (5.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
simplecov (0.18.5)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
simplecov-lcov (0.8.0)
unicode-display_width (2.4.2)

PLATFORMS
ruby

DEPENDENCIES
bundler (>= 1.17)
codecov
rack
rake (~> 10.0)
rspec (~> 3.0)
rubocop (~> 1.28.2)
sentry-sanitizer!
simplecov
simplecov-lcov

BUNDLED WITH
2.3.16
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "sentry/sanitizer"
Expand Down
6 changes: 6 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pre-commit:
commands:
lint:
run: bundle exec rubocop -A {staged_files}
glob: "*.rb"
stage_fixed: true
6 changes: 4 additions & 2 deletions lib/sentry-sanitizer.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
require 'sentry/sanitizer/version'
require 'sentry/sanitizer'
# frozen_string_literal: true

require "sentry/sanitizer/version"
require "sentry/sanitizer"
10 changes: 6 additions & 4 deletions lib/sentry/sanitizer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require 'sentry-ruby'
require 'sentry/integrable'
require 'sentry/sanitizer/configuration'
# frozen_string_literal: true

require "sentry-ruby"
require "sentry/integrable"
require "sentry/sanitizer/configuration"

module Sentry
module Sanitizer
extend Integrable

register_integration name: 'sanitizer', version: Sentry::Sanitizer::VERSION
register_integration name: "sanitizer", version: Sentry::Sanitizer::VERSION
end
end
25 changes: 14 additions & 11 deletions lib/sentry/sanitizer/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

module Sentry
module Sanitizer
class Cleaner
DEFAULT_MASK = '[FILTERED]'.freeze
DEFAULT_MASK = "[FILTERED]"
DEFAULT_SENSITIVE_HEADERS = %w[
Authorization
X-Xsrf-Token
Expand All @@ -21,7 +23,7 @@ def call(event)
if event.is_a?(Sentry::Event)
sanitize(event, :object) if event.request
elsif event.is_a?(Hash)
sanitize(event, :stringified_hash) if event['request']
sanitize(event, :stringified_hash) if event["request"]
sanitize(event, :symbolized_hash) if event[:request]
end
end
Expand All @@ -35,11 +37,11 @@ def sanitize(event, type)
event.request.query_string = sanitize_query_string(event.request.query_string)
event.extra = sanitize_data(event.extra)
when :stringified_hash
event['request']['data'] = sanitize_data(event['request']['data'])
event['request']['headers'] = sanitize_headers(event['request']['headers'])
event['request']['cookies'] = sanitize_cookies(event['request']['cookies'])
event['request']['query_string'] = sanitize_query_string(event['request']['query_string'])
event['extra'] = sanitize_data(event['extra'])
event["request"]["data"] = sanitize_data(event["request"]["data"])
event["request"]["headers"] = sanitize_headers(event["request"]["headers"])
event["request"]["cookies"] = sanitize_cookies(event["request"]["cookies"])
event["request"]["query_string"] = sanitize_query_string(event["request"]["query_string"])
event["extra"] = sanitize_data(event["extra"])
when :symbolized_hash
event[:request][:data] = sanitize_data(event[:request][:data])
event[:request][:headers] = sanitize_headers(event[:request][:headers])
Expand Down Expand Up @@ -71,6 +73,7 @@ def sanitize_headers(headers)
headers.transform_values { mask }
when Array
return headers unless http_headers.size.positive?

http_headers_regex = sensitive_regexp(http_headers)

headers.keys.select { |key| key.match?(http_headers_regex) }.each do |key|
Expand All @@ -95,14 +98,14 @@ def sanitize_query_string(query_string)
return query_string unless do_query_string
return query_string unless query_string.is_a? String

sanitized_array = query_string.split('&').map do |kv_pair|
k, v = kv_pair.split('=')
sanitized_array = query_string.split("&").map do |kv_pair|
k, v = kv_pair.split("=")
new_v = sanitize_string(k, v)

"#{k}=#{new_v}"
end

sanitized_array.join('&')
sanitized_array.join("&")
end

def sanitize_value(value, key)
Expand Down Expand Up @@ -145,7 +148,7 @@ def sensitive_fields
end

def sensitive_regexp(fields)
Regexp.new(fields.map { |field| "\\b#{field}\\b" }.join('|'), 'i')
Regexp.new(fields.map { |field| "\\b#{field}\\b" }.join("|"), "i")
end
end
end
Expand Down
Loading

0 comments on commit 7cc1153

Please sign in to comment.