From ed2366270c3c94488985597d831687069db8df79 Mon Sep 17 00:00:00 2001 From: David Dick Date: Sat, 2 Nov 2024 22:20:49 +1100 Subject: [PATCH] Adding support for socks scheme in proxy variables. Thanks to Veraellyunjie for the bug report in GH#68 --- lib/Firefox/Marionette.pm | 3 +++ t/04-proxy.t | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/Firefox/Marionette.pm b/lib/Firefox/Marionette.pm index 7a6a287..7d02ff5 100644 --- a/lib/Firefox/Marionette.pm +++ b/lib/Firefox/Marionette.pm @@ -8514,6 +8514,9 @@ sub _proxy_from_env { $build->{proxyAutoconfigUrl} = Firefox::Marionette::Proxy->get_inline_pac($uri); } + elsif ( $value =~ /^socks(?:[45])?:\/\/(.*?(:\d+)?)$/smx ) { + $build->{ $build_key . 'Proxy' } = $1; + } else { $build->{ $build_key . 'Proxy' } = $uri->host_port(); } diff --git a/t/04-proxy.t b/t/04-proxy.t index 511b191..3177acf 100644 --- a/t/04-proxy.t +++ b/t/04-proxy.t @@ -254,6 +254,18 @@ SKIP: { ok($firefox->go("http://$nginx_listen:" . $nginx->port()), "Retrieved webpage with SOCKS proxy (v5)"); $strip = $firefox->strip(); ok($strip eq $nginx->content(), "Successfully retrieved web page through ssh and SOCKS proxy (v5):$strip:"); + foreach my $scheme (qw(socks socks4 socks5)) { + local $ENV{all_proxy} = $scheme . '://' . $socks_listen . ':' . $socks->port(); + my $firefox = Firefox::Marionette->new( + debug => $debug, + visible => $visible, + profile => $profile, + ); + ok($firefox, "Created a firefox object going through ssh and the all_proxy environment variable of ($scheme://$socks_listen:" . $socks->port() . ")"); + ok($firefox->go("http://$nginx_listen:" . $nginx->port()), "Retrieved webpage with all_proxy environment variable set to a scheme of $scheme"); + my $strip = $firefox->strip(); + ok($strip eq $nginx->content(), "Successfully retrieved web page through all_proxy environment variable set to a scheme of $scheme"); + } ok($nginx->stop() == 0, "Stopped nginx on $nginx_listen:" . $nginx->port()); ok($socks->stop() == 0, "Stopped SOCKS proxy on $socks_listen:" . $socks->port()); }