5
5
from io import BytesIO
6
6
from bottle import Bottle , debug as set_debug , abort , redirect , HTTPResponse
7
7
from sentry_sdk import capture_message
8
+ from sentry_sdk .consts import DEFAULT_MAX_VALUE_LENGTH
8
9
from sentry_sdk .integrations .bottle import BottleIntegration
9
10
from sentry_sdk .serializer import MAX_DATABAG_BREADTH
10
11
@@ -121,9 +122,9 @@ def index():
121
122
122
123
123
124
def 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" )
125
126
126
- data = {"foo" : {"bar" : "a" * 2000 }}
127
+ data = {"foo" : {"bar" : "a" * ( DEFAULT_MAX_VALUE_LENGTH + 10 ) }}
127
128
128
129
@app .route ("/" , method = "POST" )
129
130
def index ():
@@ -144,9 +145,14 @@ def index():
144
145
145
146
(event ,) = events
146
147
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
+ }
148
154
}
149
- assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == 1024
155
+ assert len (event ["request" ]["data" ]["foo" ]["bar" ]) == DEFAULT_MAX_VALUE_LENGTH
150
156
151
157
152
158
@pytest .mark .parametrize ("data" , [{}, []], ids = ["empty-dict" , "empty-list" ])
@@ -174,9 +180,9 @@ def index():
174
180
175
181
176
182
def 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" )
178
184
179
- data = {"foo" : "a" * 2000 }
185
+ data = {"foo" : "a" * ( DEFAULT_MAX_VALUE_LENGTH + 10 ) }
180
186
181
187
@app .route ("/" , method = "POST" )
182
188
def index ():
@@ -194,9 +200,14 @@ def index():
194
200
195
201
(event ,) = events
196
202
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
+ }
198
209
}
199
- assert len (event ["request" ]["data" ]["foo" ]) == 1024
210
+ assert len (event ["request" ]["data" ]["foo" ]) == DEFAULT_MAX_VALUE_LENGTH
200
211
201
212
202
213
@pytest .mark .parametrize ("input_char" , ["a" , b"a" ])
@@ -233,7 +244,10 @@ def index():
233
244
def test_files_and_form (sentry_init , capture_events , app , get_client ):
234
245
sentry_init (integrations = [BottleIntegration ()], max_request_body_size = "always" )
235
246
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
+ }
237
251
238
252
@app .route ("/" , method = "POST" )
239
253
def index ():
@@ -253,9 +267,14 @@ def index():
253
267
254
268
(event ,) = events
255
269
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
+ }
257
276
}
258
- assert len (event ["request" ]["data" ]["foo" ]) == 1024
277
+ assert len (event ["request" ]["data" ]["foo" ]) == DEFAULT_MAX_VALUE_LENGTH
259
278
260
279
assert event ["_meta" ]["request" ]["data" ]["file" ] == {
261
280
"" : {
0 commit comments