@@ -459,3 +459,41 @@ def close(self):
459459 data = b"plain text no iac"
460460 server .data_received (data )
461461 assert bytes (server .reader ._buffer ).endswith (data )
462+
463+
464+ @pytest .mark .parametrize (
465+ "ssl_obj,expect_log" ,
466+ [
467+ pytest .param (None , False , id = "no_tls" ),
468+ pytest .param (
469+ type (
470+ "SSL" ,
471+ (),
472+ {"version" : lambda self : "TLSv1.3" , "cipher" : lambda self : ("AES" , "TLSv1.3" , 256 )},
473+ )(),
474+ True ,
475+ id = "tls_with_cipher" ,
476+ ),
477+ pytest .param (
478+ type ("SSL" , (), {"version" : lambda self : None , "cipher" : lambda self : None })(),
479+ True ,
480+ id = "tls_no_cipher" ,
481+ ),
482+ ],
483+ )
484+ def test_log_tls_info (ssl_obj , expect_log , caplog ):
485+ from telnetlib3 ._base import TelnetProtocolBase
486+
487+ proto = TelnetProtocolBase .__new__ (TelnetProtocolBase )
488+ proto ._extra = {}
489+ proto ._transport = MagicMock ()
490+ proto ._transport .get_extra_info = lambda name , default = None : (
491+ ssl_obj if name == "ssl_object" else default
492+ )
493+ log = logging .getLogger ("test_tls_info" )
494+ with caplog .at_level (logging .DEBUG , logger = "test_tls_info" ):
495+ proto ._log_tls_info (log )
496+ tls_msgs = [r for r in caplog .records if "TLS handshake" in r .message ]
497+ assert bool (tls_msgs ) == expect_log
498+ if ssl_obj and ssl_obj .cipher ():
499+ assert "AES" in tls_msgs [0 ].message
0 commit comments