Skip to content

Commit

Permalink
[2.7] bpo-34391: Fix ftplib test for TLS 1.3 (GH-8787) (GH-8791)
Browse files Browse the repository at this point in the history
Read from data socket to avoid "[SSL] shutdown while in init" exception
during shutdown of the dummy server.

Signed-off-by: Christian Heimes <christian@python.org>

<!-- issue-number: [bpo-34391](https://www.bugs.python.org/issue34391) -->
https://bugs.python.org/issue34391
<!-- /issue-number -->.
(cherry picked from commit 1590c39)

Co-authored-by: Christian Heimes <christian@python.org>
  • Loading branch information
tiran committed Aug 16, 2018
1 parent 00aebab commit 2ec530c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Lib/test/test_ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,20 +675,25 @@ def test_data_connection(self):
# clear text
sock = self.client.transfercmd('list')
self.assertNotIsInstance(sock, ssl.SSLSocket)
self.assertEqual(sock.recv(1024), LIST_DATA.encode('ascii'))
sock.close()
self.assertEqual(self.client.voidresp(), "226 transfer complete")

# secured, after PROT P
self.client.prot_p()
sock = self.client.transfercmd('list')
self.assertIsInstance(sock, ssl.SSLSocket)
# consume from SSL socket to finalize handshake and avoid
# "SSLError [SSL] shutdown while in init"
self.assertEqual(sock.recv(1024), LIST_DATA.encode('ascii'))
sock.close()
self.assertEqual(self.client.voidresp(), "226 transfer complete")

# PROT C is issued, the connection must be in cleartext again
self.client.prot_c()
sock = self.client.transfercmd('list')
self.assertNotIsInstance(sock, ssl.SSLSocket)
self.assertEqual(sock.recv(1024), LIST_DATA.encode('ascii'))
sock.close()
self.assertEqual(self.client.voidresp(), "226 transfer complete")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ftplib test for TLS 1.3 by reading from data socket.

0 comments on commit 2ec530c

Please sign in to comment.