@@ -187,109 +187,6 @@ def test_subproc_signal_handler_trouble(self, mock_exit, mock_kill):
187187 mock_exit .assert_called_once_with (0 )
188188
189189
190- class AlreadyListeningTest (unittest .TestCase ):
191- """Tests for already_listening() method."""
192- def setUp (self ):
193- from letsencrypt .plugins .standalone .authenticator import \
194- StandaloneAuthenticator
195- self .authenticator = StandaloneAuthenticator (config = CONFIG , name = None )
196-
197- @mock .patch ("letsencrypt.plugins.standalone.authenticator.psutil."
198- "net_connections" )
199- @mock .patch ("letsencrypt.plugins.standalone.authenticator.psutil.Process" )
200- @mock .patch ("letsencrypt.plugins.standalone.authenticator."
201- "zope.component.getUtility" )
202- def test_race_condition (self , mock_get_utility , mock_process , mock_net ):
203- # This tests a race condition, or permission problem, or OS
204- # incompatibility in which, for some reason, no process name can be
205- # found to match the identified listening PID.
206- from psutil ._common import sconn
207- conns = [
208- sconn (fd = - 1 , family = 2 , type = 1 , laddr = ("0.0.0.0" , 30 ),
209- raddr = (), status = "LISTEN" , pid = None ),
210- sconn (fd = 3 , family = 2 , type = 1 , laddr = ("192.168.5.10" , 32783 ),
211- raddr = ("20.40.60.80" , 22 ), status = "ESTABLISHED" , pid = 1234 ),
212- sconn (fd = - 1 , family = 10 , type = 1 , laddr = ("::1" , 54321 ),
213- raddr = ("::1" , 111 ), status = "CLOSE_WAIT" , pid = None ),
214- sconn (fd = 3 , family = 2 , type = 1 , laddr = ("0.0.0.0" , 17 ),
215- raddr = (), status = "LISTEN" , pid = 4416 )]
216- mock_net .return_value = conns
217- mock_process .side_effect = psutil .NoSuchProcess ("No such PID" )
218- # We simulate being unable to find the process name of PID 4416,
219- # which results in returning False.
220- self .assertFalse (self .authenticator .already_listening (17 ))
221- self .assertEqual (mock_get_utility .generic_notification .call_count , 0 )
222- mock_process .assert_called_once_with (4416 )
223-
224- @mock .patch ("letsencrypt.plugins.standalone.authenticator.psutil."
225- "net_connections" )
226- @mock .patch ("letsencrypt.plugins.standalone.authenticator.psutil.Process" )
227- @mock .patch ("letsencrypt.plugins.standalone.authenticator."
228- "zope.component.getUtility" )
229- def test_not_listening (self , mock_get_utility , mock_process , mock_net ):
230- from psutil ._common import sconn
231- conns = [
232- sconn (fd = - 1 , family = 2 , type = 1 , laddr = ("0.0.0.0" , 30 ),
233- raddr = (), status = "LISTEN" , pid = None ),
234- sconn (fd = 3 , family = 2 , type = 1 , laddr = ("192.168.5.10" , 32783 ),
235- raddr = ("20.40.60.80" , 22 ), status = "ESTABLISHED" , pid = 1234 ),
236- sconn (fd = - 1 , family = 10 , type = 1 , laddr = ("::1" , 54321 ),
237- raddr = ("::1" , 111 ), status = "CLOSE_WAIT" , pid = None )]
238- mock_net .return_value = conns
239- mock_process .name .return_value = "inetd"
240- self .assertFalse (self .authenticator .already_listening (17 ))
241- self .assertEqual (mock_get_utility .generic_notification .call_count , 0 )
242- self .assertEqual (mock_process .call_count , 0 )
243-
244- @mock .patch ("letsencrypt.plugins.standalone.authenticator.psutil."
245- "net_connections" )
246- @mock .patch ("letsencrypt.plugins.standalone.authenticator.psutil.Process" )
247- @mock .patch ("letsencrypt.plugins.standalone.authenticator."
248- "zope.component.getUtility" )
249- def test_listening_ipv4 (self , mock_get_utility , mock_process , mock_net ):
250- from psutil ._common import sconn
251- conns = [
252- sconn (fd = - 1 , family = 2 , type = 1 , laddr = ("0.0.0.0" , 30 ),
253- raddr = (), status = "LISTEN" , pid = None ),
254- sconn (fd = 3 , family = 2 , type = 1 , laddr = ("192.168.5.10" , 32783 ),
255- raddr = ("20.40.60.80" , 22 ), status = "ESTABLISHED" , pid = 1234 ),
256- sconn (fd = - 1 , family = 10 , type = 1 , laddr = ("::1" , 54321 ),
257- raddr = ("::1" , 111 ), status = "CLOSE_WAIT" , pid = None ),
258- sconn (fd = 3 , family = 2 , type = 1 , laddr = ("0.0.0.0" , 17 ),
259- raddr = (), status = "LISTEN" , pid = 4416 )]
260- mock_net .return_value = conns
261- mock_process .name .return_value = "inetd"
262- result = self .authenticator .already_listening (17 )
263- self .assertTrue (result )
264- self .assertEqual (mock_get_utility .call_count , 1 )
265- mock_process .assert_called_once_with (4416 )
266-
267- @mock .patch ("letsencrypt.plugins.standalone.authenticator.psutil."
268- "net_connections" )
269- @mock .patch ("letsencrypt.plugins.standalone.authenticator.psutil.Process" )
270- @mock .patch ("letsencrypt.plugins.standalone.authenticator."
271- "zope.component.getUtility" )
272- def test_listening_ipv6 (self , mock_get_utility , mock_process , mock_net ):
273- from psutil ._common import sconn
274- conns = [
275- sconn (fd = - 1 , family = 2 , type = 1 , laddr = ("0.0.0.0" , 30 ),
276- raddr = (), status = "LISTEN" , pid = None ),
277- sconn (fd = 3 , family = 2 , type = 1 , laddr = ("192.168.5.10" , 32783 ),
278- raddr = ("20.40.60.80" , 22 ), status = "ESTABLISHED" , pid = 1234 ),
279- sconn (fd = - 1 , family = 10 , type = 1 , laddr = ("::1" , 54321 ),
280- raddr = ("::1" , 111 ), status = "CLOSE_WAIT" , pid = None ),
281- sconn (fd = 3 , family = 10 , type = 1 , laddr = ("::" , 12345 ), raddr = (),
282- status = "LISTEN" , pid = 4420 ),
283- sconn (fd = 3 , family = 2 , type = 1 , laddr = ("0.0.0.0" , 17 ),
284- raddr = (), status = "LISTEN" , pid = 4416 )]
285- mock_net .return_value = conns
286- mock_process .name .return_value = "inetd"
287- result = self .authenticator .already_listening (12345 )
288- self .assertTrue (result )
289- self .assertEqual (mock_get_utility .call_count , 1 )
290- mock_process .assert_called_once_with (4420 )
291-
292-
293190class PerformTest (unittest .TestCase ):
294191 """Tests for perform() method."""
295192 def setUp (self ):
0 commit comments