Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

lint: Harden various checks for URLs.

Tim Abbottcb1321d0d2cb
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index 077a7b7b4de..6a1b22ac3ba 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -407,7 +407,7 @@ def apply_event(state: Dict[str, Any],
if event['op'] == "add":
person = copy.deepcopy(person)
if client_gravatar:
- if 'gravatar.com' in person['avatar_url']:
+ if person['avatar_url'].startswith("https://secure.gravatar.com"):
person['avatar_url'] = None
person['is_active'] = True
if not person['is_bot']:
@@ -467,7 +467,7 @@ def apply_event(state: Dict[str, Any],
if client_gravatar and 'avatar_url' in person:
# Respect the client_gravatar setting in the `users` data.
- if 'gravatar.com' in person['avatar_url']:
+ if person['avatar_url'].startswith("https://secure.gravatar.com"):
person['avatar_url'] = None
person['avatar_url_medium'] = None
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index 11007b01c4c..65f4282e3ff 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -2339,7 +2339,7 @@ class GitHubAuthBackendTest(SocialAuthBase):
all_emails_verified = True
for email_data_dict in self.email_data:
email = email_data_dict["email"]
- if email.endswith("noreply.github.com"):
+ if email.endswith("@users.noreply.github.com"):
self.assert_not_in_success_response([email], result)
elif email_data_dict.get('verified'):
self.assert_in_success_response([email], result)
diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py
index f711d576cf9..e08238f3d05 100644
--- a/zerver/tests/test_bugdown.py
+++ b/zerver/tests/test_bugdown.py
@@ -982,11 +982,11 @@ class BugdownTest(ZulipTestCase):
converted = bugdown.convert(content, message_realm=realm, message=msg)
converted_topic = bugdown.topic_links(realm.id, content)
if convert:
- self.assertTrue('trac.example.com' in converted)
+ self.assertTrue('https://trac.example.com' in converted)
self.assertEqual(len(converted_topic), 1)
- self.assertTrue('trac.example.com' in converted_topic[0])
+ self.assertTrue('https://trac.example.com' in converted_topic[0])
else:
- self.assertTrue('trac.example.com' not in converted)
+ self.assertTrue('https://trac.example.com' not in converted)
self.assertEqual(len(converted_topic), 0)
assert_conversion('Hello #123 World')
assert_conversion('Hello #123World', False)
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 1287cd1509f..6986e223d57 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -467,7 +467,7 @@ class GetEventsTest(ZulipTestCase):
message = get_message(apply_markdown=False, client_gravatar=False)
self.assertEqual(message["display_recipient"], "Denmark")
self.assertEqual(message["content"], "**hello**")
- self.assertIn('gravatar.com', message["avatar_url"])
+ self.assertTrue(message["avatar_url"].startswith("https://secure.gravatar.com"))
message = get_message(apply_markdown=True, client_gravatar=False)
self.assertEqual(message["display_recipient"], "Denmark")
diff --git a/zproject/backends.py b/zproject/backends.py
index 77ee437257d..48bf0d1f2dd 100644
--- a/zproject/backends.py
+++ b/zproject/backends.py
@@ -1461,7 +1461,7 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2):
email_objs = self.get_all_associated_email_objects(*args, **kwargs)
return [
email for email in email_objs
- if not email["email"].endswith("noreply.github.com")
+ if not email["email"].endswith("@users.noreply.github.com")
]
def user_data(self, access_token: str, *args: Any, **kwargs: Any) -> Dict[str, str]: