Skip to content
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

Change out the triple-dot sequence in third-party invites to an ellipsis character #324

Merged
merged 6 commits into from
Dec 1, 2020
Merged
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
1 change: 1 addition & 0 deletions changelog.d/324.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch out triple-period sequences in third-party invites for an ellipsis character.
10 changes: 5 additions & 5 deletions sydent/http/servlets/store_invite_servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _redact(self, s, characters_to_reveal):
:type s: unicode

:param characters_to_reveal: How many characters of the string to leave before
the '...'
the ellipsis
:type characters_to_reveal: int

:return: The redacted string.
Expand All @@ -191,16 +191,16 @@ def _redact(self, s, characters_to_reveal):
# redact based on size instead. This ensures that at least *some*
# part of the string is obfuscated, regardless of its total length.
if len(s) > 5:
return s[:3] + u"..."
return s[:3] + u""
if len(s) > 1:
return s[0] + u"..."
return u"..."
return s[0] + u""
return u""

# Otherwise just return the original string.
return s

# Truncate to the configured length and add an ellipses.
return s[:characters_to_reveal] + u"..."
return s[:characters_to_reveal] + u""

def _randomString(self, length):
"""
Expand Down
18 changes: 10 additions & 8 deletions tests/test_invites.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from mock import Mock
from sydent.http.httpclient import FederationHttpClient
from sydent.db.invite_tokens import JoinTokenStore
Expand Down Expand Up @@ -83,43 +85,43 @@ def test_invited_email_address_obfuscation(self):
email_address = "[email protected]"
redacted_address = store_invite_servlet.redact_email_address(email_address)

self.assertEqual(redacted_address, "123456...@12345678...")
self.assertEqual(redacted_address, u"123456@12345678")

# Addresses that are shorter than the configured reveal length are not redacted if
# always_obfuscate is false
short_email_address = "[email protected]"
redacted_address = store_invite_servlet.redact_email_address(short_email_address)
self.assertEqual(redacted_address, "[email protected]")
self.assertEqual(redacted_address, u"[email protected]")

# Set always_obfuscate to true
self.sydent.always_obfuscate = True
redacted_address = store_invite_servlet.redact_email_address(short_email_address)
self.assertEqual(redacted_address, "...@1...")
self.assertEqual(redacted_address, u"…@1…")

# Try using a username separator string
self.sydent.third_party_invite_username_separator_string = "-"
email_address = "[email protected]"
redacted_address = store_invite_servlet.redact_email_address(email_address)
# Each individual component of the username should be obfuscated, but not the domain
self.assertEqual(redacted_address, "johnat...-jin...-smithi...@john-smi...")
self.assertEqual(redacted_address, u"johnat-jin-smithi@john-smi")

# Try one with a separator at a word boundary
email_address = "[email protected]"
redacted_address = store_invite_servlet.redact_email_address(email_address)
self.assertEqual(redacted_address, "applej...-@someexam...")
self.assertEqual(redacted_address, u"applej-@someexam")

# Try one where the username is just the separator.
email_address = "[email protected]"
redacted_address = store_invite_servlet.redact_email_address(email_address)
self.assertEqual(redacted_address, "-@someexam...")
self.assertEqual(redacted_address, u"-@someexam")

# Try multiple, sequential separators
self.sydent.username_reveal_characters = 3
self.sydent.domain_reveal_characters = 3

email_address = "[email protected]"
redacted_address = store_invite_servlet.redact_email_address(email_address)
self.assertEqual(redacted_address, "don...--fau...--puc...@dis...")
self.assertEqual(redacted_address, u"don--fau--puc@dis")

class ThreepidInvitesFallbackConfigTestCase(unittest.TestCase):
"""Tests that any fallback config options work."""
Expand All @@ -146,7 +148,7 @@ def test_invited_email_address_obfuscation_fallback_config(self):
email_address = "[email protected]"
redacted_address = store_invite_servlet.redact_email_address(email_address)

self.assertEqual(redacted_address, "123456789...@1234...")
self.assertEqual(redacted_address, u"123456789@1234")


class ThreepidInvitesNoDeleteTestCase(unittest.TestCase):
Expand Down