forked from rails/exception_notification
/
exception_notifier_helper_test.rb
61 lines (49 loc) · 2.19 KB
/
exception_notifier_helper_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'test_helper'
require 'exception_notifier_helper'
class ExceptionNotifierHelperTest < Test::Unit::TestCase
class ExceptionNotifierHelperIncludeTarget
include ExceptionNotifierHelper
end
def setup
@helper = ExceptionNotifierHelperIncludeTarget.new
end
# No controller
def test_should_not_exclude_raw_post_parameters_if_no_controller
assert !@helper.exclude_raw_post_parameters?
end
# Controller, no filtering
class ControllerWithoutFilterParameters; end
def test_should_not_filter_env_values_for_raw_post_data_keys_if_controller_can_not_filter_parameters
stub_controller(ControllerWithoutFilterParameters.new)
assert @helper.filter_sensitive_post_data_from_env("RAW_POST_DATA", "secret").include?("secret")
end
def test_should_not_exclude_raw_post_parameters_if_controller_can_not_filter_parameters
stub_controller(ControllerWithoutFilterParameters.new)
assert !@helper.exclude_raw_post_parameters?
end
def test_should_return_params_if_controller_can_not_filter_parameters
stub_controller(ControllerWithoutFilterParameters.new)
assert_equal :params, @helper.filter_sensitive_post_data_parameters(:params)
end
# Controller with filtering
class ControllerWithFilterParameters
def filter_parameters(params); :filtered end
end
def test_should_filter_env_values_for_raw_post_data_keys_if_controller_can_filter_parameters
stub_controller(ControllerWithFilterParameters.new)
assert !@helper.filter_sensitive_post_data_from_env("RAW_POST_DATA", "secret").include?("secret")
assert @helper.filter_sensitive_post_data_from_env("SOME_OTHER_KEY", "secret").include?("secret")
end
def test_should_exclude_raw_post_parameters_if_controller_can_filter_parameters
stub_controller(ControllerWithFilterParameters.new)
assert @helper.exclude_raw_post_parameters?
end
def test_should_delegate_param_filtering_to_controller_if_controller_can_filter_parameters
stub_controller(ControllerWithFilterParameters.new)
assert_equal :filtered, @helper.filter_sensitive_post_data_parameters(:params)
end
private
def stub_controller(controller)
@helper.instance_variable_set(:@controller, controller)
end
end