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.

zephyr: Fix compute_mit_user_fullname for py3dns returning bytes.

Anders Kaseorg498c6c485ebf
diff --git a/zerver/lib/zephyr.py b/zerver/lib/zephyr.py
index 20a73a48574..f983317916e 100644
--- a/zerver/lib/zephyr.py
+++ b/zerver/lib/zephyr.py
@@ -10,7 +10,7 @@ def compute_mit_user_fullname(email: str) -> str:
match_user = re.match(r"^([a-zA-Z0-9_.-]+)(\|.+)?@mit\.edu$", email.lower())
if match_user and match_user.group(2) is None:
answer = DNS.dnslookup(f"{match_user.group(1)}.passwd.ns.athena.mit.edu", DNS.Type.TXT)
- hesiod_name = answer[0][0].split(":")[4].split(",")[0].strip()
+ hesiod_name = answer[0][0].decode().split(":")[4].split(",")[0].strip()
if hesiod_name != "":
return hesiod_name
elif match_user:
diff --git a/zerver/tests/test_external.py b/zerver/tests/test_external.py
index d0a94c8ed21..47a8bcac163 100644
--- a/zerver/tests/test_external.py
+++ b/zerver/tests/test_external.py
@@ -39,7 +39,7 @@ class MITNameTest(ZulipTestCase):
with mock.patch(
"DNS.dnslookup",
return_value=[
- ["starnine:*:84233:101:Athena Consulting Exchange User,,,:/mit/starnine:/bin/bash"]
+ [b"starnine:*:84233:101:Athena Consulting Exchange User,,,:/mit/starnine:/bin/bash"]
],
):
self.assertEqual(
@@ -48,7 +48,7 @@ class MITNameTest(ZulipTestCase):
)
with mock.patch(
"DNS.dnslookup",
- return_value=[["sipbexch:*:87824:101:Exch Sipb,,,:/mit/sipbexch:/bin/athena/bash"]],
+ return_value=[[b"sipbexch:*:87824:101:Exch Sipb,,,:/mit/sipbexch:/bin/athena/bash"]],
):
self.assertEqual(compute_mit_user_fullname("[email protected]"), "Exch Sipb")
@@ -73,7 +73,7 @@ class MITNameTest(ZulipTestCase):
self.assertRaises(ValidationError, email_is_not_mit_mailing_list, "[email protected]")
def test_notmailinglist(self) -> None:
- with mock.patch("DNS.dnslookup", return_value=[["POP IMAP.EXCHANGE.MIT.EDU starnine"]]):
+ with mock.patch("DNS.dnslookup", return_value=[[b"POP IMAP.EXCHANGE.MIT.EDU starnine"]]):
email_is_not_mit_mailing_list("[email protected]")
diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py
index 507632bac91..f12dc78031d 100644
--- a/zerver/tests/test_message_send.py
+++ b/zerver/tests/test_message_send.py
@@ -1054,7 +1054,7 @@ class MessagePOSTTest(ZulipTestCase):
with mock.patch(
"DNS.dnslookup",
return_value=[
- ["starnine:*:84233:101:Athena Consulting Exchange User,,,:/mit/starnine:/bin/bash"]
+ [b"starnine:*:84233:101:Athena Consulting Exchange User,,,:/mit/starnine:/bin/bash"]
],
):
result1 = self.api_post(
@@ -1064,7 +1064,7 @@ class MessagePOSTTest(ZulipTestCase):
with mock.patch(
"DNS.dnslookup",
- return_value=[["espuser:*:95494:101:Esp Classroom,,,:/mit/espuser:/bin/athena/bash"]],
+ return_value=[[b"espuser:*:95494:101:Esp Classroom,,,:/mit/espuser:/bin/athena/bash"]],
):
result2 = self.api_post(
self.mit_user("espuser"), "/api/v1/messages", msg, subdomain="zephyr"
diff --git a/zerver/tests/test_mirror_users.py b/zerver/tests/test_mirror_users.py
index 3e25dc120ca..0b468dee927 100644
--- a/zerver/tests/test_mirror_users.py
+++ b/zerver/tests/test_mirror_users.py
@@ -50,7 +50,7 @@ class MirroredMessageUsersTest(ZulipTestCase):
@mock.patch(
"DNS.dnslookup",
- return_value=[["sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh"]],
+ return_value=[[b"sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh"]],
)
def test_zephyr_mirror_new_recipient(self, ignored: object) -> None:
"""Test mirror dummy user creation for direct message recipients"""
@@ -80,7 +80,7 @@ class MirroredMessageUsersTest(ZulipTestCase):
@mock.patch(
"DNS.dnslookup",
- return_value=[["sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh"]],
+ return_value=[[b"sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh"]],
)
def test_zephyr_mirror_new_sender(self, ignored: object) -> None:
"""Test mirror dummy user creation for sender when sending to stream"""
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py
index 538718f293d..14dd8eada53 100644
--- a/zerver/tests/test_signup.py
+++ b/zerver/tests/test_signup.py
@@ -4136,7 +4136,7 @@ class UserSignUpTest(ZulipTestCase):
@patch(
"DNS.dnslookup",
- return_value=[["sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh"]],
+ return_value=[[b"sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh"]],
)
def test_registration_of_mirror_dummy_user(self, ignored: Any) -> None:
password = "test"
@@ -4217,7 +4217,7 @@ class UserSignUpTest(ZulipTestCase):
@patch(
"DNS.dnslookup",
- return_value=[["sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh"]],
+ return_value=[[b"sipbtest:*:20922:101:Fred Sipb,,,:/mit/sipbtest:/bin/athena/tcsh"]],
)
def test_registration_of_active_mirror_dummy_user(self, ignored: Any) -> None:
"""