jira_exception_collector 0.8.0 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -3,5 +3,4 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - jruby
6
- - ruby-head
7
6
  - ree
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # JIRA Exception Collector
2
2
 
3
+ ![Travis CI](https://secure.travis-ci.org/manalang/jira_exception_collector.png?branch=master)
4
+
3
5
  A gem that logs your exceptions as a JIRA issue. Once it's in JIRA, you can route it to
4
6
  the appropriate developer to fix the issue using JIRA's workflow engine.
5
7
 
@@ -60,7 +62,7 @@ You can also configure filters to scrub out sensitive environment variables:
60
62
  use Rack::JiraExceptionCollector do |collector|
61
63
  collector.collector_url = "[collector url]"
62
64
  collector.report_under << "your_custom_env"
63
- collector.filters << %w(SECRET_KEY SECRET_TOKEN)
65
+ collector.environment_filters << %w(SECRET_KEY SECRET_TOKEN)
64
66
  end
65
67
  ````
66
68
 
@@ -12,14 +12,18 @@ module Rack
12
12
 
13
13
  class Error < StandardError; end
14
14
 
15
- def initialize(app, collector_url = nil, rack_environment = 'RACK_ENV')
15
+ attr_accessor :collector_url, :environment_filters, :report_under, :rack_environment,
16
+ :failsafe, :error
17
+
18
+ def initialize(app, collector_url = nil)
16
19
  @app = app
17
20
  @collector_url = collector_url
18
- @report_under = report_under
19
- @rack_environment = %w(production staging)
20
- @filters = %w(AWS_ACCESS_KEY AWS_SECRET_ACCESS_KEY AWS_ACCOUNT SSH_AUTH_SOCK)
21
+ @report_under = %w(production staging)
22
+ @rack_environment = "RACK_ENV"
23
+ @environment_filters = %w(AWS_ACCESS_KEY AWS_SECRET_ACCESS_KEY AWS_ACCOUNT SSH_AUTH_SOCK)
21
24
  @failsafe = $stderr
22
25
  yield self if block_given?
26
+ raise(Error, "You need to provide a collector URL") unless @collector_url
23
27
  end
24
28
 
25
29
  def call(env)
@@ -35,7 +39,7 @@ module Rack
35
39
  end
36
40
 
37
41
  def environment_filter_keys
38
- @filters.flatten
42
+ @environment_filters.flatten
39
43
  end
40
44
 
41
45
  def environment_filter_regexps
@@ -45,13 +49,12 @@ module Rack
45
49
  end
46
50
  private
47
51
  def report?
48
- @report_under.include?(rack_env) || rack_env == "test"
52
+ @report_under.include?(rack_env)
49
53
  end
50
54
 
51
55
  def send_exception(exception, env)
52
56
  return true unless report?
53
57
  request = Rack::Request.new(env)
54
- env['rack.session'] = {:a => 1}
55
58
 
56
59
  options = {
57
60
  :url => env['REQUEST_URI'],
@@ -141,10 +144,10 @@ module Rack
141
144
  http.use_ssl = true if uri.scheme == "https"
142
145
  request = Net::HTTP::Post.new(uri.request_uri)
143
146
  request['X-JIRA-Client-Name'] = "Rack::JiraExceptionCollector"
144
- error = document_for(exception, options)
147
+ @error = document_for(exception, options)
145
148
  request.set_form_data({
146
149
  "description" => "#{exception.class.name}: #{exception.message}",
147
- "webInfo" => error
150
+ "webInfo" => @error
148
151
  })
149
152
  response = http.request(request)
150
153
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class JiraExceptionCollector
3
- VERSION = "0.8.0"
3
+ VERSION = "0.8.3"
4
4
  end
5
5
  end
@@ -7,13 +7,35 @@ class Rack::JiraExceptionCollector::TestLogException < Test::Unit::TestCase
7
7
  :body => "Thanks for providing your feedback", :status => ["200", "OK"])
8
8
 
9
9
  @app = Rack::Lobster.new
10
- @collector = Rack::JiraExceptionCollector.new @app, @collector_url
10
+ @collector = Rack::JiraExceptionCollector.new(@app, @collector_url){|c|
11
+ c.report_under << "test"
12
+ }
11
13
  @request = Rack::MockRequest.new @collector
12
14
  end
13
15
 
14
- def test_exception_was_sent
16
+ def make_it_crash
17
+ ENV['RACK_ENV'] = 'test'
18
+ env = Rack::MockRequest.env_for('/?flip=crash', :method => 'GET')
19
+ end
20
+
21
+ def test_no_collector_url_generates_exception
22
+ assert_raise(Rack::JiraExceptionCollector::Error){ Rack::JiraExceptionCollector.new(@app) }
23
+ end
24
+
25
+ def test_collector_url_can_be_configured_in_block
15
26
  ENV['RACK_ENV'] = 'test'
16
27
  env = Rack::MockRequest.env_for('/?flip=crash', :method => 'GET')
28
+ collector = Rack::JiraExceptionCollector.new(@app){|c|
29
+ c.collector_url = @collector_url
30
+ c.report_under << "test"
31
+ }
32
+ assert collector.collector_url == @collector_url
33
+ assert_raise(RuntimeError) { collector.call(env) }
34
+ assert_true env['jira.notified'], "JIRA exception created"
35
+ end
36
+
37
+ def test_exception_was_sent
38
+ env = make_it_crash
17
39
  assert_raise(RuntimeError) { @collector.call(env) }
18
40
  assert_true env['jira.notified'], "JIRA exception created"
19
41
  end
@@ -21,7 +43,42 @@ class Rack::JiraExceptionCollector::TestLogException < Test::Unit::TestCase
21
43
  def test_exception_can_be_sent_from_a_custom_env
22
44
  ENV['RACK_ENV'] = "my_custom_env"
23
45
  env = Rack::MockRequest.env_for('/?flip=crash', :method => 'GET')
24
- collector = Rack::JiraExceptionCollector.new @app, @collector_url, "my_custom_env"
46
+ collector = Rack::JiraExceptionCollector.new(@app, @collector_url){|c| c.report_under << "my_custom_env"}
47
+ assert_raise(RuntimeError) { collector.call(env) }
48
+ assert_true env['jira.notified'], "JIRA exception created"
49
+ end
50
+
51
+ def test_exception_can_be_filtered
52
+ ENV["SUPER_SECRET_CODE"] = "My super secret code"
53
+ env = make_it_crash
54
+ collector = Rack::JiraExceptionCollector.new(@app, @collector_url){|c|
55
+ c.environment_filters << "SUPER_SECRET_CODE"
56
+ c.report_under << "test"
57
+ }
58
+ assert_raise(RuntimeError) { collector.call(env) }
59
+ assert_match /ENV\["SUPER_SECRET_CODE"\]\: \[FILTERED\]/, collector.error
60
+ end
61
+
62
+ def test_exception_can_be_filtered_with_more_than_one_filter
63
+ ENV["SUPER_SECRET_CODE1"] = "My super secret code1"
64
+ ENV["SUPER_SECRET_CODE2"] = "My super secret code2"
65
+ env = make_it_crash
66
+ collector = Rack::JiraExceptionCollector.new(@app, @collector_url){|c|
67
+ c.environment_filters = %w(SUPER_SECRET_CODE1 SUPER_SECRET_CODE2)
68
+ c.report_under << "test"
69
+ }
70
+ assert_raise(RuntimeError) { collector.call(env) }
71
+ assert_match /ENV\["SUPER_SECRET_CODE1"\]\: \[FILTERED\]/, collector.error
72
+ assert_match /ENV\["SUPER_SECRET_CODE2"\]\: \[FILTERED\]/, collector.error
73
+ end
74
+
75
+ def test_rack_env_can_be_changed
76
+ ENV['CUSTOM_ENV'] = 'test'
77
+ env = Rack::MockRequest.env_for('/?flip=crash', :method => 'GET')
78
+ collector = Rack::JiraExceptionCollector.new(@app, @collector_url){|c|
79
+ c.report_under << "test"
80
+ c.rack_environment = "CUSTOM_ENV"
81
+ }
25
82
  assert_raise(RuntimeError) { collector.call(env) }
26
83
  assert_true env['jira.notified'], "JIRA exception created"
27
84
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira_exception_collector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 3
10
+ version: 0.8.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rich Manalang