-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log missing key warning after Rails initialization completes (#444)
- Loading branch information
Showing
16 changed files
with
294 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'railties', '4.2.10', require: %w(action_controller rails) | ||
gem 'bugsnag', path: '../../../..' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Bundler.require | ||
|
||
run InitializerConfigApp ||= Class.new(Rails::Application) { | ||
config.secret_key_base = routes.append { | ||
root to: proc { | ||
[200, {"Content-Type" => "text/plain"}, ["Hello!"]] | ||
} | ||
}.to_s | ||
|
||
config.cache_classes = true | ||
config.eager_load = true | ||
config.logger = Logger.new(STDOUT) | ||
config.log_level = :warn | ||
|
||
initialize! | ||
} |
3 changes: 3 additions & 0 deletions
3
spec/fixtures/apps/rails-initializer-config/config/initializers/bugsnag.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Bugsnag.configure do |config| | ||
config.api_key = 'c34a2472bd240ac0ab0f52715bbdc05d' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'railties', '4.2.10', require: %w(action_controller rails) | ||
gem 'bugsnag', path: '../../../..' |
16 changes: 16 additions & 0 deletions
16
spec/fixtures/apps/rails-invalid-initializer-config/config.ru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Bundler.require | ||
|
||
run InitializerConfigApp ||= Class.new(Rails::Application) { | ||
config.secret_key_base = routes.append { | ||
root to: proc { | ||
[200, {"Content-Type" => "text/plain"}, ["Hello!"]] | ||
} | ||
}.to_s | ||
|
||
config.cache_classes = true | ||
config.eager_load = true | ||
config.logger = Logger.new(STDOUT) | ||
config.log_level = :warn | ||
|
||
initialize! | ||
} |
3 changes: 3 additions & 0 deletions
3
spec/fixtures/apps/rails-invalid-initializer-config/config/initializers/bugsnag.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Bugsnag.configure do |config| | ||
config.api_key = '1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'railties', '4.2.10', require: %w(action_controller rails) | ||
gem 'bugsnag', path: '../../../..' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Bundler.require | ||
|
||
run NoConfigApp ||= Class.new(Rails::Application) { | ||
config.secret_key_base = routes.append { | ||
root to: proc { | ||
[200, {"Content-Type" => "text/plain"}, ["Hello!"]] | ||
} | ||
}.to_s | ||
|
||
config.cache_classes = true | ||
config.eager_load = true | ||
config.logger = Logger.new(STDOUT) | ||
config.log_level = :warn | ||
|
||
initialize! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'bugsnag', path: '../../../..' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'bugsnag' | ||
|
||
Bugsnag.configure do |config| | ||
config.api_key = 'no' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'bugsnag' | ||
|
||
Bugsnag.configure do |config| | ||
config.api_key = 'f25a2472bd230ac0ab0fa2715bbdc654' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'bugsnag' | ||
|
||
Bugsnag.configure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Configuration.logger' do | ||
|
||
before do | ||
@env = {} | ||
end | ||
|
||
context 'in a Rails app' do | ||
key_warning = '[Bugsnag]: No valid API key has been set, notifications will not be sent' | ||
is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' | ||
incompatible = (RUBY_VERSION < '2.0.0') || is_jruby | ||
|
||
before do | ||
skip "Incompatible with Ruby <2.0 and JRuby" if incompatible | ||
@env['RACK_ENV'] = 'production' | ||
end | ||
|
||
def run_app(name) | ||
out_reader, out_writer = IO.pipe | ||
Dir.chdir(File.join(File.dirname(__FILE__), "../fixtures/apps/#{name}")) do | ||
Bundler.with_clean_env do | ||
pid = Process.spawn('bundle install', | ||
out: out_writer.fileno, | ||
err: out_writer.fileno) | ||
Process.waitpid(pid, 0) | ||
pid = Process.spawn(@env, 'bundle exec rackup config.ru', | ||
out: out_writer.fileno, | ||
err: out_writer.fileno) | ||
sleep(2) | ||
Process.kill(1, pid) | ||
end | ||
end | ||
out_writer.close | ||
output = "" | ||
output << out_reader.gets until out_reader.eof? | ||
output | ||
end | ||
context 'sets an API key using the BUGSNAG_API_KEY env var' do | ||
it 'does not log a warning' do | ||
skip "Incompatible with Ruby <2.0 and JRuby" if incompatible | ||
@env['BUGSNAG_API_KEY'] = 'c34a2472bd240ac0ab0f52715bbdc05d' | ||
output = run_app('rails-no-config') | ||
expect(output).not_to include(key_warning) | ||
end | ||
end | ||
|
||
context 'sets an API key using the bugsnag initializer' do | ||
it 'does not log a warning' do | ||
skip "Incompatible with Ruby <2.0 and JRuby" if incompatible | ||
output = run_app('rails-initializer-config') | ||
expect(output).not_to include(key_warning) | ||
end | ||
end | ||
|
||
context 'skips setting an API key' do | ||
it 'logs a warning' do | ||
skip "Incompatible with Ruby <2.0 and JRuby" if incompatible | ||
output = run_app('rails-no-config') | ||
expect(output).to include(key_warning) | ||
end | ||
end | ||
|
||
context 'sets an invalid API key using the BUGSNAG_API_KEY env var' do | ||
it 'logs a warning' do | ||
skip "Incompatible with Ruby <2.0 and JRuby" if incompatible | ||
output = run_app('rails-invalid-initializer-config') | ||
expect(output).to include(key_warning) | ||
end | ||
end | ||
|
||
context 'sets an invalid API key using the BUGSNAG_API_KEY env var' do | ||
it 'logs a warning' do | ||
skip "Incompatible with Ruby <2.0 and JRuby" if incompatible | ||
@env['BUGSNAG_API_KEY'] = 'not a real key' | ||
output = run_app('rails-no-config') | ||
expect(output).to include(key_warning) | ||
end | ||
end | ||
end | ||
|
||
context 'in a script' do | ||
key_warning = /\[Bugsnag\] .* No valid API key has been set, notifications will not be sent/ | ||
|
||
def run_app(name) | ||
out_reader, out_writer = IO.pipe | ||
Dir.chdir(File.join(File.dirname(__FILE__), "../fixtures/apps/scripts")) do | ||
Bundler.with_clean_env do | ||
pid = Process.spawn(@env, "bundle exec ruby #{name}.rb", | ||
out: out_writer.fileno, | ||
err: out_writer.fileno) | ||
Process.waitpid(pid, 0) | ||
end | ||
end | ||
out_writer.close | ||
output = "" | ||
output << out_reader.gets until out_reader.eof? | ||
output | ||
end | ||
|
||
context 'sets an API key using the BUGSNAG_API_KEY env var' do | ||
it 'does not log a warning' do | ||
@env['BUGSNAG_API_KEY'] = 'c34a2472bd240ac0ab0f52715bbdc05d' | ||
output = run_app('no_config') | ||
expect(output).not_to match(key_warning) | ||
end | ||
end | ||
|
||
context 'sets an API key using Bugsnag.configure' do | ||
it 'does not log a warning' do | ||
output = run_app('configure_key') | ||
expect(output).not_to match(key_warning) | ||
end | ||
end | ||
|
||
context 'sets an invalid API key using Bugsnag.configure' do | ||
it 'logs a warning' do | ||
output = run_app('configure_invalid_key') | ||
expect(output).to match(key_warning) | ||
end | ||
end | ||
|
||
context 'sets an invalid API key using the BUGSNAG_API_KEY env var' do | ||
it 'logs a warning' do | ||
@env['BUGSNAG_API_KEY'] = 'bad key bad key whatcha gonna do' | ||
output = run_app('no_config') | ||
expect(output).to match(key_warning) | ||
end | ||
end | ||
|
||
context 'skips setting an API key' do | ||
it 'logs a warning' do | ||
output = run_app('no_config') | ||
expect(output).to match(key_warning) | ||
end | ||
end | ||
end | ||
end |