@@ -468,19 +468,33 @@ def test_tcp_connector_expect_fingerprint_invalid_len(self):
468
468
with self .assertRaises (ValueError ):
469
469
aiohttp .TCPConnector (loop = self .loop , expect_fingerprint = invalid )
470
470
471
+ def test_tcp_connector_expect_fingerprint_invalid_type (self ):
472
+ invalid = 123
473
+ with self .assertRaises (TypeError ):
474
+ aiohttp .TCPConnector (loop = self .loop , expect_fingerprint = invalid )
475
+
471
476
def test_tcp_connector_expect_fingerprint (self ):
472
- # the even-index fingerprints below are for sample.crt.der,
473
- # the certificate presented by test_utils.run_server
477
+ # The even-index fingerprints below are "expect success" cases
478
+ # for ./sample.crt.der, the cert presented by test_utils.run_server.
479
+ # The odd-index fingerprints are "expect fail" cases.
474
480
testcases = (
475
481
# md5
476
- 'a20647adaaf5d85c4a995e62793b063d' , # good
477
- 'ffffffffffffffffffffffffffffffff' , # bad
482
+ 'a2:06:47:ad:aa:f5:d8:5c:4a:99:5e:62:79:3b:06:3d' , # good
483
+ 'ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff' , # bad
484
+
485
+ 'A20647ADAAF5D85C4A995E62793B063D' , # colons and case ignored
486
+ 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' ,
487
+
488
+ b'\xa2 \x06 G\xad \xaa \xf5 \xd8 \\ J\x99 ^by;\x06 =' , # bytes ok too
489
+ b'\xff ' * 16 ,
490
+
478
491
# sha1
479
- '7393fd3aed081d6fa9ae71391ae3c57f89e76cf9' , # good
480
- 'ffffffffffffffffffffffffffffffffffffffff' , # bad
492
+ '7393fd3aed081d6fa9ae71391ae3c57f89e76cf9' ,
493
+ 'ffffffffffffffffffffffffffffffffffffffff' ,
494
+
481
495
# sha256
482
- '309ac94483dc9127889111a16497fdcb7e37551444404c11ab99a8aeb714ee8b' , # good # flake8: noqa
483
- 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' , # bad # flake8: noqa
496
+ '309ac94483dc9127889111a16497fdcb7e37551444404c11ab99a8aeb714ee8b' , # flake8: noqa
497
+ 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' , # flake8: noqa
484
498
)
485
499
for i , fingerprint in enumerate (testcases ):
486
500
expect_fail = i % 2
@@ -490,10 +504,8 @@ def test_tcp_connector_expect_fingerprint(self):
490
504
coro = client .request ('get' , httpd .url ('method' , 'get' ),
491
505
connector = conn , loop = self .loop )
492
506
if expect_fail :
493
- with self .assertRaises (FingerprintMismatch ) as cm :
507
+ with self .assertRaises (FingerprintMismatch ):
494
508
self .loop .run_until_complete (coro )
495
- self .assertEqual (cm .exception .expected , fingerprint )
496
- self .assertEqual (cm .exception .got , testcases [i - 1 ])
497
509
else :
498
510
# should not raise
499
511
self .loop .run_until_complete (coro )
0 commit comments