-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config options for how much to obfuscate email addresses in 3rd p…
…arty invites (#311) When inviting a user via their email address using Sydent, a third party invite event is injected into the room using an obfuscated version of the invitee's email address (to prevent This PR adds two new config options to sydent: * `email.third_party_invite_username_obfuscate_characters` - for obfuscating the text before the `@` sign * `email.third_party_invite_domain_obfuscate_characters - for obfuscating the text after the `@` sign Instead of only truncating the string, I decided to keep the old behaviour of redacting based on string length (only if the string's length is <= the configured threshold). The old behaviour ensured that a full email address is never shown, even if it is very short (e.g. [email protected]), which is a property I believe we want to uphold.
- Loading branch information
1 parent
611d836
commit 2f0d4bb
Showing
4 changed files
with
85 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add config options for controlling how email addresses are obfuscated in third party invites. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,22 @@ | |
from tests.utils import make_sydent | ||
from twisted.web.client import Response | ||
from twisted.trial import unittest | ||
from sydent.http.servlets.store_invite_servlet import StoreInviteServlet | ||
|
||
|
||
class ThreepidInvitesTestCase(unittest.TestCase): | ||
"""Tests features related to storing and delivering 3PID invites.""" | ||
|
||
def setUp(self): | ||
# Create a new sydent | ||
self.sydent = make_sydent() | ||
config = { | ||
"email": { | ||
# Used by test_invited_email_address_obfuscation | ||
"email.third_party_invite_username_obfuscate_characters": "6", | ||
"email.third_party_invite_domain_obfuscate_characters": "8", | ||
}, | ||
} | ||
self.sydent = make_sydent(test_config=config) | ||
|
||
def test_delete_on_bind(self): | ||
"""Tests that 3PID invite tokens are deleted upon delivery after a successful | ||
|
@@ -65,6 +73,23 @@ def post_json_get_nothing(uri, post_json, opts): | |
# Check that we didn't get any result. | ||
self.assertEqual(len(rows), 0, rows) | ||
|
||
def test_invited_email_address_obfuscation(self): | ||
"""Test that email addresses included in third-party invites are properly | ||
obfuscated according to the relevant config options | ||
""" | ||
store_invite_servlet = StoreInviteServlet(self.sydent) | ||
|
||
email_address = "[email protected]" | ||
redacted_address = store_invite_servlet.redact_email_address(email_address) | ||
|
||
self.assertEqual(redacted_address, "123456...@12345678...") | ||
|
||
# Even short addresses are redacted | ||
short_email_address = "[email protected]" | ||
redacted_address = store_invite_servlet.redact_email_address(short_email_address) | ||
|
||
self.assertEqual(redacted_address, "...@1...") | ||
|
||
|
||
class ThreepidInvitesNoDeleteTestCase(unittest.TestCase): | ||
"""Test that invite tokens are not deleted when that is disabled. | ||
|