@@ -81,26 +81,40 @@ def test_accept_header_not_jsonapi
81
81
assert_equal "All requests must use the '#{ JSONAPI ::MEDIA_TYPE } ' Accept without media type parameters. This request specified '#{ @request . headers [ 'Accept' ] } '." , json_response [ 'errors' ] [ 0 ] [ 'detail' ]
82
82
end
83
83
84
- def test_exception_class_whitelist
85
- original_whitelist = JSONAPI . configuration . exception_class_whitelist . dup
84
+ def test_exception_class_allowlist
85
+ original_allowlist = JSONAPI . configuration . exception_class_allowlist . dup
86
86
$PostProcessorRaisesErrors = true
87
87
# test that the operations dispatcher rescues the error when it
88
- # has not been added to the exception_class_whitelist
88
+ # has not been added to the exception_class_allowlist
89
89
assert_cacheable_get :index
90
90
assert_response 500
91
91
92
92
# test that the operations dispatcher does not rescue the error when it
93
- # has been added to the exception_class_whitelist
94
- JSONAPI . configuration . exception_class_whitelist << PostsController ::SpecialError
93
+ # has been added to the exception_class_allowlist
94
+ JSONAPI . configuration . exception_class_allowlist << PostsController ::SpecialError
95
95
assert_cacheable_get :index
96
96
assert_response 403
97
97
ensure
98
98
$PostProcessorRaisesErrors = false
99
- JSONAPI . configuration . exception_class_whitelist = original_whitelist
99
+ JSONAPI . configuration . exception_class_allowlist = original_allowlist
100
+ end
101
+
102
+ def test_allow_all_exceptions
103
+ original_config = JSONAPI . configuration . allow_all_exceptions
104
+ $PostProcessorRaisesErrors = true
105
+ assert_cacheable_get :index
106
+ assert_response 500
107
+
108
+ JSONAPI . configuration . allow_all_exceptions = true
109
+ assert_cacheable_get :index
110
+ assert_response 403
111
+ ensure
112
+ $PostProcessorRaisesErrors = false
113
+ JSONAPI . configuration . allow_all_exceptions = original_config
100
114
end
101
115
102
116
def test_whitelist_all_exceptions
103
- original_config = JSONAPI . configuration . whitelist_all_exceptions
117
+ original_config = JSONAPI . configuration . allow_all_exceptions
104
118
$PostProcessorRaisesErrors = true
105
119
assert_cacheable_get :index
106
120
assert_response 500
@@ -114,18 +128,18 @@ def test_whitelist_all_exceptions
114
128
end
115
129
116
130
def test_exception_added_to_request_env
117
- original_config = JSONAPI . configuration . whitelist_all_exceptions
131
+ original_config = JSONAPI . configuration . allow_all_exceptions
118
132
$PostProcessorRaisesErrors = true
119
133
refute @request . env [ 'action_dispatch.exception' ]
120
134
assert_cacheable_get :index
121
135
assert @request . env [ 'action_dispatch.exception' ]
122
136
123
- JSONAPI . configuration . whitelist_all_exceptions = true
137
+ JSONAPI . configuration . allow_all_exceptions = true
124
138
assert_cacheable_get :index
125
139
assert @request . env [ 'action_dispatch.exception' ]
126
140
ensure
127
141
$PostProcessorRaisesErrors = false
128
- JSONAPI . configuration . whitelist_all_exceptions = original_config
142
+ JSONAPI . configuration . allow_all_exceptions = original_config
129
143
end
130
144
131
145
def test_exception_includes_backtrace_when_enabled
@@ -168,7 +182,7 @@ def test_exception_includes_application_backtrace_when_enabled
168
182
169
183
def test_on_server_error_block_callback_with_exception
170
184
original_config = JSONAPI . configuration . dup
171
- JSONAPI . configuration . exception_class_whitelist = [ ]
185
+ JSONAPI . configuration . exception_class_allowlist = [ ]
172
186
$PostProcessorRaisesErrors = true
173
187
174
188
@controller . class . instance_variable_set ( :@callback_message , "none" )
@@ -189,7 +203,7 @@ def test_on_server_error_block_callback_with_exception
189
203
190
204
def test_on_server_error_method_callback_with_exception
191
205
original_config = JSONAPI . configuration . dup
192
- JSONAPI . configuration . exception_class_whitelist = [ ]
206
+ JSONAPI . configuration . exception_class_allowlist = [ ]
193
207
$PostProcessorRaisesErrors = true
194
208
195
209
#ignores methods that don't exist
@@ -208,7 +222,7 @@ def test_on_server_error_method_callback_with_exception
208
222
209
223
def test_on_server_error_method_callback_with_exception_on_serialize
210
224
original_config = JSONAPI . configuration . dup
211
- JSONAPI . configuration . exception_class_whitelist = [ ]
225
+ JSONAPI . configuration . exception_class_allowlist = [ ]
212
226
$PostSerializerRaisesErrors = true
213
227
214
228
#ignores methods that don't exist
@@ -4000,6 +4014,16 @@ def test_uncaught_error_in_controller_translated_to_internal_server_error
4000
4014
assert_match /Internal Server Error/ , json_response [ 'errors' ] [ 0 ] [ 'detail' ]
4001
4015
end
4002
4016
4017
+ def test_not_allowed_error_in_controller
4018
+ original_config = JSONAPI . configuration . dup
4019
+ JSONAPI . configuration . exception_class_allowlist = [ ]
4020
+ get :show , params : { id : '1' }
4021
+ assert_response 500
4022
+ assert_match /Internal Server Error/ , json_response [ 'errors' ] [ 0 ] [ 'detail' ]
4023
+ ensure
4024
+ JSONAPI . configuration = original_config
4025
+ end
4026
+
4003
4027
def test_not_whitelisted_error_in_controller
4004
4028
original_config = JSONAPI . configuration . dup
4005
4029
JSONAPI . configuration . exception_class_whitelist = [ ]
@@ -4010,6 +4034,18 @@ def test_not_whitelisted_error_in_controller
4010
4034
JSONAPI . configuration = original_config
4011
4035
end
4012
4036
4037
+ def test_allowed_error_in_controller
4038
+ original_config = JSONAPI . configuration . dup
4039
+ $PostProcessorRaisesErrors = true
4040
+ JSONAPI . configuration . exception_class_allowlist = [ PostsController ::SubSpecialError ]
4041
+ assert_raises PostsController ::SubSpecialError do
4042
+ assert_cacheable_get :show , params : { id : '1' }
4043
+ end
4044
+ ensure
4045
+ JSONAPI . configuration = original_config
4046
+ $PostProcessorRaisesErrors = false
4047
+ end
4048
+
4013
4049
def test_whitelisted_error_in_controller
4014
4050
original_config = JSONAPI . configuration . dup
4015
4051
$PostProcessorRaisesErrors = true
0 commit comments