@@ -308,11 +308,51 @@ def test_enable_devtools(
308
308
mock_acceptor_pool .return_value .setup .assert_called_once ()
309
309
mock_listener .return_value .setup .assert_called_once ()
310
310
311
- # def test_pac_file(self) -> None:
312
- # pass
313
-
314
- # def test_imports_plugin(self) -> None:
315
- # pass
316
-
317
- # def test_cannot_enable_https_proxy_and_tls_interception_mutually(self) -> None:
318
- # pass
311
+ @mock .patch ('time.sleep' )
312
+ @mock .patch ('proxy.common.plugins.Plugins.load' )
313
+ @mock .patch ('proxy.common.flag.FlagParser.parse_args' )
314
+ @mock .patch ('proxy.proxy.EventManager' )
315
+ @mock .patch ('proxy.proxy.AcceptorPool' )
316
+ @mock .patch ('proxy.proxy.ThreadlessPool' )
317
+ @mock .patch ('proxy.proxy.Listener' )
318
+ @mock .patch ('proxy.proxy.SshHttpProtocolHandler' )
319
+ @mock .patch ('proxy.proxy.SshTunnelListener' )
320
+ def test_enable_ssh_tunnel (
321
+ self ,
322
+ mock_ssh_tunnel_listener : mock .Mock ,
323
+ mock_ssh_http_proto_handler : mock .Mock ,
324
+ mock_listener : mock .Mock ,
325
+ mock_executor_pool : mock .Mock ,
326
+ mock_acceptor_pool : mock .Mock ,
327
+ mock_event_manager : mock .Mock ,
328
+ mock_parse_args : mock .Mock ,
329
+ mock_load_plugins : mock .Mock ,
330
+ mock_sleep : mock .Mock ,
331
+ ) -> None :
332
+ mock_sleep .side_effect = KeyboardInterrupt ()
333
+ mock_args = mock_parse_args .return_value
334
+ self .mock_default_args (mock_args )
335
+ mock_args .enable_ssh_tunnel = True
336
+ mock_args .local_executor = 0
337
+ main (enable_ssh_tunnel = True , local_executor = 0 )
338
+ mock_load_plugins .assert_called ()
339
+ self .assertEqual (
340
+ mock_load_plugins .call_args_list [0 ][0 ][0 ], [
341
+ bytes_ (PLUGIN_HTTP_PROXY ),
342
+ ],
343
+ )
344
+ mock_parse_args .assert_called_once ()
345
+ mock_event_manager .assert_not_called ()
346
+ if _env_threadless_compliant ():
347
+ mock_executor_pool .assert_called_once ()
348
+ mock_executor_pool .return_value .setup .assert_called_once ()
349
+ mock_acceptor_pool .assert_called_once ()
350
+ mock_acceptor_pool .return_value .setup .assert_called_once ()
351
+ mock_listener .return_value .setup .assert_called_once ()
352
+ mock_ssh_http_proto_handler .assert_called_once ()
353
+ mock_ssh_tunnel_listener .assert_called_once ()
354
+ mock_ssh_tunnel_listener .return_value .setup .assert_called_once ()
355
+ mock_ssh_tunnel_listener .return_value .start_port_forward .assert_called_once ()
356
+ mock_ssh_tunnel_listener .return_value .shutdown .assert_called_once ()
357
+ # shutdown will internally call stop port forward
358
+ mock_ssh_tunnel_listener .return_value .stop_port_forward .assert_not_called ()
0 commit comments