Skip to content

Commit 494fe29

Browse files
sharmagotroot
andauthored
Added test case to verify TLS 1.3 auto-negotiation support (#575)
Co-authored-by: root <[email protected]>
1 parent 899c9b7 commit 494fe29

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

vertica_python/tests/integration_tests/test_tls.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,59 @@ def test_sslcontext_verify_full(self):
298298
res = self._query_and_fetchone(self.SSL_STATE_SQL)
299299
self.assertEqual(res[0], 'Server')
300300

301+
def _get_tls_version(self, conn):
302+
sock = getattr(conn, '_socket', None)
303+
if not sock:
304+
return None
305+
306+
if hasattr(sock, 'version') and callable(sock.version):
307+
return sock.version()
308+
309+
ssl_obj = getattr(sock, '_sslobj', None)
310+
if ssl_obj and hasattr(ssl_obj, 'version'):
311+
return ssl_obj.version()
312+
313+
return None
314+
315+
def test_tls13_support_auto_negotiation(self):
316+
"""
317+
Verify that the client supports TLS 1.3 negotiation.
318+
If the server supports TLS 1.3, the connection should establish using it.
319+
If the server supports only TLS 1.2, the connection should still succeed.
320+
"""
321+
322+
# Set up server certificates and enable TLS
323+
try:
324+
CA_cert = self._generate_and_set_certificates()
325+
except Exception:
326+
self.skipTest("Failed to generate CA certificates; skipping TLS test")
327+
328+
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
329+
ssl_context.verify_mode = ssl.CERT_REQUIRED
330+
ssl_context.check_hostname = True
331+
ssl_context.load_verify_locations(cadata=CA_cert)
332+
333+
self._conn_info['ssl'] = ssl_context
334+
self._conn_info['tlsmode'] = 'require'
335+
336+
with self._connect() as conn:
337+
# First ensure TLS really got enabled on server
338+
res = self._query_and_fetchone(self.SSL_STATE_SQL)
339+
if res[0] != 'Server':
340+
self.skipTest("TLS is not configured on server")
341+
342+
# Prefer public API, fall back only if needed
343+
tls_version = self._get_tls_version(conn)
344+
345+
if tls_version is None:
346+
self.skipTest("Could not determine negotiated TLS version.")
347+
348+
self.assertIn(
349+
tls_version,
350+
("TLSv1.2", "TLSv1.3"),
351+
msg=f"Unexpected TLS version negotiated: {tls_version}"
352+
)
353+
301354
def test_sslcontext_mutual_TLS(self):
302355
# Setting certificates with TLS configuration
303356
CA_cert = self._generate_and_set_certificates(mutual_mode=True)

0 commit comments

Comments
 (0)