bugsnag 6.7.0 → 6.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60129feaa76e872e91284f6c222eeeaa6728fb23
4
- data.tar.gz: ab2269d57bd7c131967acf0a37b7508fd1095d7a
3
+ metadata.gz: 313641e103c52e05c89cc8d3277a0a7285504523
4
+ data.tar.gz: 3bbe2d377ff467cec0a868510c507f467385d069
5
5
  SHA512:
6
- metadata.gz: 123b069a26b2e6d3b611eb65a43b36c79878ad49075e63e7b0d600fcdcaecd9396bf7c9a42e66cbeb236d4d06a44290bdc7125b8eff0dab54ae4531209882b07
7
- data.tar.gz: 2afa07a981784dff59491cb8a156f977905f06e462dcaacb352b3f09241d6ae90afadf6b3bd0bbecd4ce1a321e88bda4af35a8e03f9a2dbfce3009ac886bc976
6
+ metadata.gz: ca1371c07f154c2c3d2241e868b9bb49fefc86cc682f4744d819552dd75d517bdeb04dbb3fb5b11f007efa9fd08458e2d6cd198da810e089381965744206a8d6
7
+ data.tar.gz: 39beb55e75be93fba3921dec840ed1d118de8b9818df62bd3b4a3a3a6d1bce190b087acb7aa36493986264cd7135020e5e38980fe535e225c9b89df679def20a
data/.travis.yml CHANGED
@@ -63,11 +63,10 @@ jobs:
63
63
  rvm: 2.4.1
64
64
  script: bundle exec rake rdoc
65
65
  if: tag =~ ^v[1-9]
