@@ -45,153 +45,9 @@ def resolve_name(obj, *_):
4545 return make_executable_schema (type_defs , query )
4646
4747
48- def test_capture_request_and_response_if_send_pii_is_on_async (
49- sentry_init , capture_events
50- ):
51- sentry_init (
52- send_default_pii = True ,
53- integrations = [
54- AriadneIntegration (),
55- FastApiIntegration (),
56- StarletteIntegration (),
57- ],
58- )
59- events = capture_events ()
60-
61- schema = schema_factory ()
62-
63- async_app = FastAPI ()
64- async_app .mount ("/graphql/" , GraphQL (schema ))
65-
66- query = {"query" : "query ErrorQuery {error}" }
67- client = TestClient (async_app )
68- client .post ("/graphql" , json = query )
69-
70- assert len (events ) == 1
71-
72- (event ,) = events
73- assert event ["exception" ]["values" ][0 ]["mechanism" ]["type" ] == "ariadne"
74- assert event ["contexts" ]["response" ] == {
75- "data" : {
76- "data" : {"error" : None },
77- "errors" : [
78- {
79- "locations" : [{"column" : 19 , "line" : 1 }],
80- "message" : "resolver failed" ,
81- "path" : ["error" ],
82- }
83- ],
84- }
85- }
86- assert event ["request" ]["api_target" ] == "graphql"
87- assert event ["request" ]["data" ] == query
88-
89-
90- def test_capture_request_and_response_if_send_pii_is_on_sync (
91- sentry_init , capture_events
92- ):
93- sentry_init (
94- send_default_pii = True ,
95- integrations = [AriadneIntegration (), FlaskIntegration ()],
96- )
97- events = capture_events ()
98-
99- schema = schema_factory ()
100-
101- sync_app = Flask (__name__ )
102-
103- @sync_app .route ("/graphql" , methods = ["POST" ])
104- def graphql_server ():
105- data = request .get_json ()
106- success , result = graphql_sync (schema , data )
107- return jsonify (result ), 200
108-
109- query = {"query" : "query ErrorQuery {error}" }
110- client = sync_app .test_client ()
111- client .post ("/graphql" , json = query )
112-
113- assert len (events ) == 1
114-
115- (event ,) = events
116- assert event ["exception" ]["values" ][0 ]["mechanism" ]["type" ] == "ariadne"
117- assert event ["contexts" ]["response" ] == {
118- "data" : {
119- "data" : {"error" : None },
120- "errors" : [
121- {
122- "locations" : [{"column" : 19 , "line" : 1 }],
123- "message" : "resolver failed" ,
124- "path" : ["error" ],
125- }
126- ],
127- }
128- }
129- assert event ["request" ]["api_target" ] == "graphql"
130- assert event ["request" ]["data" ] == query
131-
132-
133- def test_do_not_capture_request_and_response_if_send_pii_is_off_async (
134- sentry_init , capture_events
135- ):
136- sentry_init (
137- integrations = [
138- AriadneIntegration (),
139- FastApiIntegration (),
140- StarletteIntegration (),
141- ],
142- )
143- events = capture_events ()
144-
145- schema = schema_factory ()
146-
147- async_app = FastAPI ()
148- async_app .mount ("/graphql/" , GraphQL (schema ))
149-
150- query = {"query" : "query ErrorQuery {error}" }
151- client = TestClient (async_app )
152- client .post ("/graphql" , json = query )
153-
154- assert len (events ) == 1
155-
156- (event ,) = events
157- assert event ["exception" ]["values" ][0 ]["mechanism" ]["type" ] == "ariadne"
158- assert "data" not in event ["request" ]
159- assert "response" not in event ["contexts" ]
160-
161-
162- def test_do_not_capture_request_and_response_if_send_pii_is_off_sync (
163- sentry_init , capture_events
164- ):
165- sentry_init (
166- integrations = [AriadneIntegration (), FlaskIntegration ()],
167- )
168- events = capture_events ()
169-
170- schema = schema_factory ()
171-
172- sync_app = Flask (__name__ )
173-
174- @sync_app .route ("/graphql" , methods = ["POST" ])
175- def graphql_server ():
176- data = request .get_json ()
177- success , result = graphql_sync (schema , data )
178- return jsonify (result ), 200
179-
180- query = {"query" : "query ErrorQuery {error}" }
181- client = sync_app .test_client ()
182- client .post ("/graphql" , json = query )
183-
184- assert len (events ) == 1
185-
186- (event ,) = events
187- assert event ["exception" ]["values" ][0 ]["mechanism" ]["type" ] == "ariadne"
188- assert "data" not in event ["request" ]
189- assert "response" not in event ["contexts" ]
190-
191-
19248def test_capture_validation_error (sentry_init , capture_events ):
19349 sentry_init (
194- send_default_pii = True ,
50+ data_collection = {} ,
19551 integrations = [
19652 AriadneIntegration (),
19753 FastApiIntegration (),
@@ -234,6 +90,7 @@ def test_no_event_if_no_errors_async(sentry_init, capture_events):
23490 FastApiIntegration (),
23591 StarletteIntegration (),
23692 ],
93+ data_collection = {},
23794 )
23895 events = capture_events ()
23996
@@ -255,6 +112,7 @@ def test_no_event_if_no_errors_async(sentry_init, capture_events):
255112def test_no_event_if_no_errors_sync (sentry_init , capture_events ):
256113 sentry_init (
257114 integrations = [AriadneIntegration (), FlaskIntegration ()],
115+ data_collection = {},
258116 )
259117 events = capture_events ()
260118
@@ -310,80 +168,58 @@ def graphql_server():
310168 return make_client
311169
312170
313- def _init_all_integrations (sentry_init , ** kwargs ):
314- sentry_init (
315- integrations = [
316- AriadneIntegration (),
317- FlaskIntegration (),
318- FastApiIntegration (),
319- StarletteIntegration (),
320- ],
321- ** kwargs ,
322- )
323-
324-
325171@pytest .mark .parametrize (
326- "init_kwargs ,expect_query,expect_variables" ,
172+ "data_collection ,expect_query,expect_variables" ,
327173 [
328174 pytest .param (
329- {"data_collection" : {} },
175+ {},
330176 True ,
331177 True ,
332178 id = "data_collection_defaults" ,
333179 ),
334180 pytest .param (
335- {"data_collection" : { " graphql" : {"document" : True , "variables" : True } }},
181+ {"graphql" : {"document" : True , "variables" : True }},
336182 True ,
337183 True ,
338184 id = "document_on_variables_on" ,
339185 ),
340186 pytest .param (
341- {"data_collection" : { " graphql" : {"document" : False } }},
187+ {"graphql" : {"document" : False }},
342188 False ,
343189 True ,
344190 id = "document_off_variables_on" ,
345191 ),
346192 pytest .param (
347- {"data_collection" : { " graphql" : {"variables" : False } }},
193+ {"graphql" : {"variables" : False }},
348194 True ,
349195 False ,
350196 id = "document_on_variables_off" ,
351197 ),
352198 pytest .param (
353- {"data_collection" : { " graphql" : {"document" : False , "variables" : False } }},
199+ {"graphql" : {"document" : False , "variables" : False }},
354200 None ,
355201 None ,
356202 id = "document_off_variables_off" ,
357203 ),
358- pytest .param (
359- {
360- "send_default_pii" : True ,
361- "data_collection" : {"graphql" : {"document" : False }},
362- },
363- False ,
364- True ,
365- id = "data_collection_takes_precedence_over_send_default_pii_on" ,
366- ),
367- pytest .param (
368- {
369- "send_default_pii" : False ,
370- "data_collection" : {"graphql" : {"document" : True }},
371- },
372- True ,
373- True ,
374- id = "data_collection_takes_precedence_over_send_default_pii_off" ,
375- ),
376204 ],
377205)
378206def test_request_data_collection (
379207 sentry_init ,
380208 capture_events ,
381209 graphql_client ,
382- init_kwargs ,
210+ data_collection ,
383211 expect_query ,
384212 expect_variables ,
385213):
386- _init_all_integrations (sentry_init , ** init_kwargs )
214+ sentry_init (
215+ integrations = [
216+ AriadneIntegration (),
217+ FlaskIntegration (),
218+ FastApiIntegration (),
219+ StarletteIntegration (),
220+ ],
221+ data_collection = data_collection ,
222+ )
387223 events = capture_events ()
388224
389225 graphql_client ().post ("/graphql" , json = ERROR_QUERY_WITH_VARIABLES )
@@ -411,10 +247,15 @@ def test_request_data_collection_body_out_of_bounds_still_collects_variables(
411247 dropped but variables (which are not subject to the bounds check) are
412248 still collected.
413249 """
414- _init_all_integrations (
415- sentry_init ,
416- max_request_body_size = "small" ,
250+ sentry_init (
251+ integrations = [
252+ AriadneIntegration (),
253+ FlaskIntegration (),
254+ FastApiIntegration (),
255+ StarletteIntegration (),
256+ ],
417257 data_collection = {},
258+ max_request_body_size = "small" ,
418259 )
419260 events = capture_events ()
420261
@@ -443,8 +284,16 @@ def test_request_data_collection_body_out_of_bounds_still_collects_variables(
443284def test_response_data_collection (
444285 sentry_init , capture_events , graphql_client , http_bodies , expect_response
445286):
446- data_collection = {} if http_bodies is None else {"http_bodies" : http_bodies }
447- _init_all_integrations (sentry_init , data_collection = data_collection )
287+ sentry_init (
288+ integrations = [
289+ AriadneIntegration (),
290+ FlaskIntegration (),
291+ FastApiIntegration (),
292+ StarletteIntegration (),
293+ ],
294+ data_collection = {} if http_bodies is None else {"http_bodies" : http_bodies },
295+ )
296+
448297 events = capture_events ()
449298
450299 graphql_client ().post ("/graphql" , json = {"query" : "query ErrorQuery {error}" })
0 commit comments