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
89from sentry_sdk .integrations .bottle import BottleIntegration
910from sentry_sdk .serializer import MAX_DATABAG_BREADTH
1011
@@ -121,9 +122,9 @@ def index():
121122
122123
123124def test_large_json_request (sentry_init , capture_events , app , get_client ):
124- sentry_init (integrations = [BottleIntegration ()])
125+ sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
125126
126- data = {"foo" : {"bar" : "a" * 2000 }}
127+ data = {"foo" : {"bar" : "a" * ( DEFAULT_MAX_VALUE_LENGTH + 10 ) }}
127128
128129 @app .route ("/" , method = "POST" )
129130 def index ():
@@ -144,9 +145,14 @@ def index():
144145
145146 (event ,) = events
146147 assert event ["_meta" ]["request" ]["data" ]["foo" ]["bar" ] == {
147- "" : {"len" : 2000 , "rem" : [["!limit" , "x" , 1021 , 1024 ]]}
148+ "" : {
149+ "len" : DEFAULT_MAX_VALUE_LENGTH + 10 ,
150+ "rem" : [
151+ ["!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
152+ ],
153+ }
148154 }
149- assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == 1024
155+ assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == DEFAULT_MAX_VALUE_LENGTH
150156
151157
152158@pytest .mark .parametrize ("data" , [{}, []], ids = ["empty-dict" , "empty-list" ])
@@ -174,9 +180,9 @@ def index():
174180
175181
176182def test_medium_formdata_request (sentry_init , capture_events , app , get_client ):
177- sentry_init (integrations = [BottleIntegration ()])
183+ sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
178184
179- data = {"foo" : "a" * 2000 }
185+ data = {"foo" : "a" * ( DEFAULT_MAX_VALUE_LENGTH + 10 ) }
180186
181187 @app .route ("/" , method = "POST" )
182188 def index ():
@@ -194,9 +200,14 @@ def index():
194200
195201 (event ,) = events
196202 assert event ["_meta" ]["request" ]["data" ]["foo" ] == {
197- "" : {"len" : 2000 , "rem" : [["!limit" , "x" , 1021 , 1024 ]]}
203+ "" : {
204+ "len" : DEFAULT_MAX_VALUE_LENGTH + 10 ,
205+ "rem" : [
206+ ["!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
207+ ],
208+ }
198209 }
199- assert len (event ["request" ]["data" ]["foo" ]) == 1024
210+ assert len (event ["request" ]["data" ]["foo" ]) == DEFAULT_MAX_VALUE_LENGTH
200211
201212
202213@pytest .mark .parametrize ("input_char" , ["a" , b"a" ])
@@ -233,7 +244,10 @@ def index():
233244def test_files_and_form (sentry_init , capture_events , app , get_client ):
234245 sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
235246
236- data = {"foo" : "a" * 2000 , "file" : (BytesIO (b"hello" ), "hello.txt" )}
247+ data = {
248+ "foo" : "a" * (DEFAULT_MAX_VALUE_LENGTH + 10 ),
249+ "file" : (BytesIO (b"hello" ), "hello.txt" ),
250+ }
237251
238252 @app .route ("/" , method = "POST" )
239253 def index ():
@@ -253,9 +267,14 @@ def index():
253267
254268 (event ,) = events
255269 assert event ["_meta" ]["request" ]["data" ]["foo" ] == {
256- "" : {"len" : 2000 , "rem" : [["!limit" , "x" , 1021 , 1024 ]]}
270+ "" : {
271+ "len" : DEFAULT_MAX_VALUE_LENGTH + 10 ,
272+ "rem" : [
273+ ["!limit" , "x" , DEFAULT_MAX_VALUE_LENGTH - 3 , DEFAULT_MAX_VALUE_LENGTH ]
274+ ],
275+ }
257276 }
258- assert len (event ["request" ]["data" ]["foo" ]) == 1024
277+ assert len (event ["request" ]["data" ]["foo" ]) == DEFAULT_MAX_VALUE_LENGTH
259278
260279 assert event ["_meta" ]["request" ]["data" ]["file" ] == {
261280 "" : {
0 commit comments