1313from sentry_sdk import capture_message
1414from sentry_sdk ._types import SENSITIVE_DATA_SUBSTITUTE
1515from sentry_sdk .integrations .starlite import StarliteIntegration
16- from tests .integrations .utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
16+ from tests .integrations .utils import DATA_COLLECTION_USER_INFO_CASES
1717
1818
1919def starlite_app_factory (middleware = None , debug = True , exception_handlers = None ):
@@ -100,7 +100,7 @@ def test_catch_exceptions(
100100 expected_message ,
101101 expected_tx_name ,
102102):
103- sentry_init (integrations = [StarliteIntegration ()])
103+ sentry_init (integrations = [StarliteIntegration ()], data_collection = {} )
104104 starlite_app = starlite_app_factory ()
105105 exceptions = capture_exceptions ()
106106 events = capture_events ()
@@ -146,6 +146,7 @@ def test_transaction_name_and_source(
146146 sentry_init (
147147 traces_sample_rate = 1.0 ,
148148 integrations = [StarliteIntegration ()],
149+ data_collection = {},
149150 )
150151 starlite_app = starlite_app_factory ()
151152 client = TestClient (starlite_app )
@@ -168,6 +169,7 @@ def test_middleware_spans(sentry_init, capture_items):
168169 sentry_init (
169170 traces_sample_rate = 1.0 ,
170171 integrations = [StarliteIntegration ()],
172+ data_collection = {},
171173 )
172174
173175 logging_config = LoggingMiddlewareConfig ()
@@ -222,6 +224,7 @@ async def do_stuff(message):
222224 sentry_init (
223225 traces_sample_rate = 1.0 ,
224226 integrations = [StarliteIntegration ()],
227+ data_collection = {},
225228 )
226229 starlite_app = starlite_app_factory (middleware = [SampleMiddleware ])
227230
@@ -283,6 +286,7 @@ async def __call__(self, scope, receive, send):
283286 sentry_init (
284287 traces_sample_rate = 1.0 ,
285288 integrations = [StarliteIntegration ()],
289+ data_collection = {},
286290 )
287291 starlite_app = starlite_app_factory (middleware = [SampleReceiveSendMiddleware ])
288292
@@ -315,6 +319,7 @@ async def my_send(*args, **kwargs):
315319 sentry_init (
316320 traces_sample_rate = 1.0 ,
317321 integrations = [StarliteIntegration ()],
322+ data_collection = {},
318323 )
319324 starlite_app = starlite_app_factory (middleware = [SamplePartialReceiveSendMiddleware ])
320325
@@ -365,6 +370,7 @@ def test_span_origin(sentry_init, capture_items):
365370 sentry_init (
366371 integrations = [StarliteIntegration ()],
367372 traces_sample_rate = 1.0 ,
373+ data_collection = {},
368374 )
369375
370376 logging_config = LoggingMiddlewareConfig ()
@@ -399,10 +405,10 @@ def test_span_origin(sentry_init, capture_items):
399405
400406
401407@pytest .mark .parametrize (
402- "init_kwargs , expect_user" , DATA_COLLECTION_USER_INFO_CASES_LEGACY
408+ "data_collection , expect_user" , DATA_COLLECTION_USER_INFO_CASES
403409)
404410def test_starlite_scope_user_on_exception_event (
405- sentry_init , capture_exceptions , capture_events , init_kwargs , expect_user
411+ sentry_init , capture_exceptions , capture_events , data_collection , expect_user
406412):
407413 class TestUserMiddleware (AbstractMiddleware ):
408414 async def __call__ (self , scope , receive , send ):
@@ -413,7 +419,7 @@ async def __call__(self, scope, receive, send):
413419 }
414420 await self .app (scope , receive , send )
415421
416- sentry_init (integrations = [StarliteIntegration ()], ** init_kwargs )
422+ sentry_init (integrations = [StarliteIntegration ()], data_collection = data_collection )
417423 starlite_app = starlite_app_factory (middleware = [TestUserMiddleware ])
418424 exceptions = capture_exceptions ()
419425 events = capture_events ()
@@ -446,7 +452,6 @@ async def __call__(self, scope, receive, send):
446452@pytest .mark .parametrize (
447453 "data_collection, expect_body" ,
448454 [
449- pytest .param (None , True , id = "no_data_collection_experiment" ),
450455 pytest .param ({}, True , id = "data_collection_http_bodies_default" ),
451456 pytest .param (
452457 {"http_bodies" : ["incoming_request" ]},
@@ -483,57 +488,26 @@ def test_request_body_data_collection(
483488 assert "data" not in event ["request" ]
484489
485490
486- def test_request_body_data_collection_wins_over_send_default_pii (
487- sentry_init , capture_events
488- ):
489- sentry_init (
490- traces_sample_rate = 1.0 ,
491- integrations = [StarliteIntegration ()],
492- send_default_pii = True ,
493- data_collection = {"http_bodies" : []},
494- )
495-
496- starlite_app = starlite_app_factory ()
497- events = capture_events ()
498-
499- client = TestClient (starlite_app )
500- client .post ("/body/json" , json = {"foo" : {"bar" : "baz" , "qux" : ["1" , "2" , "3" ]}})
501-
502- (event ,) = events
503-
504- assert "data" not in event ["request" ]
505-
506-
507491@pytest .mark .parametrize (
508- "init_kwargs , expected_cookies" ,
492+ "data_collection , expected_cookies" ,
509493 [
510494 pytest .param (
511- {"send_default_pii" : True },
495+ {},
512496 {
513- "jwt" : "tokenval" ,
497+ "jwt" : SENSITIVE_DATA_SUBSTITUTE ,
514498 "theme" : "dark" ,
515499 "lang" : "en" ,
516- "identity" : "alice" ,
500+ "identity" : SENSITIVE_DATA_SUBSTITUTE ,
517501 },
518- id = "send_default_pii_true" ,
519- ),
520- pytest .param (
521- {"send_default_pii" : False },
522- None ,
523- id = "send_default_pii_false" ,
524- ),
525- pytest .param (
526- {},
527- None ,
528- id = "defaults" ,
502+ id = "data_collection_default" ,
529503 ),
530504 pytest .param (
531- {"data_collection" : { " cookies" : {"mode" : "off" } }},
505+ {"cookies" : {"mode" : "off" }},
532506 None ,
533507 id = "data_collection_off" ,
534508 ),
535509 pytest .param (
536- {"data_collection" : { " cookies" : {"mode" : "denylist" } }},
510+ {"cookies" : {"mode" : "denylist" }},
537511 {
538512 "jwt" : SENSITIVE_DATA_SUBSTITUTE ,
539513 "theme" : "dark" ,
@@ -543,7 +517,7 @@ def test_request_body_data_collection_wins_over_send_default_pii(
543517 id = "data_collection_denylist_default" ,
544518 ),
545519 pytest .param (
546- {"data_collection" : { " cookies" : {"mode" : "denylist" , "terms" : ["theme" ]} }},
520+ {"cookies" : {"mode" : "denylist" , "terms" : ["theme" ]}},
547521 {
548522 "jwt" : SENSITIVE_DATA_SUBSTITUTE ,
549523 "theme" : SENSITIVE_DATA_SUBSTITUTE ,
@@ -553,7 +527,7 @@ def test_request_body_data_collection_wins_over_send_default_pii(
553527 id = "data_collection_denylist_custom_terms" ,
554528 ),
555529 pytest .param (
556- {"data_collection" : { " cookies" : {"mode" : "allowlist" , "terms" : ["theme" ]} }},
530+ {"cookies" : {"mode" : "allowlist" , "terms" : ["theme" ]}},
557531 {
558532 "jwt" : SENSITIVE_DATA_SUBSTITUTE ,
559533 "theme" : "dark" ,
@@ -563,11 +537,7 @@ def test_request_body_data_collection_wins_over_send_default_pii(
563537 id = "data_collection_allowlist" ,
564538 ),
565539 pytest .param (
566- {
567- "data_collection" : {
568- "cookies" : {"mode" : "allowlist" , "terms" : ["identity" ]}
569- }
570- },
540+ {"cookies" : {"mode" : "allowlist" , "terms" : ["identity" ]}},
571541 {
572542 "jwt" : SENSITIVE_DATA_SUBSTITUTE ,
573543 "theme" : SENSITIVE_DATA_SUBSTITUTE ,
@@ -576,28 +546,15 @@ def test_request_body_data_collection_wins_over_send_default_pii(
576546 },
577547 id = "data_collection_allowlist_sensitive_term" ,
578548 ),
579- pytest .param (
580- {
581- "send_default_pii" : False ,
582- "data_collection" : {"cookies" : {"mode" : "denylist" }},
583- },
584- {
585- "jwt" : SENSITIVE_DATA_SUBSTITUTE ,
586- "theme" : "dark" ,
587- "lang" : "en" ,
588- "identity" : SENSITIVE_DATA_SUBSTITUTE ,
589- },
590- id = "data_collection_wins_over_send_default_pii" ,
591- ),
592549 ],
593550)
594551def test_cookie_data_collection (
595- sentry_init , capture_events , init_kwargs , expected_cookies
552+ sentry_init , capture_events , data_collection , expected_cookies
596553):
597554 sentry_init (
598555 traces_sample_rate = 1.0 ,
599556 integrations = [StarliteIntegration ()],
600- ** init_kwargs ,
557+ data_collection = data_collection ,
601558 )
602559
603560 starlite_app = starlite_app_factory ()
0 commit comments