Skip to content

Commit

Permalink
refactor: Add recursive scrubbing to EventScrubber with tests, change
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheapshot003 committed Feb 22, 2024
1 parent fd1f9f4 commit 10cc33d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sentry_sdk/scrubber.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

class EventScrubber(object):
def __init__(self, denylist=None, recursive=False):
# type: (Optional[List[str]]) -> None
# type: (Optional[List[str]], bool) -> None
self.denylist = DEFAULT_DENYLIST if denylist is None else denylist
self.denylist = [x.lower() for x in self.denylist]
self.recursive = recursive
Expand Down
12 changes: 4 additions & 8 deletions tests/test_scrubber.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from sentry_sdk import capture_exception, capture_event, start_transaction, start_span
from sentry_sdk.utils import event_from_exception, AnnotatedValue
from sentry_sdk.utils import event_from_exception
from sentry_sdk.scrubber import EventScrubber


Expand Down Expand Up @@ -171,10 +171,9 @@ def test_scrubbing_doesnt_affect_local_vars(sentry_init, capture_events):
assert password == "cat123"


def test_recursive_EventScrubber(sentry_init, capture_events):
sentry_init()
def test_recursive_event_scrubber(sentry_init, capture_events):
sentry_init(event_scrubber=EventScrubber(recursive=True))
events = capture_events()
customScrubber = EventScrubber(recursive=True)
complex_structure = {
"deep": {
"deeper": [{"deepest": {"password": "my_darkest_secret"}}],
Expand All @@ -184,7 +183,4 @@ def test_recursive_EventScrubber(sentry_init, capture_events):
capture_event({"extra": complex_structure})

(event,) = events
customScrubber.scrub_event(event)
assert isinstance(
event["extra"]["deep"]["deeper"][0]["deepest"]["password"], AnnotatedValue
)
assert event["extra"]["deep"]["deeper"][0]["deepest"]["password"] == "'[Filtered]'"

0 comments on commit 10cc33d

Please sign in to comment.