-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backup): Add EmailObfuscatingComparator (#53763)
This comparator is added to prevent sensitive data like user emails from leaking into logs, stack traces, and so on. Issue: getsentry/team-ospo#157
- Loading branch information
1 parent
4ebc61d
commit ed99e6e
Showing
2 changed files
with
208 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
from sentry.runner.commands.backup import DateUpdatedComparator, InstanceID | ||
from sentry.runner.commands.backup import ( | ||
DateUpdatedComparator, | ||
EmailObfuscatingComparator, | ||
InstanceID, | ||
) | ||
from sentry.utils.json import JSONData | ||
|
||
|
||
def test_good_comparator_both_sides_existing(): | ||
cmp = DateUpdatedComparator("my_date_field") | ||
id = InstanceID("test", 1) | ||
present = { | ||
present: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
|
@@ -17,7 +22,7 @@ def test_good_comparator_both_sides_existing(): | |
def test_good_comparator_neither_side_existing(): | ||
cmp = DateUpdatedComparator("my_date_field") | ||
id = InstanceID("test", 1) | ||
missing = { | ||
missing: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": {}, | ||
|
@@ -28,14 +33,14 @@ def test_good_comparator_neither_side_existing(): | |
def test_bad_comparator_only_one_side_existing(): | ||
cmp = DateUpdatedComparator("my_date_field") | ||
id = InstanceID("test", 1) | ||
present = { | ||
present: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"my_date_field": "2023-06-22T23:12:34.567Z", | ||
}, | ||
} | ||
missing = { | ||
missing: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": {}, | ||
|
@@ -60,14 +65,14 @@ def test_bad_comparator_only_one_side_existing(): | |
def test_good_date_updated_comparator(): | ||
cmp = DateUpdatedComparator("my_date_field") | ||
id = InstanceID("test", 1) | ||
left = { | ||
left: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"my_date_field": "2023-06-22T23:00:00.123Z", | ||
}, | ||
} | ||
right = { | ||
right: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
|
@@ -80,14 +85,14 @@ def test_good_date_updated_comparator(): | |
def test_bad_date_updated_comparator(): | ||
cmp = DateUpdatedComparator("my_date_field") | ||
id = InstanceID("test", 1) | ||
left = { | ||
left: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"my_date_field": "2023-06-22T23:12:34.567Z", | ||
}, | ||
} | ||
right = { | ||
right: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
|
@@ -99,3 +104,101 @@ def test_bad_date_updated_comparator(): | |
assert res[0] | ||
assert res[0].on == id | ||
assert res[0].kind == "DateUpdatedComparator" | ||
|
||
|
||
def test_good_email_obfuscating_comparator(): | ||
cmp = EmailObfuscatingComparator("one_email", "many_emails") | ||
id = InstanceID("test", 1) | ||
model = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"one_email": "[email protected]", | ||
"many_emails": [ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
}, | ||
} | ||
assert not cmp.compare(id, model, model) | ||
|
||
|
||
def test_bad_email_obfuscating_comparator(): | ||
cmp = EmailObfuscatingComparator("one_email", "many_emails") | ||
id = InstanceID("test", 1) | ||
left: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"one_email": "[email protected]", | ||
"many_emails": [ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
}, | ||
} | ||
right: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"one_email": "[email protected]", | ||
"many_emails": [ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
}, | ||
} | ||
res = cmp.compare(id, left, right) | ||
assert res | ||
|
||
assert res[0] | ||
assert res[0].on == id | ||
assert res[0].kind == "EmailObfuscatingComparator" | ||
assert "[email protected]" in res[0].reason | ||
assert "[email protected]" in res[0].reason | ||
|
||
assert res[1] | ||
assert res[1].on == id | ||
assert res[1].kind == "EmailObfuscatingComparator" | ||
assert "[email protected]" in res[1].reason | ||
assert "[email protected]" in res[1].reason | ||
|
||
|
||
def test_goo_email_obfuscating_comparator_scrubbed(): | ||
cmp = EmailObfuscatingComparator("one_email", "many_emails") | ||
left: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"one_email": "[email protected]", | ||
"many_emails": [ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
}, | ||
} | ||
right: JSONData = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"one_email": "[email protected]", | ||
"many_emails": [ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
}, | ||
} | ||
cmp.scrub(left, right) | ||
assert left["scrubbed"] | ||
assert left["scrubbed"]["EmailObfuscatingComparator::one_email"] == ["[email protected]"] | ||
assert left["scrubbed"]["EmailObfuscatingComparator::many_emails"] == [ | ||
"[email protected]", | ||
"[email protected]", | ||
] | ||
|
||
assert right["scrubbed"] | ||
assert right["scrubbed"]["EmailObfuscatingComparator::one_email"] == ["[email protected]"] | ||
assert right["scrubbed"]["EmailObfuscatingComparator::many_emails"] == [ | ||
"[email protected]", | ||
"[email protected]", | ||
] |