[3.13] gh-130637: Add validation for numeric response data in stat() method (GH-130646) (#130763)

gh-130637: Add validation for numeric response data in `stat()` method (GH-130646)
(cherry picked from commit a42168d316)

Co-authored-by: Kanishk Pachauri <itskanishkp.py@gmail.com>
Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-03-02 21:28:56 +01:00 committed by GitHub
parent 3bef4af301
commit e6dfa9d601
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 2 deletions

View file

@ -289,6 +289,37 @@ class TestPOP3Class(TestCase):
def test_stat(self):
self.assertEqual(self.client.stat(), (10, 100))
original_shortcmd = self.client._shortcmd
def mock_shortcmd_invalid_format(cmd):
if cmd == 'STAT':
return b'+OK'
return original_shortcmd(cmd)
self.client._shortcmd = mock_shortcmd_invalid_format
with self.assertRaises(poplib.error_proto):
self.client.stat()
def mock_shortcmd_invalid_data(cmd):
if cmd == 'STAT':
return b'+OK abc def'
return original_shortcmd(cmd)
self.client._shortcmd = mock_shortcmd_invalid_data
with self.assertRaises(poplib.error_proto):
self.client.stat()
def mock_shortcmd_extra_fields(cmd):
if cmd == 'STAT':
return b'+OK 1 2 3 4 5'
return original_shortcmd(cmd)
self.client._shortcmd = mock_shortcmd_extra_fields
result = self.client.stat()
self.assertEqual(result, (1, 2))
self.client._shortcmd = original_shortcmd
def test_list(self):
self.assertEqual(self.client.list()[1:],
([b'1 1', b'2 2', b'3 3', b'4 4', b'5 5'],