Skip to content

Commit 681fae2

Browse files
test: decode email payloads before validating (ietf-tools#3926)
1 parent 8fc8e9a commit 681fae2

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

ietf/ipr/management/tests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ def test_send_error_to_admin(self, process_mock, send_smtp_mock):
4242
self.assertTrue(msg.is_multipart(), 'Error email should have attachments')
4343
parts = msg.get_payload()
4444
self.assertEqual(len(parts), 3, 'Error email should contain message, traceback, and original message')
45-
content = parts[0].get_payload()
46-
traceback = parts[1].get_payload()
47-
original = parts[2].get_payload(decode=True).decode() # convert octet-stream to string
45+
# decode=True decodes the quoted-printable encoding, including removing soft linebreaks.
46+
# The .decode() converts the resulting octet-stream bytes to a string
47+
content = parts[0].get_payload(decode=True).decode()
48+
traceback = parts[1].get_payload(decode=True).decode()
49+
original = parts[2].get_payload(decode=True).decode()
4850
self.assertIn('RuntimeError', content, 'Error type should be included in error email')
4951
self.assertIn('mock.py', content, 'File where error occurred should be included in error email')
5052
self.assertIn('traceback', traceback.lower(), 'Traceback should be attached to error email')

ietf/nomcom/management/tests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def test_send_error_to_admins(self, send_smtp_mock):
3535
self.assertEqual(msg['to'], 'admin@example.com', 'Email recipient should be the admins')
3636
self.assertIn('error', msg['subject'], 'Email subject should indicate error')
3737
self.assertFalse(msg.is_multipart(), 'Nomcom feedback error sent to admin should not have attachments')
38-
content = msg.get_payload()
38+
# decode=True decodes the quoted-printable encoding, including removing soft linebreaks.
39+
# The .decode() converts the resulting octet-stream bytes to a string
40+
content = msg.get_payload(decode=True).decode()
3941
self.assertIn('CommandError', content, 'Admin email should contain error type')
4042
self.assertIn('feedback_email.py', content, 'Admin email should contain file where error occurred')
4143
self.assertNotIn('traceback', content.lower(), 'Admin email should not contain traceback')
@@ -63,7 +65,8 @@ def test_send_error_to_chair(self, create_feedback_mock, send_smtp_mock):
6365
self.assertTrue(msg.is_multipart(), 'Chair feedback error should have attachments')
6466
parts = msg.get_payload()
6567
content = parts[0].get_payload()
66-
# decode=True decodes the base64 encoding, .decode() converts the octet-stream bytes to a string
68+
# decode=True decodes the quoted-printable encoding, including removing soft linebreaks.
69+
# The .decode() converts the resulting octet-stream bytes to a string
6770
attachment = parts[1].get_payload(decode=True).decode()
6871
self.assertIn('RuntimeError', content, 'Nomcom email should contain error type')
6972
self.assertIn('mock.py', content, 'Nomcom email should contain file where error occurred')

0 commit comments

Comments
 (0)