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