Skip to content

Commit 99aab1b

Browse files
authored
PYTHON-3017 Properly check for closed KMS connections (#790)
1 parent a655c57 commit 99aab1b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pymongo/encryption.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ def kms_request(self, kms_context):
129129
conn.sendall(message)
130130
while kms_context.bytes_needed > 0:
131131
data = conn.recv(kms_context.bytes_needed)
132+
if not data:
133+
raise OSError('KMS connection closed')
132134
kms_context.feed(data)
133135
finally:
134136
conn.close()

test/test_encryption.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,9 +1775,6 @@ def test_invalid_hostname_in_kms_certificate(self):
17751775
class TestKmsTLSOptions(EncryptionIntegrationTest):
17761776
@unittest.skipUnless(any(AWS_CREDS.values()),
17771777
'AWS environment credentials are not set')
1778-
@unittest.skipIf(sys.version_info[:2] >= (3, 10) and
1779-
sys.platform == 'win32',
1780-
'These tests hang with Python 3.10 on Windows')
17811778
def setUp(self):
17821779
super(TestKmsTLSOptions, self).setUp()
17831780
# 1, create client with only tlsCAFile.
@@ -1822,15 +1819,16 @@ def setUp(self):
18221819
self.addCleanup(self.client_encryption_invalid_hostname.close)
18231820
# Errors when client has no cert, some examples:
18241821
# [SSL: TLSV13_ALERT_CERTIFICATE_REQUIRED] tlsv13 alert certificate required (_ssl.c:2623)
1825-
self.cert_error = 'certificate required|SSL handshake failed'
1822+
self.cert_error = ('certificate required|SSL handshake failed|'
1823+
'KMS connection closed')
18261824
# On Windows this error might be:
18271825
# [WinError 10054] An existing connection was forcibly closed by the remote host
18281826
if sys.platform == 'win32':
18291827
self.cert_error += '|forcibly closed'
18301828
# On Windows Python 3.10+ this error might be:
18311829
# EOF occurred in violation of protocol (_ssl.c:2384)
18321830
if sys.version_info[:2] >= (3, 10):
1833-
self.cert_error += '|forcibly closed'
1831+
self.cert_error += '|EOF'
18341832

18351833
def test_01_aws(self):
18361834
key = {

0 commit comments

Comments
 (0)