@@ -166,6 +166,22 @@ def test_start_with_tls_verify_false
166166 assert_equal ( true , smtp . rset . success? )
167167 end
168168
169+ def test_tls_verify_true_after_initialize
170+ smtp = MySMTP . new ( start_smtpd_starttls , tls_verify : false )
171+ smtp . tls_verify = true
172+ assert_raise ( OpenSSL ::SSL ::SSLError ) { smtp . start }
173+ assert_equal ( OpenSSL ::X509 ::V_ERR_SELF_SIGNED_CERT_IN_CHAIN , smtp . __ssl_socket . verify_result )
174+ assert_equal ( OpenSSL ::SSL ::VERIFY_PEER , smtp . __ssl_context . verify_mode )
175+ end
176+
177+ def test_tls_verify_false_after_initialize
178+ smtp = MySMTP . new ( start_smtpd_starttls , tls_verify : true )
179+ smtp . tls_verify = false
180+ smtp . start
181+ assert_equal ( OpenSSL ::SSL ::VERIFY_NONE , smtp . __ssl_context . verify_mode )
182+ assert_equal ( true , smtp . rset . success? )
183+ end
184+
169185 def test_start_with_tls_hostname
170186 smtp = MySMTP . new ( start_smtpd_starttls , tls_hostname : "unexpected.example.com" )
171187 context = default_ssl_context
@@ -184,10 +200,27 @@ def test_start_without_tls_hostname
184200 assert_equal ( true , smtp . rset . success? )
185201 end
186202
203+ def test_tls_hostname_after_initialize
204+ smtp = MySMTP . new ( start_smtpd_starttls )
205+ smtp . tls_hostname = "unexpected.example.com"
206+ context = default_ssl_context
207+ smtp . enable_starttls ( context )
208+ assert_raise ( OpenSSL ::SSL ::SSLError ) { smtp . start }
209+ # TODO: Not all OpenSSL versions have the same verify_result code
210+ assert_equal ( "unexpected.example.com" , smtp . __ssl_socket . hostname )
211+ end
212+
187213 def test_start_with_ssl_context_params
188214 smtp = MySMTP . new ( start_smtpd_starttls , ssl_context_params : { timeout : 123 , verify_mode : OpenSSL ::SSL ::VERIFY_NONE } )
189215 smtp . start
190216 assert_equal ( 123 , smtp . __ssl_context . timeout )
191217 end
218+
219+ def test_ssl_context_params_after_initialize
220+ smtp = MySMTP . new ( start_smtpd_starttls )
221+ smtp . ssl_context_params = { timeout : 123 , verify_mode : OpenSSL ::SSL ::VERIFY_NONE }
222+ smtp . start
223+ assert_equal ( 123 , smtp . __ssl_context . timeout )
224+ end
192225 end
193226end
0 commit comments