99import time
1010from contextlib import contextmanager
1111from multiprocessing .synchronize import Event as MP_Event
12+ from pathlib import Path
1213from smtplib import SMTP as SMTPClient
1314from smtplib import SMTP_SSL
1415from typing import Generator
2122from aiosmtpd .main import main , parseargs
2223from aiosmtpd .testing .helpers import catchup_delay
2324from aiosmtpd .testing .statuscodes import SMTP_STATUS_CODES as S
24- from aiosmtpd .tests .conftest import AUTOSTOP_DELAY , SERVER_CRT , SERVER_KEY
25+ from aiosmtpd .tests .conftest import AUTOSTOP_DELAY
2526
2627try :
2728 import pwd
@@ -199,24 +200,24 @@ def test_debug_3(self):
199200
200201@pytest .mark .skipif (sys .platform == "darwin" , reason = "No idea why these are failing" )
201202class TestMainByWatcher :
202- def test_tls (self , temp_event_loop ):
203+ def test_tls (self , temp_event_loop , server_crt : Path , server_key : Path ):
203204 with watcher_process (watch_for_tls ) as retq :
204205 temp_event_loop .call_later (AUTOSTOP_DELAY , temp_event_loop .stop )
205- main_n ("--tlscert" , str (SERVER_CRT ), "--tlskey" , str (SERVER_KEY ))
206+ main_n ("--tlscert" , str (server_crt ), "--tlskey" , str (server_key ))
206207 catchup_delay ()
207208 has_starttls = retq .get ()
208209 assert has_starttls is True
209210 require_tls = retq .get ()
210211 assert require_tls is True
211212
212- def test_tls_noreq (self , temp_event_loop ):
213+ def test_tls_noreq (self , temp_event_loop , server_crt : Path , server_key : Path ):
213214 with watcher_process (watch_for_tls ) as retq :
214215 temp_event_loop .call_later (AUTOSTOP_DELAY , temp_event_loop .stop )
215216 main_n (
216217 "--tlscert" ,
217- str (SERVER_CRT ),
218+ str (server_crt ),
218219 "--tlskey" ,
219- str (SERVER_KEY ),
220+ str (server_key ),
220221 "--no-requiretls" ,
221222 )
222223 catchup_delay ()
@@ -225,10 +226,10 @@ def test_tls_noreq(self, temp_event_loop):
225226 require_tls = retq .get ()
226227 assert require_tls is False
227228
228- def test_smtps (self , temp_event_loop ):
229+ def test_smtps (self , temp_event_loop , server_crt : Path , server_key : Path ):
229230 with watcher_process (watch_for_smtps ) as retq :
230231 temp_event_loop .call_later (AUTOSTOP_DELAY , temp_event_loop .stop )
231- main_n ("--smtpscert" , str (SERVER_CRT ), "--smtpskey" , str (SERVER_KEY ))
232+ main_n ("--smtpscert" , str (server_crt ), "--smtpskey" , str (server_key ))
232233 catchup_delay ()
233234 has_smtps = retq .get ()
234235 assert has_smtps is True
@@ -335,19 +336,21 @@ def test_norequiretls(self, capsys, mocker):
335336 assert args .requiretls is False
336337
337338 @pytest .mark .parametrize (
338- ("certfile " , "keyfile " , "expect" ),
339+ ("certfile_present " , "keyfile_present " , "expect" ),
339340 [
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" ),
341+ (False , False , "Cert file x not found" ),
342+ (True , False , "Key file x not found" ),
343+ (False , True , "Cert file x not found" ),
343344 ],
344345 ids = ["x-x" , "cert-x" , "x-key" ],
345346 )
346347 @pytest .mark .parametrize ("meth" , ["smtps" , "tls" ])
347- def test_ssl_files_err (self , capsys , mocker , meth , certfile , keyfile , expect ):
348+ def test_ssl_files_err (self , capsys , mocker , meth , certfile_present , keyfile_present , expect , request : pytest .FixtureRequest ):
349+ certfile = request .getfixturevalue ("server_crt" ) if certfile_present else "x"
350+ keyfile = request .getfixturevalue ("server_key" ) if keyfile_present else "x"
348351 mocker .patch ("aiosmtpd.main.PROGRAM" , "smtpd" )
349352 with pytest .raises (SystemExit ) as exc :
350- parseargs ((f"--{ meth } cert" , certfile , f"--{ meth } key" , keyfile ))
353+ parseargs ((f"--{ meth } cert" , str ( certfile ) , f"--{ meth } key" , str ( keyfile ) ))
351354 assert exc .value .code == 2
352355 assert expect in capsys .readouterr ().err
353356
0 commit comments