8000 fix: Wsgi - valid JSONs ([], {}) are evaluated as raw data by shenek · Pull Request #286 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content

fix: Wsgi - valid JSONs ([], {}) are evaluated as raw data #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/_wsgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def extract_into_event(self, event):
)
else:
parsed_body = self.parsed_body()
if parsed_body:
if parsed_body is not None:
data = parsed_body
elif self.raw_data():
data = AnnotatedValue(
Expand Down
22 changes: 22 additions & 0 deletions tests/integrations/flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,28 @@ def index():
assert len(event["request"]["data"]["foo"]["bar"]) == 512


@pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"])
def test_flask_empty_json_request(sentry_init, capture_events, app, data):
sentry_init(integrations=[flask_sentry.FlaskIntegration()])

@app.route("/", methods=["POST"])
def index():
assert request.json == data
assert request.data == json.dumps(data).encode("ascii")
assert not request.form
capture_message("hi")
return "ok"

events = capture_events()

client = app.test_client()
response = client.post("/", content_type="application/json", data=json.dumps(data))
assert response.status_code == 200

event, = events
assert event["request"]["data"] == data


def test_flask_medium_formdata_request(sentry_init, capture_events, app):
sentry_init(integrations=[flask_sentry.FlaskIntegration()])

Expand Down
22 changes: 22 additions & 0 deletions tests/integrations/pyramid/test_pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ def index(request):
assert len(event["request"]["data"]["foo"]["bar"]) == 512


@pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"])
def test_flask_empty_json_request(sentry_init, capture_events, route, get_client, data):
sentry_init(integrations=[PyramidIntegration()])

@route("/")
def index(request):
assert request.json == data
assert request.text == json.dumps(data)
assert not request.POST
capture_message("hi")
return Response("ok")

events = capture_events()

client = get_client()
response = client.post("/", content_type="application/json", data=json.dumps(data))
assert response[1] == "200 OK"

event, = events
assert event["request"]["data"] == data


def test_files_and_form(sentry_init, capture_events, route, get_client):
sentry_init(integrations=[PyramidIntegration()], request_bodies="always")

Expand Down
0