@@ -81,26 +81,40 @@ def test_accept_header_not_jsonapi
8181 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' ]
8282 end
8383
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
8686 $PostProcessorRaisesErrors = true
8787 # 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
8989 assert_cacheable_get :index
9090 assert_response 500
9191
9292 # 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
9595 assert_cacheable_get :index
9696 assert_response 403
9797 ensure
9898 $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
100114 end
101115
102116 def test_whitelist_all_exceptions
103- original_config = JSONAPI . configuration . whitelist_all_exceptions
117+ original_config = JSONAPI . configuration . allow_all_exceptions
104118 $PostProcessorRaisesErrors = true
105119 assert_cacheable_get :index
106120 assert_response 500
@@ -114,18 +128,18 @@ def test_whitelist_all_exceptions
114128 end
115129
116130 def test_exception_added_to_request_env
117- original_config = JSONAPI . configuration . whitelist_all_exceptions
131+ original_config = JSONAPI . configuration . allow_all_exceptions
118132 $PostProcessorRaisesErrors = true
119133 refute @request . env [ 'action_dispatch.exception' ]
120134 assert_cacheable_get :index
121135 assert @request . env [ 'action_dispatch.exception' ]
122136
123- JSONAPI . configuration . whitelist_all_exceptions = true
137+ JSONAPI . configuration . allow_all_exceptions = true
124138 assert_cacheable_get :index
125139 assert @request . env [ 'action_dispatch.exception' ]
126140 ensure
127141 $PostProcessorRaisesErrors = false
128- JSONAPI . configuration . whitelist_all_exceptions = original_config
142+ JSONAPI . configuration . allow_all_exceptions = original_config
129143 end
130144
131145 def test_exception_includes_backtrace_when_enabled
@@ -168,7 +182,7 @@ def test_exception_includes_application_backtrace_when_enabled
168182
169183 def test_on_server_error_block_callback_with_exception
170184 original_config = JSONAPI . configuration . dup
171- JSONAPI . configuration . exception_class_whitelist = [ ]
185+ JSONAPI . configuration . exception_class_allowlist = [ ]
172186 $PostProcessorRaisesErrors = true
173187
174188 @controller . class . instance_variable_set ( :@callback_message , "none" )
@@ -189,7 +203,7 @@ def test_on_server_error_block_callback_with_exception
189203
190204 def test_on_server_error_method_callback_with_exception
191205 original_config = JSONAPI . configuration . dup
192- JSONAPI . configuration . exception_class_whitelist = [ ]
206+ JSONAPI . configuration . exception_class_allowlist = [ ]
193207 $PostProcessorRaisesErrors = true
194208
195209 #ignores methods that don't exist
@@ -208,7 +222,7 @@ def test_on_server_error_method_callback_with_exception
208222
209223 def test_on_server_error_method_callback_with_exception_on_serialize
210224 original_config = JSONAPI . configuration . dup
211- JSONAPI . configuration . exception_class_whitelist = [ ]
225+ JSONAPI . configuration . exception_class_allowlist = [ ]
212226 $PostSerializerRaisesErrors = true
213227
214228 #ignores methods that don't exist
@@ -4000,6 +4014,16 @@ def test_uncaught_error_in_controller_translated_to_internal_server_error
40004014 assert_match /Internal Server Error/ , json_response [ 'errors' ] [ 0 ] [ 'detail' ]
40014015 end
40024016
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+
40034027 def test_not_whitelisted_error_in_controller
40044028 original_config = JSONAPI . configuration . dup
40054029 JSONAPI . configuration . exception_class_whitelist = [ ]
@@ -4010,6 +4034,18 @@ def test_not_whitelisted_error_in_controller
40104034 JSONAPI . configuration = original_config
40114035 end
40124036
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+
40134049 def test_whitelisted_error_in_controller
40144050 original_config = JSONAPI . configuration . dup
40154051 $PostProcessorRaisesErrors = true
0 commit comments