redact survey password type values w/ tests

This commit is contained in:
Chris Meyers
2015-02-18 07:32:57 -05:00
parent 50e174ea43
commit 1e871f8d7c
13 changed files with 553 additions and 239 deletions

View File

@@ -1,8 +1,10 @@
import re
import urlparse
REPLACE_STR = '$encrypted$'
class UriCleaner(object):
REPLACE_STR = '$encrypted$'
REPLACE_STR = REPLACE_STR
# https://regex101.com/r/sV2dO2/2
SENSITIVE_URI_PATTERN = re.compile(ur'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019]))', re.MULTILINE)
@@ -51,4 +53,9 @@ class UriCleaner(object):
return redactedtext
class PlainTextCleaner(object):
REPLACE_STR = REPLACE_STR
@staticmethod
def remove_sensitive(cleartext, sensitive):
return re.sub(r'%s' % re.escape(sensitive), '$encrypted$', cleartext)