@@ -1213,6 +1213,8 @@ def get_server_settings(cls):
1213
1213
'ssl_cert_file' : SSL_CERT_FILE ,
1214
1214
'ssl_key_file' : SSL_KEY_FILE ,
1215
1215
'ssl_ca_file' : CLIENT_CA_CERT_FILE ,
1216
+ 'ssl_min_protocol_version' : 'TLSv1.2' ,
1217
+ 'ssl_max_protocol_version' : 'TLSv1.2' ,
1216
1218
})
1217
1219
1218
1220
return conf
@@ -1408,6 +1410,42 @@ async def test_executemany_uvloop_ssl_issue_700(self):
1408
1410
finally :
1409
1411
await con .close ()
1410
1412
1413
+ async def test_tls_version (self ):
1414
+ # XXX: uvloop artifact
1415
+ old_handler = self .loop .get_exception_handler ()
1416
+ try :
1417
+ self .loop .set_exception_handler (lambda * args : None )
1418
+ with self .assertRaisesRegex (ssl .SSLError , 'protocol version' ):
1419
+ await self .connect (
1420
+ dsn = 'postgresql://ssl_user@localhost/postgres'
1421
+ '?sslmode=require&ssl_min_protocol_version=TLSv1.3'
1422
+ )
1423
+ with self .assertRaisesRegex (ssl .SSLError , 'protocol version' ):
1424
+ await self .connect (
1425
+ dsn = 'postgresql://ssl_user@localhost/postgres'
1426
+ '?sslmode=require'
1427
+ '&ssl_min_protocol_version=TLSv1.1'
1428
+ '&ssl_max_protocol_version=TLSv1.1'
1429
+ )
1430
+ with self .assertRaisesRegex (ssl .SSLError , 'no protocols' ):
1431
+ await self .connect (
1432
+ dsn = 'postgresql://ssl_user@localhost/postgres'
1433
+ '?sslmode=require'
1434
+ '&ssl_min_protocol_version=TLSv1.2'
1435
+ '&ssl_max_protocol_version=TLSv1.1'
1436
+ )
1437
+ con = await self .connect (
1438
+ dsn = 'postgresql://ssl_user@localhost/postgres?sslmode=require'
1439
+ '&ssl_min_protocol_version=TLSv1.2'
1440
+ '&ssl_max_protocol_version=TLSv1.2'
1441
+ )
1442
+ try :
1443
+ self .assertEqual (await con .fetchval ('SELECT 42' ), 42 )
1444
+ finally :
1445
+ await con .close ()
1446
+ finally :
1447
+ self .loop .set_exception_handler (old_handler )
1448
+
1411
1449
1412
1450
@unittest .skipIf (os .environ .get ('PGHOST' ), 'unmanaged cluster' )
1413
1451
class TestClientSSLConnection (BaseTestSSLConnection ):
0 commit comments