2121from aiosmtpd .main import main , parseargs
2222from aiosmtpd .testing .helpers import catchup_delay
2323from aiosmtpd .testing .statuscodes import SMTP_STATUS_CODES as S
24- from aiosmtpd .tests .conftest import AUTOSTOP_DELAY , SERVER_CRT , SERVER_KEY
24+ from aiosmtpd .tests .conftest import AUTOSTOP_DELAY
2525
2626try :
2727 import pwd
@@ -199,24 +199,24 @@ def test_debug_3(self):
199199
200200@pytest .mark .skipif (sys .platform == "darwin" , reason = "No idea why these are failing" )
201201class TestMainByWatcher :
202- def test_tls (self , temp_event_loop ):
202+ def test_tls (self , temp_event_loop , tls_cert_pem_path , tls_key_pem_path ):
203203 with watcher_process (watch_for_tls ) as retq :
204204 temp_event_loop .call_later (AUTOSTOP_DELAY , temp_event_loop .stop )
205- main_n ("--tlscert" , str ( SERVER_CRT ) , "--tlskey" , str ( SERVER_KEY ) )
205+ main_n ("--tlscert" , tls_cert_pem_path , "--tlskey" , tls_key_pem_path )
206206 catchup_delay ()
207207 has_starttls = retq .get ()
208208 assert has_starttls is True
209209 require_tls = retq .get ()
210210 assert require_tls is True
211211
212- def test_tls_noreq (self , temp_event_loop ):
212+ def test_tls_noreq (self , temp_event_loop , tls_cert_pem_path , tls_key_pem_path ):
213213 with watcher_process (watch_for_tls ) as retq :
214214 temp_event_loop .call_later (AUTOSTOP_DELAY , temp_event_loop .stop )
215215 main_n (
216216 "--tlscert" ,
217- str ( SERVER_CRT ) ,
217+ tls_cert_pem_path ,
218218 "--tlskey" ,
219- str ( SERVER_KEY ) ,
219+ tls_key_pem_path ,
220220 "--no-requiretls" ,
221221 )
222222 catchup_delay ()
@@ -225,10 +225,10 @@ def test_tls_noreq(self, temp_event_loop):
225225 require_tls = retq .get ()
226226 assert require_tls is False
227227
228- def test_smtps (self , temp_event_loop ):
228+ def test_smtps (self , temp_event_loop , tls_cert_pem_path , tls_key_pem_path ):
229229 with watcher_process (watch_for_smtps ) as retq :
230230 temp_event_loop .call_later (AUTOSTOP_DELAY , temp_event_loop .stop )
231- main_n ("--smtpscert" , str ( SERVER_CRT ) , "--smtpskey" , str ( SERVER_KEY ) )
231+ main_n ("--smtpscert" , tls_cert_pem_path , "--smtpskey" , tls_key_pem_path )
232232 catchup_delay ()
233233 has_smtps = retq .get ()
234234 assert has_smtps is True
@@ -335,16 +335,18 @@ def test_norequiretls(self, capsys, mocker):
335335 assert args .requiretls is False
336336
337337 @pytest .mark .parametrize (
338- ("certfile " , "keyfile " , "expect" ),
338+ ("certfile_present " , "keyfile_present " , "expect" ),
339339 [
340- ("x" , "x" , "Cert file x not found" ),
341- (SERVER_CRT , "x" , "Key file x not found" ),
342- ("x" , SERVER_KEY , "Cert file x not found" ),
340+ (False , False , "Cert file x not found" ),
341+ (True , False , "Key file x not found" ),
342+ (False , True , "Cert file x not found" ),
343343 ],
344344 ids = ["x-x" , "cert-x" , "x-key" ],
345345 )
346346 @pytest .mark .parametrize ("meth" , ["smtps" , "tls" ])
347- def test_ssl_files_err (self , capsys , mocker , meth , certfile , keyfile , expect ):
347+ def test_ssl_files_err (self , capsys , mocker , meth , certfile_present , keyfile_present , expect , request ):
348+ certfile = request .getfixturevalue ("tls_cert_pem_path" ) if certfile_present else "x"
349+ keyfile = request .getfixturevalue ("tls_key_pem_path" ) if keyfile_present else "x"
348350 mocker .patch ("aiosmtpd.main.PROGRAM" , "smtpd" )
349351 with pytest .raises (SystemExit ) as exc :
350352 parseargs ((f"--{ meth } cert" , certfile , f"--{ meth } key" , keyfile ))
0 commit comments