55from io import BytesIO
66from bottle import Bottle , debug as set_debug , abort , redirect , HTTPResponse
77from sentry_sdk import capture_message
8- from sentry_sdk .consts import DEFAULT_MAX_VALUE_LENGTH
98from sentry_sdk .integrations .bottle import BottleIntegration
109from sentry_sdk .serializer import MAX_DATABAG_BREADTH
1110
@@ -121,10 +120,17 @@ def index():
121120 assert event ["exception" ]["values" ][0 ]["mechanism" ]["handled" ] is False
122121
123122
124- def test_large_json_request (sentry_init , capture_events , app , get_client ):
125- sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
123+ @pytest .mark .parametrize ("max_value_length" , [1024 , None ])
124+ def test_large_json_request (
125+ sentry_init , capture_events , app , get_client , max_value_length
126+ ):
127+ sentry_init (
128+ integrations = [BottleIntegration ()],
129+ max_request_body_size = "always" ,
130+ max_value_length = max_value_length ,
131+ )
126132
127- data = {"foo" : {"bar" : "a" * (DEFAULT_MAX_VALUE_LENGTH + 10 )}}
133+ data = {"foo" : {"bar" : "a" * (1034 )}}
128134
129135 @app .route ("/" , method = "POST" )
130136 def index ():
@@ -144,15 +150,17 @@ def index():
144150 assert response [1 ] == "200 OK"
145151
146152 (event ,) = events
147- assert event ["_meta" ]["request" ]["data" ]["foo" ]["bar" ] == {
148- "" : {
149- "len" : DEFAULT_MAX_VALUE_LENGTH + 10 ,
150- "rem" : [
151- ["!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
152- ],
153+
154+ if max_value_length :
155+ assert event ["_meta" ]["request" ]["data" ]["foo" ]["bar" ] == {
156+ "" : {
157+ "len" : 1034 ,
158+ "rem" : [["!limit" , "x" , 1021 , 1024 ]],
159+ }
153160 }
154- }
155- assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == DEFAULT_MAX_VALUE_LENGTH
161+ assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == 1024
162+ else :
163+ assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == 1034
156164
157165
158166@pytest .mark .parametrize ("data" , [{}, []], ids = ["empty-dict" , "empty-list" ])
@@ -179,10 +187,17 @@ def index():
179187 assert event ["request" ]["data" ] == data
180188
181189
182- def test_medium_formdata_request (sentry_init , capture_events , app , get_client ):
183- sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
190+ @pytest .mark .parametrize ("max_value_length" , [1024 , None ])
191+ def test_medium_formdata_request (
192+ sentry_init , capture_events , app , get_client , max_value_length
193+ ):
194+ sentry_init (
195+ integrations = [BottleIntegration ()],
196+ max_request_body_size = "always" ,
197+ max_value_length = max_value_length ,
198+ )
184199
185- data = {"foo" : "a" * (DEFAULT_MAX_VALUE_LENGTH + 10 )}
200+ data = {"foo" : "a" * (1034 )}
186201
187202 @app .route ("/" , method = "POST" )
188203 def index ():
@@ -199,15 +214,17 @@ def index():
199214 assert response [1 ] == "200 OK"
200215
201216 (event ,) = events
202- assert event ["_meta" ]["request" ]["data" ]["foo" ] == {
203- "" : {
204- "len" : DEFAULT_MAX_VALUE_LENGTH + 10 ,
205- "rem" : [
206- ["!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
207- ],
217+
218+ if max_value_length :
219+ assert event ["_meta" ]["request" ]["data" ]["foo" ] == {
220+ "" : {
221+ "len" : 1034 ,
222+ "rem" : [["!limit" , "x" , 1021 , 1024 ]],
223+ }
208224 }
209- }
210- assert len (event ["request" ]["data" ]["foo" ]) == DEFAULT_MAX_VALUE_LENGTH
225+ assert len (event ["request" ]["data" ]["foo" ]) == 1024
226+ else :
227+ assert len (event ["request" ]["data" ]["foo" ]) == 1034
211228
212229
213230@pytest .mark .parametrize ("input_char" , ["a" , b"a" ])
@@ -241,11 +258,16 @@ def index():
241258 assert not event ["request" ]["data" ]
242259
243260
244- def test_files_and_form (sentry_init , capture_events , app , get_client ):
245- sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
261+ @pytest .mark .parametrize ("max_value_length" , [1024 , None ])
262+ def test_files_and_form (sentry_init , capture_events , app , get_client , max_value_length ):
263+ sentry_init (
264+ integrations = [BottleIntegration ()],
265+ max_request_body_size = "always" ,
266+ max_value_length = max_value_length ,
267+ )
246268
247269 data = {
248- "foo" : "a" * (DEFAULT_MAX_VALUE_LENGTH + 10 ),
270+ "foo" : "a" * (1034 ),
249271 "file" : (BytesIO (b"hello" ), "hello.txt" ),
250272 }
251273
@@ -266,15 +288,16 @@ def index():
266288 assert response [1 ] == "200 OK"
267289
268290 (event ,) = events
269- assert event [ "_meta" ][ "request" ][ "data" ][ "foo" ] == {
270- "" : {
271- "len " : DEFAULT_MAX_VALUE_LENGTH + 10 ,
272- "rem " : [
273- [ "!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
274- ],
291+ if max_value_length :
292+ assert event [ "_meta" ][ "request" ][ "data" ][ "foo" ] == {
293+ "" : {
294+ "len " : 1034 ,
295+ "rem" : [[ "!limit" , "x" , 1021 , 1024 ]],
296+ }
275297 }
276- }
277- assert len (event ["request" ]["data" ]["foo" ]) == DEFAULT_MAX_VALUE_LENGTH
298+ assert len (event ["request" ]["data" ]["foo" ]) == 1024
299+ else :
300+ assert len (event ["request" ]["data" ]["foo" ]) == 1034
278301
279302 assert event ["_meta" ]["request" ]["data" ]["file" ] == {
280303 "" : {
0 commit comments