Permalink
Browse files

changed serialization check from blacklist to whitelist #217

  • Loading branch information...
1 parent b1ece68 commit da5bc5a09f0d887e114e2d3aa86268330e05e513 Tammer Saleh committed Mar 18, 2009
Showing with 33 additions and 7 deletions.
  1. +5 −1 lib/hoptoad_notifier.rb
  2. +28 −6 test/configuration_test.rb
View
@@ -337,7 +337,11 @@ def clean_non_serializable_data(notice) #:nodoc:
end
def serializable?(value) #:nodoc:
- !(value.is_a?(Module) || value.kind_of?(IO))
+ value.is_a?(Fixnum) ||
+ value.is_a?(Array) ||
+ value.is_a?(String) ||
+ value.is_a?(Hash) ||
+ value.is_a?(Bignum)
end
def stringify_keys(hash) #:nodoc:
View
@@ -40,24 +40,46 @@ def rescue_action e
assert_equal 'secret', HoptoadNotifier.proxy_pass
assert_equal 2, HoptoadNotifier.http_open_timeout
assert_equal 5, HoptoadNotifier.http_read_timeout
- assert_equal (HoptoadNotifier::IGNORE_USER_AGENT_DEFAULT + ['UserAgentString', /UserAgentRegexp/]), HoptoadNotifier.ignore_user_agent
- assert_equal (HoptoadNotifier::IGNORE_DEFAULT + [RuntimeError]), HoptoadNotifier.ignore
+ assert_equal HoptoadNotifier::IGNORE_USER_AGENT_DEFAULT + ['UserAgentString', /UserAgentRegexp/],
+ HoptoadNotifier.ignore_user_agent
+ assert_equal HoptoadNotifier::IGNORE_DEFAULT + [RuntimeError],
+ HoptoadNotifier.ignore
end
should "set a default host" do
HoptoadNotifier.instance_variable_set("@host",nil)
assert_equal "hoptoadapp.com", HoptoadNotifier.host
end
+ [File.open(__FILE__), Proc.new { puts "boo!" }, Module.new].each do |object|
+ should "remove #{object.class} when cleaning environment" do
+ HoptoadNotifier.configure {}
+ notice = @controller.send(:normalize_notice, {})
+ notice[:environment][:strange_object] = object
+
+ assert_nil @controller.send(:clean_non_serializable_data, notice)[:environment][:strange_object]
+ end
+ end
+
+ [123, "string", 123_456_789_123_456_789, [:a, :b], {:a => 1}, HashWithIndifferentAccess.new].each do |object|
+ should "not remove #{object.class} when cleaning environment" do
+ HoptoadNotifier.configure {}
+ notice = @controller.send(:normalize_notice, {})
+ notice[:environment][:strange_object] = object
+
+ assert_equal object, @controller.send(:clean_non_serializable_data, notice)[:environment][:strange_object]
+ end
+ end
+
should "remove notifier trace when cleaning backtrace" do
HoptoadNotifier.configure {}
- options = HoptoadNotifier.default_notice_options
+ notice = @controller.send(:normalize_notice, {})
- options = @controller.send(:normalize_notice, {})
- dirty_backtrace = @controller.send(:clean_hoptoad_backtrace, options[:backtrace])
+ assert notice[:backtrace].grep(%r{lib/hoptoad_notifier.rb}).any?, notice[:backtrace].inspect
+ dirty_backtrace = @controller.send(:clean_hoptoad_backtrace, notice[:backtrace])
dirty_backtrace.each do |line|
- assert_no_match /lib\/hoptoad_notifier.rb/, line
+ assert_no_match %r{lib/hoptoad_notifier.rb}, line
end
end

0 comments on commit da5bc5a

Please sign in to comment.