trackets 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/features/rails.feature +27 -0
- data/features/step_definitions/rails_steps.rb +62 -0
- data/features/support/common.rb +11 -0
- data/features/support/env.rb +9 -0
- data/features/support/rails.rb +43 -0
- data/features/support/templates/trackets_interceptor.rb +9 -0
- data/lib/trackets/client.rb +24 -2
- data/lib/trackets/configuration.rb +4 -2
- data/lib/trackets/params.rb +43 -0
- data/lib/trackets/version.rb +1 -1
- data/trackets.gemspec +4 -1
- metadata +59 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ab51f862a68579d25a95431d01837188a576643
|
4
|
+
data.tar.gz: 9ab4073d18a851ce750e1f515cf1a373dc1c792c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f3934d1d485647b2820b5145b320b0458be583ffbdc0c79069333a4432a9807c23b4846843fb2c1b5a6193e64fe2334daf86988e3bd6e2995bff5db62b804ea
|
7
|
+
data.tar.gz: 65d9ba622500cf4f0ed079ecf70bcafd4bec459d8c2ce916686a9f302f466d17156355a4e5afe5a88fcb3ce23bc8294fa6f69664a279ec06046a0504903ff4a5
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Gem works in Rails application
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I'm in a new Rails application named "trackets_test"
|
5
|
+
|
6
|
+
Scenario: Rescue an exception in a controller
|
7
|
+
When I configure an app to use Trackets
|
8
|
+
And I define action "test#index" to
|
9
|
+
"""
|
10
|
+
raise "This is testing error"
|
11
|
+
"""
|
12
|
+
And I define route "/test" to "test#index"
|
13
|
+
And I request "http://foo.bar:31337/test"
|
14
|
+
Then I should receive notification to Trackets server
|
15
|
+
|
16
|
+
Scenario: Send filtered params to Trackets when there's exception in Rails
|
17
|
+
When I configure an app to use Trackets
|
18
|
+
And I define action "test#index" to
|
19
|
+
"""
|
20
|
+
raise "This is testing error"
|
21
|
+
"""
|
22
|
+
And I define route "/test" to "test#index"
|
23
|
+
And I request "http://foo.bar:31337/test?cvv=7739&name=John"
|
24
|
+
Then I should receive notification to Trackets server
|
25
|
+
And last notice params for key "name" is "John"
|
26
|
+
And last notice params for key "cvv" is "[FILTERED]"
|
27
|
+
And last notice params should not contain "7739"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
3
|
+
Given(/^I'm in a new Rails application named "(.*?)"$/) do |app_name|
|
4
|
+
step "I successfully run `rails new #{app_name} --skip-gemfile -O -T`"
|
5
|
+
step %{I cd to "#{app_name}"}
|
6
|
+
@app_name = app_name
|
7
|
+
end
|
8
|
+
|
9
|
+
When(/^I configure an app to use Trackets$/) do
|
10
|
+
step %{I copy "trackets_interceptor.rb" to apps "config/initializers"}
|
11
|
+
step "I successfully run `rails g trackets:install my-api-key`"
|
12
|
+
|
13
|
+
additions =<<-EOS
|
14
|
+
config.api_url = "http://trackets.com"
|
15
|
+
EOS
|
16
|
+
|
17
|
+
replace_in_file(File.join(@dirs, "config", "initializers", "trackets.rb"), /^end$/, "#{additions}\nend")
|
18
|
+
end
|
19
|
+
|
20
|
+
When(/^I copy "(.*?)" to apps "(.*?)"$/) do |template_name, target_path|
|
21
|
+
template = File.join(TEMPLATES_DIR, template_name)
|
22
|
+
target = File.join(@dirs, target_path)
|
23
|
+
|
24
|
+
FileUtils.cp(template, target)
|
25
|
+
end
|
26
|
+
|
27
|
+
When(/^I define action "(.*?)" to$/) do |controller_and_action, code|
|
28
|
+
define_controller_action_to(controller_and_action, code)
|
29
|
+
end
|
30
|
+
|
31
|
+
When(/^I define route "(.*?)" to "(.*?)"$/) do |route, target|
|
32
|
+
route_definition = %{get "#{route}", to: "#{target}"}
|
33
|
+
replace_in_file(File.join(@dirs, "config", "routes.rb"), /^end$/, "#{route_definition}\nend")
|
34
|
+
end
|
35
|
+
|
36
|
+
When(/^I request "(.*?)"$/) do |url|
|
37
|
+
script =<<-EOS
|
38
|
+
require File.expand_path('../config/environment', __FILE__)
|
39
|
+
|
40
|
+
env = Rack::MockRequest.env_for(#{url.inspect})
|
41
|
+
p #{@app_name.classify}::Application.call(env)
|
42
|
+
EOS
|
43
|
+
|
44
|
+
File.open(File.join(@dirs, "script.rb"), "w") { |f| f.write(script) }
|
45
|
+
step "I run `rails r script.rb`"
|
46
|
+
end
|
47
|
+
|
48
|
+
Then(/^I should receive notification to Trackets server$/) do
|
49
|
+
expect(requests.size).to be > 0
|
50
|
+
end
|
51
|
+
|
52
|
+
Then(/^last notice params should (?:(not ))?contain "(.*?)"$/) do |negator, string|
|
53
|
+
if negator
|
54
|
+
last_notice_serialized_data.should_not match string
|
55
|
+
else
|
56
|
+
last_notice_serialized_data.should match string
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Then(/^last notice params for key "(.*?)" is "(.*?)"$/) do |key, val|
|
61
|
+
last_notice_params_for(key).should eq val
|
62
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module RailsHelpers
|
2
|
+
|
3
|
+
def requests
|
4
|
+
path = File.join(@dirs, "request_log.txt")
|
5
|
+
|
6
|
+
if File.exist?(path)
|
7
|
+
File.foreach(path).map { |l| JSON.parse(l) }
|
8
|
+
else
|
9
|
+
[]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def last_notice
|
14
|
+
requests.last
|
15
|
+
end
|
16
|
+
|
17
|
+
def last_notice_serialized_data
|
18
|
+
last_notice["rack.input"].first
|
19
|
+
end
|
20
|
+
|
21
|
+
def last_notice_form_data
|
22
|
+
CGI::parse(last_notice_serialized_data)
|
23
|
+
end
|
24
|
+
|
25
|
+
def last_notice_params_for(key)
|
26
|
+
last_notice_form_data["error[params][#{key}]"].first
|
27
|
+
end
|
28
|
+
|
29
|
+
def define_controller_action_to(controller_and_action, code)
|
30
|
+
controller, action = controller_and_action.split("#")
|
31
|
+
|
32
|
+
File.open(File.join(@dirs, "app", "controllers", "#{controller}_controller.rb"), "w") do |f|
|
33
|
+
f.puts "class #{controller.classify}Controller < ApplicationController"
|
34
|
+
f.puts " def #{action}"
|
35
|
+
f.puts code
|
36
|
+
f.puts " end"
|
37
|
+
f.puts "end"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
World(RailsHelpers)
|
data/lib/trackets/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "httparty"
|
2
2
|
require "trackets/backtrace"
|
3
|
+
require "trackets/params"
|
3
4
|
|
4
5
|
module Trackets
|
5
6
|
class Client
|
@@ -25,20 +26,41 @@ module Trackets
|
|
25
26
|
@backtrace ||= Backtrace.new(exception.backtrace)
|
26
27
|
end
|
27
28
|
|
29
|
+
def params
|
30
|
+
@params ||= Params.new(env)
|
31
|
+
end
|
32
|
+
|
28
33
|
def whitelisted_env
|
29
34
|
env.reject { |k,v| !Trackets.configuration.whitelisted_env.include?(k) }
|
30
35
|
end
|
31
36
|
|
37
|
+
def filtered_env
|
38
|
+
whitelisted_env.inject({}) do |result, (key, val)|
|
39
|
+
result[key] = filter_env_val(val) if key && val =~ /\S/
|
40
|
+
result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def filter_env_val(value)
|
45
|
+
value.scan(/(?:^|&|\?)([^=?&]+)=([^&]+)/).each do |match|
|
46
|
+
next unless params.blacklisted?(match[0])
|
47
|
+
value.gsub!(/#{match[1]}/, '[FILTERED]')
|
48
|
+
end
|
49
|
+
|
50
|
+
value
|
51
|
+
end
|
52
|
+
|
32
53
|
def payload
|
33
54
|
{
|
34
55
|
language: "ruby",
|
35
56
|
message: exception.message,
|
36
57
|
class_name: exception.class.to_s,
|
37
58
|
stacktrace: backtrace.parse.join("\n"),
|
38
|
-
env:
|
59
|
+
env: filtered_env,
|
39
60
|
environment_name: config.environment_name,
|
40
61
|
project_root: config.project_root,
|
41
|
-
framework: config.framework
|
62
|
+
framework: config.framework,
|
63
|
+
params: params.filtered
|
42
64
|
}
|
43
65
|
end
|
44
66
|
|
@@ -23,14 +23,16 @@ module Trackets
|
|
23
23
|
"REMOTE_PORT",
|
24
24
|
"ORIGINAL_FULLPATH"
|
25
25
|
].freeze
|
26
|
+
DEFAULT_BLACKLISTED_PARAMS = ["password", "password_confirmation", "card_number", "cvv"].freeze
|
26
27
|
|
27
|
-
DEFAULT_API_URL = "https://trackets.
|
28
|
+
DEFAULT_API_URL = "https://trackets.com"
|
28
29
|
|
29
|
-
attr_accessor :api_url, :api_key, :environment_name, :project_root, :framework, :whitelisted_env
|
30
|
+
attr_accessor :api_url, :api_key, :environment_name, :project_root, :framework, :whitelisted_env, :blacklisted_params
|
30
31
|
|
31
32
|
def initialize
|
32
33
|
@api_url = DEFAULT_API_URL
|
33
34
|
@whitelisted_env = DEFAULT_WHITELISTED_ENV_KEYS
|
35
|
+
@blacklisted_params = DEFAULT_BLACKLISTED_PARAMS
|
34
36
|
end
|
35
37
|
|
36
38
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Trackets
|
2
|
+
class Params
|
3
|
+
|
4
|
+
attr_reader :rack_env
|
5
|
+
|
6
|
+
def initialize(rack_env)
|
7
|
+
@rack_env = rack_env
|
8
|
+
end
|
9
|
+
|
10
|
+
def rack_filter_keys
|
11
|
+
@rack_filter_keys ||= Array(rack_env["action_dispatch.parameter_filter"])
|
12
|
+
end
|
13
|
+
|
14
|
+
def request
|
15
|
+
@request ||= Rack::Request.new(rack_env)
|
16
|
+
end
|
17
|
+
|
18
|
+
def hash
|
19
|
+
@hash ||= request.params
|
20
|
+
end
|
21
|
+
|
22
|
+
def blacklisted_keys
|
23
|
+
@blacklisted_keys ||= (Trackets.configuration.blacklisted_params + rack_filter_keys).map(&:to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
def blacklisted?(key)
|
27
|
+
blacklisted_keys.include?(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def filtered
|
31
|
+
hash.inject({}) do |ret, (key, value)|
|
32
|
+
ret[key] = if value.kind_of?(Hash)
|
33
|
+
self.class.new(value).filtered
|
34
|
+
else
|
35
|
+
blacklisted?(key) ? "[FILTERED]" : value
|
36
|
+
end
|
37
|
+
|
38
|
+
ret
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/trackets/version.rb
CHANGED
data/trackets.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["votava@deployment.cz"]
|
11
11
|
spec.summary = %q{Trackets.com Ruby support GEM}
|
12
12
|
spec.description = %q{Helpers for Trackets.com error tracking service}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "http://www.trackets.com"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -23,5 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency "rack"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
|
+
spec.add_development_dependency "cucumber-rails", "~> 1.4.1"
|
27
|
+
spec.add_development_dependency "aruba", "~> 0.5.4"
|
28
|
+
spec.add_development_dependency "sham_rack"
|
26
29
|
spec.add_development_dependency "rake"
|
27
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Votava
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -66,6 +66,48 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cucumber-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aruba
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sham_rack
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: rake
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +134,12 @@ files:
|
|
92
134
|
- LICENSE.txt
|
93
135
|
- README.md
|
94
136
|
- Rakefile
|
137
|
+
- features/rails.feature
|
138
|
+
- features/step_definitions/rails_steps.rb
|
139
|
+
- features/support/common.rb
|
140
|
+
- features/support/env.rb
|
141
|
+
- features/support/rails.rb
|
142
|
+
- features/support/templates/trackets_interceptor.rb
|
95
143
|
- lib/generators/trackets/install_generator.rb
|
96
144
|
- lib/generators/trackets/templates/initializer.rb
|
97
145
|
- lib/trackets.rb
|
@@ -99,11 +147,12 @@ files:
|
|
99
147
|
- lib/trackets/client.rb
|
100
148
|
- lib/trackets/configuration.rb
|
101
149
|
- lib/trackets/middleware/rack_exception_handler.rb
|
150
|
+
- lib/trackets/params.rb
|
102
151
|
- lib/trackets/railtie.rb
|
103
152
|
- lib/trackets/version.rb
|
104
153
|
- lib/trackets/view_helpers.rb
|
105
154
|
- trackets.gemspec
|
106
|
-
homepage:
|
155
|
+
homepage: http://www.trackets.com
|
107
156
|
licenses:
|
108
157
|
- MIT
|
109
158
|
metadata: {}
|
@@ -127,4 +176,10 @@ rubygems_version: 2.2.2
|
|
127
176
|
signing_key:
|
128
177
|
specification_version: 4
|
129
178
|
summary: Trackets.com Ruby support GEM
|
130
|
-
test_files:
|
179
|
+
test_files:
|
180
|
+
- features/rails.feature
|
181
|
+
- features/step_definitions/rails_steps.rb
|
182
|
+
- features/support/common.rb
|
183
|
+
- features/support/env.rb
|
184
|
+
- features/support/rails.rb
|
185
|
+
- features/support/templates/trackets_interceptor.rb
|