66
-
67
- deploy:
68
- provider: pages
69
- local_dir: rdoc # only include the contents of the generated docs dir
70
- skip_cleanup: true
71
- github_token: $GITHUB_TOKEN # set in travis-ci dashboard
72
- on:
73
- tags: true # only deploy when tag is applied to commit
66
+ deploy:
67
+ provider: pages
68
+ local_dir: rdoc # only include the contents of the generated docs dir
69
+ skip_cleanup: true
70
+ github_token: $GITHUB_TOKEN # set in travis-ci dashboard
71
+ on:
72
+ tags: true # only deploy when tag is applied to commit
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## 6.7.1 (11 Apr 2018)
5
+
6
+ ### Fixes
7
+
8
+ * (Rails) Log missing key warning after initialization completes, avoiding
9
+ incorrectly logging a warning that the API key is missing
10
+ | [#444](https://github.com/bugsnag/bugsnag-ruby/pull/444)
11
+
4
12
  ## 6.7.0 (05 Apr 2018)
5
13
 
6
14
  ### Enhancements
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.7.0
1
+ 6.7.1
data/lib/bugsnag.rb CHANGED
@@ -37,14 +37,10 @@ module Bugsnag
37
37
  # Configure the Bugsnag notifier application-wide settings.
38
38
  #
39
39
  # Yields a configuration object to use to set application settings.
40
- def configure
40
+ def configure(validate_api_key=true)
41
41
  yield(configuration) if block_given?
42
42
 
43
- @key_warning = false unless defined?(@key_warning)
44
- if !configuration.valid_api_key? && !@key_warning
45
- configuration.warn("No valid API key has been set, notifications will not be sent")
46
- @key_warning = true
47
- end
43
+ check_key_valid if validate_api_key
48
44
  end
49
45
 
50
46
  ##
@@ -179,6 +175,15 @@ module Bugsnag
179
175
  configuration.debug("Integration #{integration} is not currently supported")
180
176
  end
181
177
  end
178
+
179
+ # Check if the API key is valid and warn (once) if it is not
180
+ def check_key_valid
181
+ @key_warning = false unless defined?(@key_warning)
182
+ if !configuration.valid_api_key? && !@key_warning
183
+ configuration.warn("No valid API key has been set, notifications will not be sent")
184
+ @key_warning = true
185
+ end
186
+ end
182
187
  end
183
188
  end
184
189
 
@@ -36,7 +36,9 @@ module Bugsnag
36
36
 
37
37
  config.before_initialize do
38
38
  # Configure bugsnag rails defaults
39
- Bugsnag.configure do |config|
39
+ # Skipping API key validation as the key may be set later in an
40
+ # initializer. If not, the key will be validated in after_initialize.
41
+ Bugsnag.configure(false) do |config|
40
42
  config.logger = ::Rails.logger
41
43
  config.release_stage = ENV["BUGSNAG_RELEASE_STAGE"] || ::Rails.env.to_s
42
44
  config.project_root = ::Rails.root.to_s
@@ -115,6 +115,66 @@ describe Bugsnag::Configuration do
115
115
  end
116
116
  end
117
117
 
118
+ context "using configure" do
119
+ before do
120
+ Bugsnag.configuration.api_key = nil
121
+ Bugsnag.instance_variable_set("@key_warning", nil)
122
+ ENV['BUGSNAG_API_KEY'] = nil
123
+ expect(@logger.logs.size).to eq(0)
124
+ end
125
+
126
+ context "API key is not specified" do
127
+ it "skips logging a warning if validate_api_key is false" do
128
+ Bugsnag.configure(false)
129
+ expect(@logger.logs.size).to eq(0)
130
+ end
131
+
132
+ it "logs a warning by default" do
133
+ Bugsnag.configure
134
+ expect(@logger.logs.size).to eq(1)
135
+ log = @logger.logs.first
136
+ expect(log).to eq({
137
+ :level => "warning",
138
+ :name => "[Bugsnag]",
139
+ :message => "No valid API key has been set, notifications will not be sent"
140
+ })
141
+ end
142
+
143
+ it "logs a warning if validate_api_key is true" do
144
+ Bugsnag.configure(true)
145
+ expect(@logger.logs.size).to eq(1)
146
+ log = @logger.logs.first
147
+ expect(log).to eq({
148
+ :level => "warning",
149
+ :name => "[Bugsnag]",
150
+ :message => "No valid API key has been set, notifications will not be sent"
151
+ })
152
+ end
153
+ end
154
+
155
+ context "API key is set" do
156
+ it "skips logging a warning when configuring with an API key" do
157
+ Bugsnag.configure do |config|
158
+ config.api_key = 'd57a2472bd130ac0ab0f52715bbdc600'
159
+ end
160
+ expect(@logger.logs.size).to eq(0)
161
+ end
162
+
163
+ it "logs a warning if the configured API key is invalid" do
164
+ Bugsnag.configure do |config|
165
+ config.api_key = 'WARNING: not a real key'
166
+ end
167
+ expect(@logger.logs.size).to eq(1)
168
+ log = @logger.logs.first
169
+ expect(log).to eq({
170
+ :level => "warning",
171
+ :name => "[Bugsnag]",
172
+ :message => "No valid API key has been set, notifications will not be sent"
173
+ })
174
+ end
175
+ end
176
+ end
177
+
118
178
  it "should log info messages to the set logger" do
119
179
  expect(@logger.logs.size).to eq(0)
120
180
  Bugsnag.configuration.info("Info message")
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '4.2.10', require: %w(action_controller rails)
4
+ gem 'bugsnag', path: '../../../..'
@@ -0,0 +1,16 @@
1
+ Bundler.require
2
+
3
+ run InitializerConfigApp ||= Class.new(Rails::Application) {
4
+ config.secret_key_base = routes.append {
5
+ root to: proc {
6
+ [200, {"Content-Type" => "text/plain"}, ["Hello!"]]
7
+ }
8
+ }.to_s
9
+
10
+ config.cache_classes = true
11
+ config.eager_load = true
12
+ config.logger = Logger.new(STDOUT)
13
+ config.log_level = :warn
14
+
15
+ initialize!
16
+ }
@@ -0,0 +1,3 @@
1
+ Bugsnag.configure do |config|
2
+ config.api_key = 'c34a2472bd240ac0ab0f52715bbdc05d'
3
+ end
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '4.2.10', require: %w(action_controller rails)
4
+ gem 'bugsnag', path: '../../../..'
@@ -0,0 +1,16 @@
1
+ Bundler.require
2
+
3
+ run InitializerConfigApp ||= Class.new(Rails::Application) {
4
+ config.secret_key_base = routes.append {
5
+ root to: proc {
6
+ [200, {"Content-Type" => "text/plain"}, ["Hello!"]]
7
+ }
8
+ }.to_s
9
+
10
+ config.cache_classes = true
11
+ config.eager_load = true
12
+ config.logger = Logger.new(STDOUT)
13
+ config.log_level = :warn
14
+
15
+ initialize!
16
+ }
@@ -0,0 +1,3 @@
1
+ Bugsnag.configure do |config|
2
+ config.api_key = '1'
3
+ end
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'railties', '4.2.10', require: %w(action_controller rails)
4
+ gem 'bugsnag', path: '../../../..'
@@ -0,0 +1,16 @@
1
+ Bundler.require
2
+
3
+ run NoConfigApp ||= Class.new(Rails::Application) {
4
+ config.secret_key_base = routes.append {
5
+ root to: proc {
6
+ [200, {"Content-Type" => "text/plain"}, ["Hello!"]]
7
+ }
8
+ }.to_s
9
+
10
+ config.cache_classes = true
11
+ config.eager_load = true
12
+ config.logger = Logger.new(STDOUT)
13
+ config.log_level = :warn
14
+
15
+ initialize!
16
+ }
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bugsnag', path: '../../../..'
@@ -0,0 +1,5 @@
1
+ require 'bugsnag'
2
+
3
+ Bugsnag.configure do |config|
4
+ config.api_key = 'no'
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'bugsnag'
2
+
3
+ Bugsnag.configure do |config|
4
+ config.api_key = 'f25a2472bd230ac0ab0fa2715bbdc654'
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'bugsnag'
2
+
3
+ Bugsnag.configure
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Configuration.logger' do
4
+
5
+ before do
6
+ @env = {}
7
+ end
8
+
9
+ context 'in a Rails app' do
10
+ key_warning = '[Bugsnag]: No valid API key has been set, notifications will not be sent'
11
+ is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
12
+ incompatible = (RUBY_VERSION < '2.0.0') || is_jruby
13
+
14
+ before do
15
+ skip "Incompatible with Ruby <2.0 and JRuby" if incompatible
16
+ @env['RACK_ENV'] = 'production'
17
+ end
18
+
19
+ def run_app(name)
20
+ out_reader, out_writer = IO.pipe
21
+ Dir.chdir(File.join(File.dirname(__FILE__), "../fixtures/apps/#{name}")) do
22
+ Bundler.with_clean_env do
23
+ pid = Process.spawn('bundle install',
24
+ out: out_writer.fileno,
25
+ err: out_writer.fileno)
26
+ Process.waitpid(pid, 0)
27
+ pid = Process.spawn(@env, 'bundle exec rackup config.ru',
28
+ out: out_writer.fileno,
29
+ err: out_writer.fileno)
30
+ sleep(2)
31
+ Process.kill(1, pid)
32
+ end
33
+ end
34
+ out_writer.close
35
+ output = ""
36
+ output << out_reader.gets until out_reader.eof?
37
+ output
38
+ end
39
+ context 'sets an API key using the BUGSNAG_API_KEY env var' do
40
+ it 'does not log a warning' do
41
+ skip "Incompatible with Ruby <2.0 and JRuby" if incompatible
42
+ @env['BUGSNAG_API_KEY'] = 'c34a2472bd240ac0ab0f52715bbdc05d'
43
+ output = run_app('rails-no-config')
44
+ expect(output).not_to include(key_warning)
45
+ end
46
+ end
47
+
48
+ context 'sets an API key using the bugsnag initializer' do
49
+ it 'does not log a warning' do
50
+ skip "Incompatible with Ruby <2.0 and JRuby" if incompatible
51
+ output = run_app('rails-initializer-config')
52
+ expect(output).not_to include(key_warning)
53
+ end
54
+ end
55
+
56
+ context 'skips setting an API key' do
57
+ it 'logs a warning' do
58
+ skip "Incompatible with Ruby <2.0 and JRuby" if incompatible
59
+ output = run_app('rails-no-config')
60
+ expect(output).to include(key_warning)
61
+ end
62
+ end
63
+
64
+ context 'sets an invalid API key using the BUGSNAG_API_KEY env var' do
65
+ it 'logs a warning' do
66
+ skip "Incompatible with Ruby <2.0 and JRuby" if incompatible
67
+ output = run_app('rails-invalid-initializer-config')
68
+ expect(output).to include(key_warning)
69
+ end
70
+ end
71
+
72
+ context 'sets an invalid API key using the BUGSNAG_API_KEY env var' do
73
+ it 'logs a warning' do
74
+ skip "Incompatible with Ruby <2.0 and JRuby" if incompatible
75
+ @env['BUGSNAG_API_KEY'] = 'not a real key'
76
+ output = run_app('rails-no-config')
77
+ expect(output).to include(key_warning)
78
+ end
79
+ end
80
+ end
81
+
82
+ context 'in a script' do
83
+ key_warning = /\[Bugsnag\] .* No valid API key has been set, notifications will not be sent/
84
+
85
+ def run_app(name)
86
+ out_reader, out_writer = IO.pipe
87
+ Dir.chdir(File.join(File.dirname(__FILE__), "../fixtures/apps/scripts")) do
88
+ Bundler.with_clean_env do
89
+ pid = Process.spawn(@env, "bundle exec ruby #{name}.rb",
90
+ out: out_writer.fileno,
91
+ err: out_writer.fileno)
92
+ Process.waitpid(pid, 0)
93
+ end
94
+ end
95
+ out_writer.close
96
+ output = ""
97
+ output << out_reader.gets until out_reader.eof?
98
+ output
99
+ end
100
+
101
+ context 'sets an API key using the BUGSNAG_API_KEY env var' do
102
+ it 'does not log a warning' do
103
+ @env['BUGSNAG_API_KEY'] = 'c34a2472bd240ac0ab0f52715bbdc05d'
104
+ output = run_app('no_config')
105
+ expect(output).not_to match(key_warning)
106
+ end
107
+ end
108
+
109
+ context 'sets an API key using Bugsnag.configure' do
110
+ it 'does not log a warning' do
111
+ output = run_app('configure_key')
112
+ expect(output).not_to match(key_warning)
113
+ end
114
+ end
115
+
116
+ context 'sets an invalid API key using Bugsnag.configure' do
117
+ it 'logs a warning' do
118
+ output = run_app('configure_invalid_key')
119
+ expect(output).to match(key_warning)
120
+ end
121
+ end
122
+
123
+ context 'sets an invalid API key using the BUGSNAG_API_KEY env var' do
124
+ it 'logs a warning' do
125
+ @env['BUGSNAG_API_KEY'] = 'bad key bad key whatcha gonna do'
126
+ output = run_app('no_config')
127
+ expect(output).to match(key_warning)
128
+ end
129
+ end
130
+
131
+ context 'skips setting an API key' do
132
+ it 'logs a warning' do
133
+ output = run_app('no_config')
134
+ expect(output).to match(key_warning)
135
+ end
136
+ end
137
+ end
138
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bugsnag
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.7.0
4
+ version: 6.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-05 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -92,6 +92,18 @@ files:
92
92
  - spec/bugsnag_spec.rb
93
93
  - spec/cleaner_spec.rb
94
94
  - spec/configuration_spec.rb
95
+ - spec/fixtures/apps/rails-initializer-config/Gemfile
96
+ - spec/fixtures/apps/rails-initializer-config/config.ru
97
+ - spec/fixtures/apps/rails-initializer-config/config/initializers/bugsnag.rb
98
+ - spec/fixtures/apps/rails-invalid-initializer-config/Gemfile
99
+ - spec/fixtures/apps/rails-invalid-initializer-config/config.ru
100
+ - spec/fixtures/apps/rails-invalid-initializer-config/config/initializers/bugsnag.rb
101
+ - spec/fixtures/apps/rails-no-config/Gemfile
102
+ - spec/fixtures/apps/rails-no-config/config.ru
103
+ - spec/fixtures/apps/scripts/Gemfile
104
+ - spec/fixtures/apps/scripts/configure_invalid_key.rb
105
+ - spec/fixtures/apps/scripts/configure_key.rb
106
+ - spec/fixtures/apps/scripts/no_config.rb
95
107
  - spec/fixtures/crashes/end_of_file.rb
96
108
  - spec/fixtures/crashes/short_file.rb
97
109
  - spec/fixtures/crashes/start_of_file.rb
@@ -102,6 +114,7 @@ files:
102
114
  - spec/integration_spec.rb
103
115
  - spec/integrations/clearance_user_spec.rb
104
116
  - spec/integrations/delayed_job_spec.rb
117
+ - spec/integrations/logger_spec.rb
105
118
  - spec/integrations/mailman_spec.rb
106
119
  - spec/integrations/que_spec.rb
107
120
  - spec/integrations/rack_spec.rb
@@ -138,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
151
  version: '0'
139
152
  requirements: []
140
153
  rubyforge_project:
141
- rubygems_version: 2.6.11
154
+ rubygems_version: 2.6.14
142
155
  signing_key:
143
156
  specification_version: 4
144
157
  summary: Ruby notifier for bugsnag.com