99from werkzeug .wrappers import Response
1010
1111from sentry_sdk import capture_message
12- from sentry_sdk .consts import DEFAULT_MAX_VALUE_LENGTH
1312from sentry_sdk .integrations .bottle import BottleIntegration
1413from sentry_sdk .integrations .logging import LoggingIntegration
1514from sentry_sdk .serializer import MAX_DATABAG_BREADTH
@@ -122,10 +121,17 @@ def index():
122121 assert event ["exception" ]["values" ][0 ]["mechanism" ]["handled" ] is False
123122
124123
125- def test_large_json_request (sentry_init , capture_events , app , get_client ):
126- sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
124+ @pytest .mark .parametrize ("max_value_length" , [1024 , None ])
125+ def test_large_json_request (
126+ sentry_init , capture_events , app , get_client , max_value_length
127+ ):
128+ sentry_init (
129+ integrations = [BottleIntegration ()],
130+ max_request_body_size = "always" ,
131+ max_value_length = max_value_length ,
132+ )
127133
128- data = {"foo" : {"bar" : "a" * (DEFAULT_MAX_VALUE_LENGTH + 10 )}}
134+ data = {"foo" : {"bar" : "a" * (1034 )}}
129135
130136 @app .route ("/" , method = "POST" )
131137 def index ():
@@ -145,15 +151,17 @@ def index():
145151 assert response [1 ] == "200 OK"
146152
147153 (event ,) = events
148- assert event ["_meta" ]["request" ]["data" ]["foo" ]["bar" ] == {
149- "" : {
150- "len" : DEFAULT_MAX_VALUE_LENGTH + 10 ,
151- "rem" : [
152- ["!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
153- ],
154+
155+ if max_value_length :
156+ assert event ["_meta" ]["request" ]["data" ]["foo" ]["bar" ] == {
157+ "" : {
158+ "len" : 1034 ,
159+ "rem" : [["!limit" , "x" , 1021 , 1024 ]],
160+ }
154161 }
155- }
156- assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == DEFAULT_MAX_VALUE_LENGTH
162+ assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == 1024
163+ else :
164+ assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == 1034
157165
158166
159167@pytest .mark .parametrize ("data" , [{}, []], ids = ["empty-dict" , "empty-list" ])
@@ -180,10 +188,17 @@ def index():
180188 assert event ["request" ]["data" ] == data
181189
182190
183- def test_medium_formdata_request (sentry_init , capture_events , app , get_client ):
184- sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
191+ @pytest .mark .parametrize ("max_value_length" , [1024 , None ])
192+ def test_medium_formdata_request (
193+ sentry_init , capture_events , app , get_client , max_value_length
194+ ):
195+ sentry_init (
196+ integrations = [BottleIntegration ()],
197+ max_request_body_size = "always" ,
198+ max_value_length = max_value_length ,
199+ )
185200
186- data = {"foo" : "a" * (DEFAULT_MAX_VALUE_LENGTH + 10 )}
201+ data = {"foo" : "a" * (1034 )}
187202
188203 @app .route ("/" , method = "POST" )
189204 def index ():
@@ -200,15 +215,17 @@ def index():
200215 assert response [1 ] == "200 OK"
201216
202217 (event ,) = events
203- assert event ["_meta" ]["request" ]["data" ]["foo" ] == {
204- "" : {
205- "len" : DEFAULT_MAX_VALUE_LENGTH + 10 ,
206- "rem" : [
207- ["!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
208- ],
218+
219+ if max_value_length :
220+ assert event ["_meta" ]["request" ]["data" ]["foo" ] == {
221+ "" : {
222+ "len" : 1034 ,
223+ "rem" : [["!limit" , "x" , 1021 , 1024 ]],
224+ }
209225 }
210- }
211- assert len (event ["request" ]["data" ]["foo" ]) == DEFAULT_MAX_VALUE_LENGTH
226+ assert len (event ["request" ]["data" ]["foo" ]) == 1024
227+ else :
228+ assert len (event ["request" ]["data" ]["foo" ]) == 1034
212229
213230
214231@pytest .mark .parametrize ("input_char" , ["a" , b"a" ])
@@ -242,11 +259,16 @@ def index():
242259 assert not event ["request" ]["data" ]
243260
244261
245- def test_files_and_form (sentry_init , capture_events , app , get_client ):
246- sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
262+ @pytest .mark .parametrize ("max_value_length" , [1024 , None ])
263+ def test_files_and_form (sentry_init , capture_events , app , get_client , max_value_length ):
264+ sentry_init (
265+ integrations = [BottleIntegration ()],
266+ max_request_body_size = "always" ,
267+ max_value_length = max_value_length ,
268+ )
247269
248270 data = {
249- "foo" : "a" * (DEFAULT_MAX_VALUE_LENGTH + 10 ),
271+ "foo" : "a" * (1034 ),
250272 "file" : (BytesIO (b"hello" ), "hello.txt" ),
251273 }
252274
@@ -267,15 +289,16 @@ def index():
267289 assert response [1 ] == "200 OK"
268290
269291 (event ,) = events
270- assert event [ "_meta" ][ "request" ][ "data" ][ "foo" ] == {
271- "" : {
272- "len " : DEFAULT_MAX_VALUE_LENGTH + 10 ,
273- "rem " : [
274- [ "!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
275- ],
292+ if max_value_length :
293+ assert event [ "_meta" ][ "request" ][ "data" ][ "foo" ] == {
294+ "" : {
295+ "len " : 1034 ,
296+ "rem" : [[ "!limit" , "x" , 1021 , 1024 ]],
297+ }
276298 }
277- }
278- assert len (event ["request" ]["data" ]["foo" ]) == DEFAULT_MAX_VALUE_LENGTH
299+ assert len (event ["request" ]["data" ]["foo" ]) == 1024
300+ else :
301+ assert len (event ["request" ]["data" ]["foo" ]) == 1034
279302
280303 assert event ["_meta" ]["request" ]["data" ]["file" ] == {
281304 "" : {
0 commit comments