1
+ import json
2
+
1
3
from aiohttp import web
2
4
3
5
from sentry_sdk .integrations .aiohttp import AioHttpIntegration
@@ -33,6 +35,7 @@ async def hello(request):
33
35
assert request ["env" ] == {"REMOTE_ADDR" : "127.0.0.1" }
34
36
assert request ["method" ] == "GET"
35
37
assert request ["query_string" ] == ""
38
+ assert request .get ("data" ) is None
36
39
assert request ["url" ] == "http://{host}/" .format (host = host )
37
40
assert request ["headers" ] == {
38
41
"Accept" : "*/*" ,
@@ -42,6 +45,63 @@ async def hello(request):
42
45
}
43
46
44
47
48
+ async def test_post_body_not_read (sentry_init , aiohttp_client , loop , capture_events ):
49
+ from sentry_sdk .integrations .aiohttp import BODY_NOT_READ_MESSAGE
50
+
51
+ sentry_init (integrations = [AioHttpIntegration ()])
52
+
53
+ body = {"some" : "value" }
54
+
55
+ async def hello (request ):
56
+ 1 / 0
57
+
58
+ app = web .Application ()
59
+ app .router .add_post ("/" , hello )
60
+
61
+ events = capture_events ()
62
+
63
+ client = await aiohttp_client (app )
64
+ resp = await client .post ("/" , json = body )
65
+ assert resp .status == 500
66
+
67
+ event , = events
68
+ exception , = event ["exception" ]["values" ]
69
+ assert exception ["type" ] == "ZeroDivisionError"
70
+ request = event ["request" ]
71
+
72
+ assert request ["env" ] == {"REMOTE_ADDR" : "127.0.0.1" }
73
+ assert request ["method" ] == "POST"
74
+ assert request ["data" ] == BODY_NOT_READ_MESSAGE
75
+
76
+
77
+ async def test_post_body_read (sentry_init , aiohttp_client , loop , capture_events ):
78
+ sentry_init (integrations = [AioHttpIntegration ()])
79
+
80
+ body = {"some" : "value" }
81
+
82
+ async def hello (request ):
83
+ await request .json ()
84
+ 1 / 0
85
+
86
+ app = web .Application ()
87
+ app .router .add_post ("/" , hello )
88
+
89
+ events = capture_events ()
90
+
91
+ client = await aiohttp_client (app )
92
+ resp = await client .post ("/" , json = body )
93
+ assert resp .status == 500
94
+
95
+ event , = events
96
+ exception , = event ["exception" ]["values" ]
97
+ assert exception ["type" ] == "ZeroDivisionError"
98
+ request = event ["request" ]
99
+
100
+ assert request ["env" ] == {"REMOTE_ADDR" : "127.0.0.1" }
101
+ assert request ["method" ] == "POST"
102
+ assert request ["data" ] == json .dumps (body )
103
+
104
+
45
105
async def test_403_not_captured (sentry_init , aiohttp_client , loop , capture_events ):
46
106
sentry_init (integrations = [AioHttpIntegration ()])
47
107
0 commit comments