auth: Remove unnecessary case from validate_email_for_realm.

The removed code path was only needed due to buggy setup code in the
test_cross_realm_scenarios test.  We address that with a less buggy
workaround, and which lets us remove unnecessary complexity from this
important validation function.

Thanks for Umair Waheed for some preliminary work on this.

Fixes #7561.
This commit is contained in:
Tim Abbott
2018-04-28 10:59:39 -07:00
parent 16873cd1ff
commit 127ac0df54
2 changed files with 6 additions and 11 deletions

View File

@@ -4092,16 +4092,7 @@ def email_not_system_bot(email: Text) -> None:
raise ValidationError('%s is an email address reserved for system bots' % (email,))
def validate_email_for_realm(target_realm: Realm, email: Text) -> None:
try:
# Registering with a system bot's email is not allowed...
email_not_system_bot(email)
except ValidationError:
# ... unless this is the first user with that email. This
# should be impossible in production, because these users are
# created by initialize_voyager_db, but it happens in a test's
# setup. (This would be a good wrinkle to clean up.)
if UserProfile.objects.filter(email__iexact=email).exists():
raise
email_not_system_bot(email)
try:
existing_user_profile = get_user(email, target_realm)

View File

@@ -266,7 +266,11 @@ class TestCrossRealmPMs(ZulipTestCase):
user2 = self.create_user(user2_email)
self.create_user(user3_email)
feedback_bot = get_system_bot(feedback_email)
support_bot = self.create_user(support_email)
with self.settings(CROSS_REALM_BOT_EMAILS=['feedback@zulip.com', 'welcome-bot@zulip.com']):
# HACK: We should probably be creating this "bot" user another
# way, but since you can't register a user with a
# cross-realm email, we need to hide this for now.
support_bot = self.create_user(support_email)
# Users can PM themselves
self.send_personal_message(user1_email, user1_email, sender_realm="1.example.com")