@@ -788,6 +788,16 @@ def test_set_verify_depth_wrong_args(self):
788
788
with pytest .raises (TypeError ):
789
789
context .set_verify_depth (None )
790
790
791
+ def test_connection_set_verify_depth_wrong_args (self ):
792
+ """
793
+ `Connection.set_verify_depth` raises `TypeError` if called with a
794
+ non-`int` argument.
795
+ """
796
+ context = Context (TLSv1_METHOD )
797
+ connection = Connection (context , None )
798
+ with pytest .raises (TypeError ):
799
+ connection .set_verify_depth (None )
800
+
791
801
def test_verify_depth (self ):
792
802
"""
793
803
`Context.set_verify_depth` sets the number of certificates in
@@ -798,6 +808,17 @@ def test_verify_depth(self):
798
808
context .set_verify_depth (11 )
799
809
assert context .get_verify_depth () == 11
800
810
811
+ def test_connection_verify_depth (self ):
812
+ """
813
+ `Connection.set_verify_depth` sets the number of certificates in
814
+ a chain to follow before giving up. The value can be retrieved with
815
+ `Connection.get_verify_depth`.
816
+ """
817
+ context = Context (TLSv1_METHOD )
818
+ connection = Connection (context , None )
819
+ connection .set_verify_depth (11 )
820
+ assert connection .get_verify_depth () == 11
821
+
801
822
def _write_encrypted_pem (self , passphrase , tmpfile ):
802
823
"""
803
824
Write a new private key out to a new file, encrypted using the given
@@ -1285,6 +1306,50 @@ def verify_callback(*args):
1285
1306
1286
1307
assert "silly verify failure" == str (exc .value )
1287
1308
1309
+ def test_set_verify_callback_in_connection_object (self ):
1310
+ """
1311
+ The first argument passed to the verify callback is the
1312
+ `Connection` instance for which verification is taking place.
1313
+ """
1314
+ serverContext = Context (TLSv1_METHOD )
1315
+ serverContext .use_privatekey (
1316
+ load_privatekey (FILETYPE_PEM , cleartextPrivateKeyPEM ))
1317
+ serverContext .use_certificate (
1318
+ load_certificate (FILETYPE_PEM , cleartextCertificatePEM ))
1319
+ serverConnection = Connection (serverContext , None )
1320
+
1321
+ class VerifyCallback (object ):
1322
+ def callback (self , connection , * args ):
1323
+ self .connection = connection
1324
+ return 1
1325
+
1326
+ verify = VerifyCallback ()
1327
+ clientContext = Context (TLSv1_METHOD )
1328
+ clientConnection = Connection (clientContext , None )
1329
+ clientConnection .set_verify (VERIFY_PEER , verify .callback )
1330
+ clientConnection .set_connect_state ()
1331
+
1332
+ handshake_in_memory (clientConnection , serverConnection )
1333
+
1334
+ assert verify .connection is clientConnection
1335
+
1336
+ def test_set_verify_wrong_args (self ):
1337
+ context = Context (TLSv1_METHOD )
1338
+ with pytest .raises (TypeError ):
1339
+ context .set_verify (None , lambda * args : None )
1340
+
1341
+ with pytest .raises (TypeError ):
1342
+ context .set_verify (VERIFY_PEER , None )
1343
+
1344
+ def test_connection_set_verify_wrong_args (self ):
1345
+ context = Context (TLSv1_METHOD )
1346
+ connection = Connection (context , None )
1347
+ with pytest .raises (TypeError ):
1348
+ connection .set_verify (None , lambda * args : None )
1349
+
1350
+ with pytest .raises (TypeError ):
1351
+ connection .set_verify (VERIFY_PEER , None )
1352
+
1288
1353
def test_add_extra_chain_cert (self , tmpdir ):
1289
1354
"""
1290
1355
`Context.add_extra_chain_cert` accepts an `X509`
@@ -1418,6 +1483,18 @@ def test_set_verify_mode(self):
1418
1483
VERIFY_PEER | VERIFY_CLIENT_ONCE , lambda * args : None )
1419
1484
assert context .get_verify_mode () == (VERIFY_PEER | VERIFY_CLIENT_ONCE )
1420
1485
1486
+ def test_connection_get_verify_mode (self ):
1487
+ """
1488
+ `Connection.get_verify_mode` returns the verify mode flags previously
1489
+ passed to `Connection.set_verify`.
1490
+ """
1491
+ context = Context (TLSv1_METHOD )
1492
+ conn = Connection (context , None )
1493
+ assert conn .get_verify_mode () == 0
1494
+ conn .set_verify (
1495
+ VERIFY_PEER | VERIFY_CLIENT_ONCE , lambda * args : None )
1496
+ assert conn .get_verify_mode () == (VERIFY_PEER | VERIFY_CLIENT_ONCE )
1497
+
1421
1498
@pytest .mark .parametrize ('mode' , [None , 1.0 , object (), 'mode' ])
1422
1499
def test_set_verify_wrong_mode_arg (self , mode ):
1423
1500
"""
0 commit comments