diff --git a/changelog.d/324.feature b/changelog.d/324.feature new file mode 100644 index 00000000..9cf166c8 --- /dev/null +++ b/changelog.d/324.feature @@ -0,0 +1 @@ +Switch out triple-period sequences in third-party invites for an ellipsis character. \ No newline at end of file diff --git a/sydent/http/servlets/store_invite_servlet.py b/sydent/http/servlets/store_invite_servlet.py index 66dfe4aa..471e4497 100644 --- a/sydent/http/servlets/store_invite_servlet.py +++ b/sydent/http/servlets/store_invite_servlet.py @@ -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. @@ -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): """ diff --git a/tests/test_invites.py b/tests/test_invites.py index a66c50a7..ff365ee4 100644 --- a/tests/test_invites.py +++ b/tests/test_invites.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from mock import Mock from sydent.http.httpclient import FederationHttpClient from sydent.db.invite_tokens import JoinTokenStore @@ -83,35 +85,35 @@ def test_invited_email_address_obfuscation(self): email_address = "1234567890@1234567890.com" 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 = "1@1.com" redacted_address = store_invite_servlet.redact_email_address(short_email_address) - self.assertEqual(redacted_address, "1@1.com") + self.assertEqual(redacted_address, u"1@1.com") # 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 = "johnathon-jingle-smithington@john-smith.notarealtld" 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 = "applejack-@someexample.com" 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 = "-@someexample.com" 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 @@ -119,7 +121,7 @@ def test_invited_email_address_obfuscation(self): email_address = "donuld--fauntleboy--puck@disnie.com" 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.""" @@ -146,7 +148,7 @@ def test_invited_email_address_obfuscation_fallback_config(self): email_address = "1234567890@1234567890.com" 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):