Skip to content

Use a guaranteed invalid email in sanitize_email #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion database_sanitizer/sanitizers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def sanitize_email(value):
given_name = given_names[num1 % given_names_count]
surname = surnames[num2 % surnames_count]
case_convert = (text_type.lower if num3 % 8 > 0 else lambda x: x)
return '{first}.{last}@x{num:x}.sanitized.net'.format(
return '{first}.{last}@x{num:x}.san.example.com'.format(
first=case_convert(given_name),
last=case_convert(surname).replace("'", ''),
num=num3)
Expand Down
28 changes: 14 additions & 14 deletions database_sanitizer/tests/test_sanitizers_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ def setup_module():
def test_sanitize_email():
assert user.sanitize_email(None) is None
assert user.sanitize_email('') == ''
assert user.sanitize_email('test@example.com') == (
'[email protected]')
assert user.sanitize_email('test2@example.com') == (
'Melanie.Pratt@x4feb7f40.sanitized.net')
assert user.sanitize_email('test@example.com') == (
'[email protected]')
assert user.sanitize_email('test3@example.com') == (
'irene.archer@x3d2e92ec.sanitized.net')
assert user.sanitize_email(' test3@example.com ') == (
'irene.archer@x3d2e92ec.sanitized.net')
assert user.sanitize_email('test@example.net') == (
'[email protected]')
assert user.sanitize_email('test2@example.net') == (
'Melanie.Pratt@x4feb7f40.san.example.com')
assert user.sanitize_email('test@example.net') == (
'[email protected]')
assert user.sanitize_email('test3@example.net') == (
'irene.archer@x3d2e92ec.san.example.com')
assert user.sanitize_email(' test3@example.net ') == (
'irene.archer@x3d2e92ec.san.example.com')


def test_sanitize_username():
Expand Down Expand Up @@ -59,9 +59,9 @@ def test_sanitize_surname_en_gb():


def test_sanitize_email_resets_on_session_reset():
assert user.sanitize_email('test@example.com') == (
'zoe.burke@xce13103b.sanitized.net')
assert user.sanitize_email('test@example.net') == (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't change the source address and expect it to sanitize to same value. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.. we had the random hash there. 👍 Will check what it gave and update the expected value. I think having different source domain helps to understand the functionality easier.

'zoe.burke@xce13103b.san.example.com')
session.reset()
assert user.sanitize_email('test@example.com') != (
'zoe.burke@xce13103b.sanitized.net')
assert user.sanitize_email('test@example.net') != (
'zoe.burke@xce13103b.san.example.com')
session.reset(b'not-so-secret-key')