@@ -45,6 +45,59 @@ def test_connect_starttls(self):
4545 server .ehlo ()
4646 server .quit ()
4747
48+ def test_connect_host_port_starttls (self ):
49+ support .get_attribute (smtplib , 'SMTP_SSL' )
50+ context = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
51+ context .check_hostname = False
52+ context .verify_mode = ssl .CERT_NONE
53+ with socket_helper .transient_internet (self .testServer ):
54+ server = smtplib .SMTP (f'{ self .testServer } :{ self .remotePort } ' )
55+ try :
56+ server .starttls (context = context )
57+ except smtplib .SMTPException as e :
58+ if e .args [0 ] == 'STARTTLS extension not supported by server.' :
59+ unittest .skip (e .args [0 ])
60+ else :
61+ raise
62+ server .ehlo ()
63+ server .quit ()
64+
65+ def test_explicit_connect_starttls (self ):
66+ support .get_attribute (smtplib , 'SMTP_SSL' )
67+ context = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
68+ context .check_hostname = False
69+ context .verify_mode = ssl .CERT_NONE
70+ with socket_helper .transient_internet (self .testServer ):
71+ server = smtplib .SMTP ()
72+ server .connect (self .testServer , self .remotePort )
73+ try :
74+ server .starttls (context = context )
75+ except smtplib .SMTPException as e :
76+ if e .args [0 ] == 'STARTTLS extension not supported by server.' :
77+ unittest .skip (e .args [0 ])
78+ else :
79+ raise
80+ server .ehlo ()
81+ server .quit ()
82+
83+ def test_explicit_connect_host_port_starttls (self ):
84+ support .get_attribute (smtplib , 'SMTP_SSL' )
85+ context = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
86+ context .check_hostname = False
87+ context .verify_mode = ssl .CERT_NONE
88+ with socket_helper .transient_internet (self .testServer ):
89+ server = smtplib .SMTP ()
90+ server .connect (f'{ self .testServer } :{ self .remotePort } ' )
91+ try :
92+ server .starttls (context = context )
93+ except smtplib .SMTPException as e :
94+ if e .args [0 ] == 'STARTTLS extension not supported by server.' :
95+ unittest .skip (e .args [0 ])
96+ else :
97+ raise
98+ server .ehlo ()
99+ server .quit ()
100+
48101
49102class SmtpSSLTest (unittest .TestCase ):
50103 testServer = SMTP_TEST_SERVER
0 commit comments