|
1 | 1 | import json
|
| 2 | +import logging |
2 | 3 | import threading
|
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 | from sentry_sdk.integrations.fastapi import FastApiIntegration
|
6 | 7 |
|
7 | 8 | fastapi = pytest.importorskip("fastapi")
|
8 | 9 |
|
9 |
| -from fastapi import FastAPI |
| 10 | +from fastapi import FastAPI, Request |
10 | 11 | from fastapi.testclient import TestClient
|
11 | 12 | from sentry_sdk import capture_message
|
12 | 13 | from sentry_sdk.integrations.starlette import StarletteIntegration
|
@@ -187,3 +188,33 @@ def test_active_thread_id(sentry_init, capture_envelopes, teardown_profiling, en
|
187 | 188 | transactions = profile.payload.json["transactions"]
|
188 | 189 | assert len(transactions) == 1
|
189 | 190 | assert str(data["active"]) == transactions[0]["active_thread_id"]
|
| 191 | + |
| 192 | + |
| 193 | +@pytest.mark.asyncio |
| 194 | +async def test_original_request_not_scrubbed(sentry_init, capture_events): |
| 195 | + sentry_init( |
| 196 | + integrations=[StarletteIntegration(), FastApiIntegration()], |
| 197 | + traces_sample_rate=1.0, |
| 198 | + debug=True, |
| 199 | + ) |
| 200 | + |
| 201 | + app = FastAPI() |
| 202 | + |
| 203 | + @app.post("/error") |
| 204 | + async def _error(request: Request): |
| 205 | + logging.critical("Oh no!") |
| 206 | + assert request.headers["Authorization"] == "Bearer ohno" |
| 207 | + assert await request.json() == {"password": "secret"} |
| 208 | + |
| 209 | + return {"error": "Oh no!"} |
| 210 | + |
| 211 | + events = capture_events() |
| 212 | + |
| 213 | + client = TestClient(app) |
| 214 | + client.post( |
| 215 | + "/error", json={"password": "secret"}, headers={"Authorization": "Bearer ohno"} |
| 216 | + ) |
| 217 | + |
| 218 | + event = events[0] |
| 219 | + assert event["request"]["data"] == {"password": "[Filtered]"} |
| 220 | + assert event["request"]["headers"]["authorization"] == "[Filtered]" |
0 commit comments