mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
improve email masking
This commit is contained in:
@@ -138,7 +138,9 @@ class PIIFilter(logging.Filter):
|
|||||||
) # ['alice@google.com', 'bob@abc.com']
|
) # ['alice@google.com', 'bob@abc.com']
|
||||||
for email in emails:
|
for email in emails:
|
||||||
# do something with each found email string
|
# do something with each found email string
|
||||||
msg = msg.replace(email, f"XXXXX{email[-10:]}")
|
email_parts = email.split("@")
|
||||||
|
masked_email = f"{email_parts[0][0:3]}XXX@{email_parts[1][0:7]}XXX"
|
||||||
|
msg = msg.replace(email, masked_email)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def filter(self, record):
|
def filter(self, record):
|
||||||
|
|||||||
@@ -62,5 +62,5 @@ def test_pii_filter():
|
|||||||
args=None,
|
args=None,
|
||||||
)
|
)
|
||||||
pii_filter = logging.PIIFilter()
|
pii_filter = logging.PIIFilter()
|
||||||
clean_msg = "phone1: 1XXXXX55555, phone2: 1XXXXX55554, email1: XXXXXe@fake.gov, email2: XXXXX2.fake.gov"
|
clean_msg = "phone1: 1XXXXX55555, phone2: 1XXXXX55554, email1: fakXXX@fake.goXXX, email2: fakXXX@fake2.fXXX"
|
||||||
assert pii_filter.filter(record).msg == clean_msg
|
assert pii_filter.filter(record).msg == clean_msg
|
||||||
|
|||||||
Reference in New Issue
Block a user