Skip to content

Commit c8a09cc

Browse files
committed
some fixes
1 parent 1553d66 commit c8a09cc

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

tests/integrations/flask/test_flask.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
capture_message,
2828
capture_exception,
2929
)
30+
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH
3031
from sentry_sdk.integrations.logging import LoggingIntegration
3132
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
3233

@@ -250,7 +251,7 @@ def login():
250251
def test_flask_large_json_request(sentry_init, capture_events, app):
251252
sentry_init(integrations=[flask_sentry.FlaskIntegration()])
252253

253-
data = {"foo": {"bar": "a" * 2000}}
254+
data = {"foo": {"bar": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10)}}
254255

255256
@app.route("/", methods=["POST"])
256257
def index():
@@ -268,9 +269,14 @@ def index():
268269

269270
(event,) = events
270271
assert event["_meta"]["request"]["data"]["foo"]["bar"] == {
271-
"": {"len": 2000, "rem": [["!limit", "x", 1021, 1024]]}
272+
"": {
273+
"len": DEFAULT_MAX_VALUE_LENGTH + 10,
274+
"rem": [
275+
["!limit", "x", DEFAULT_MAX_VALUE_LENGTH - 3, DEFAULT_MAX_VALUE_LENGTH]
276+
],
277+
}
272278
}
273-
assert len(event["request"]["data"]["foo"]["bar"]) == 1024
279+
assert len(event["request"]["data"]["foo"]["bar"]) == DEFAULT_MAX_VALUE_LENGTH
274280

275281

276282
def test_flask_session_tracking(sentry_init, capture_envelopes, app):
@@ -338,7 +344,7 @@ def index():
338344
def test_flask_medium_formdata_request(sentry_init, capture_events, app):
339345
sentry_init(integrations=[flask_sentry.FlaskIntegration()])
340346

341-
data = {"foo": "a" * 2000}
347+
data = {"foo": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10)}
342348

343349
@app.route("/", methods=["POST"])
344350
def index():
@@ -360,9 +366,14 @@ def index():
360366

361367
(event,) = events
362368
assert event["_meta"]["request"]["data"]["foo"] == {
363-
"": {"len": 2000, "rem": [["!limit", "x", 1021, 1024]]}
369+
"": {
370+
"len": DEFAULT_MAX_VALUE_LENGTH + 10,
371+
"rem": [
372+
["!limit", "x", DEFAULT_MAX_VALUE_LENGTH - 3, DEFAULT_MAX_VALUE_LENGTH]
373+
],
374+
}
364375
}
365-
assert len(event["request"]["data"]["foo"]) == 1024
376+
assert len(event["request"]["data"]["foo"]) == DEFAULT_MAX_VALUE_LENGTH
366377

367378

368379
def test_flask_formdata_request_appear_transaction_body(
@@ -441,7 +452,10 @@ def test_flask_files_and_form(sentry_init, capture_events, app):
441452
integrations=[flask_sentry.FlaskIntegration()], max_request_body_size="always"
442453
)
443454

444-
data = {"foo": "a" * 2000, "file": (BytesIO(b"hello"), "hello.txt")}
455+
data = {
456+
"foo": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10),
457+
"file": (BytesIO(b"hello"), "hello.txt"),
458+
}
445459

446460
@app.route("/", methods=["POST"])
447461
def index():
@@ -463,9 +477,14 @@ def index():
463477

464478
(event,) = events
465479
assert event["_meta"]["request"]["data"]["foo"] == {
466-
"": {"len": 2000, "rem": [["!limit", "x", 1021, 1024]]}
480+
"": {
481+
"len": DEFAULT_MAX_VALUE_LENGTH + 10,
482+
"rem": [
483+
["!limit", "x", DEFAULT_MAX_VALUE_LENGTH - 3, DEFAULT_MAX_VALUE_LENGTH]
484+
],
485+
}
467486
}
468-
assert len(event["request"]["data"]["foo"]) == 1024
487+
assert len(event["request"]["data"]["foo"]) == DEFAULT_MAX_VALUE_LENGTH
469488

470489
assert event["_meta"]["request"]["data"]["file"] == {"": {"rem": [["!raw", "x"]]}}
471490
assert not event["request"]["data"]["file"]

tests/integrations/sqlalchemy/test_sqlalchemy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ def processor(event, hint):
275275

276276
# The _meta for other truncated fields should be there as well.
277277
assert event["_meta"]["message"] == {
278-
"": {"len": 1034, "rem": [["!limit", "x", 1021, 1024]]}
278+
"": {
279+
"len": DEFAULT_MAX_VALUE_LENGTH + 10,
280+
"rem": [
281+
["!limit", "x", DEFAULT_MAX_VALUE_LENGTH - 3, DEFAULT_MAX_VALUE_LENGTH]
282+
],
283+
}
279284
}
280285

281286

tests/test_client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,14 +773,14 @@ def test_databag_string_stripping(sentry_init, capture_events, benchmark):
773773
def inner():
774774
del events[:]
775775
try:
776-
a = "A" * 1000000 # noqa
776+
a = "A" * DEFAULT_MAX_VALUE_LENGTH * 100 # noqa
777777
1 / 0
778778
except Exception:
779779
capture_exception()
780780

781781
(event,) = events
782782

783-
assert len(json.dumps(event)) < 10000
783+
assert len(json.dumps(event)) < DEFAULT_MAX_VALUE_LENGTH * 100
784784

785785

786786
def test_databag_breadth_stripping(sentry_init, capture_events, benchmark):
@@ -1073,7 +1073,10 @@ def test_multiple_positional_args(sentry_init):
10731073
"sdk_options, expected_data_length",
10741074
[
10751075
({}, DEFAULT_MAX_VALUE_LENGTH),
1076-
({"max_value_length": 1800}, 1800),
1076+
(
1077+
{"max_value_length": DEFAULT_MAX_VALUE_LENGTH + 1000},
1078+
DEFAULT_MAX_VALUE_LENGTH + 1000,
1079+
),
10771080
],
10781081
)
10791082
def test_max_value_length_option(
@@ -1082,7 +1085,7 @@ def test_max_value_length_option(
10821085
sentry_init(sdk_options)
10831086
events = capture_events()
10841087

1085-
capture_message("a" * 2000)
1088+
capture_message("a" * (DEFAULT_MAX_VALUE_LENGTH + 2000))
10861089

10871090
assert len(events[0]["message"]) == expected_data_length
10881091

tests/test_serializer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH
56
from sentry_sdk.serializer import MAX_DATABAG_BREADTH, MAX_DATABAG_DEPTH, serialize
67

78
try:
@@ -166,11 +167,11 @@ def test_no_trimming_if_max_request_body_size_is_always(body_normalizer):
166167

167168

168169
def test_max_value_length_default(body_normalizer):
169-
data = {"key": "a" * 2000}
170+
data = {"key": "a" * (DEFAULT_MAX_VALUE_LENGTH * 10)}
170171

171172
result = body_normalizer(data)
172173

173-
assert len(result["key"]) == 1024 # fallback max length
174+
assert len(result["key"]) == DEFAULT_MAX_VALUE_LENGTH # fallback max length
174175

175176

176177
def test_max_value_length(body_normalizer):

0 commit comments

Comments
 (0)