From 2552fab2ca6f80ffbc01c387d5627eeea39f3f92 Mon Sep 17 00:00:00 2001 From: Winston Date: Wed, 9 Nov 2016 17:08:38 -0800 Subject: [PATCH 1/2] Allow HTTP_PROXY settings to use username and password --- lib/soap/netHttpClient.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/soap/netHttpClient.rb b/lib/soap/netHttpClient.rb index 95a9d6aed..792ea3ddb 100644 --- a/lib/soap/netHttpClient.rb +++ b/lib/soap/netHttpClient.rb @@ -169,8 +169,10 @@ def create_connection(url) unless no_proxy?(url) proxy_host = @proxy.host proxy_port = @proxy.port + proxy_user = @proxy.user + proxy_password = @proxy.password end - http = Net::HTTP::Proxy(proxy_host, proxy_port).new(url.host, url.port) + http = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_password).new(url.host, url.port) if http.respond_to?(:set_debug_output) http.set_debug_output(@debug_dev) end From 1113f8c84d8c9c649d28b91da21e80679632489a Mon Sep 17 00:00:00 2001 From: "Laurence A. Lee" Date: Thu, 9 Jul 2026 13:36:27 -1000 Subject: [PATCH 2/2] Add regression coverage for proxy username/password support Winston's fix (previous commit) passes @proxy's user/password through to Net::HTTP::Proxy(...), which the Net::HTTP fallback driver (lib/soap/netHttpClient.rb) previously dropped on the floor entirely. No existing test exercises this file at all: HTTPStreamHandler only falls back to NetHttpClient when both httpclient and http-access2 fail to load, and this project's Gemfile always requires httpclient, so nothing else in the suite ever reaches this code path. Added test/soap/test_nethttpclient.rb, calling create_connection directly (it's private, invoked via #send) since it just builds and configures a Net::HTTP object with no actual #start/connect call -- safe to test without a real network call or proxy server. Covers the credentialed case, the credential-less case (no regression), and the no-proxy-at-all case. Confirmed this fails on the exact credentialed-proxy assertion without Winston's fix, and passes cleanly with it. Co-Authored-By: Winston --- test/soap/test_nethttpclient.rb | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/soap/test_nethttpclient.rb diff --git a/test/soap/test_nethttpclient.rb b/test/soap/test_nethttpclient.rb new file mode 100644 index 000000000..d51598d09 --- /dev/null +++ b/test/soap/test_nethttpclient.rb @@ -0,0 +1,45 @@ +# encoding: UTF-8 +require 'helper' +require 'soap/netHttpClient' + +module SOAP + + +# Covers SOAP::NetHttpClient#create_connection directly (via #send, since +# it's private) rather than through the full driver/streamHandler stack: +# HTTPStreamHandler only falls back to NetHttpClient when both httpclient +# and http-access2 fail to load, and this project's Gemfile always +# requires httpclient, so nothing else in the suite ever exercises this +# file. create_connection only builds and configures a Net::HTTP object +# (no #start call), so this is safe to test without a real network call +# or proxy server. +class TestNetHttpClient < Test::Unit::TestCase + TARGET = URI.parse("http://target.example.com/") + + def test_proxy_with_credentials + client = NetHttpClient.new("http://myuser:mypass@myproxy.example.com:8080") + conn = client.send(:create_connection, TARGET) + assert_equal("myproxy.example.com", conn.proxy_address) + assert_equal(8080, conn.proxy_port) + assert_equal("myuser", conn.proxy_user) + assert_equal("mypass", conn.proxy_pass) + end + + def test_proxy_without_credentials + client = NetHttpClient.new("http://myproxy.example.com:8080") + conn = client.send(:create_connection, TARGET) + assert_equal("myproxy.example.com", conn.proxy_address) + assert_equal(8080, conn.proxy_port) + assert_nil(conn.proxy_user) + assert_nil(conn.proxy_pass) + end + + def test_no_proxy + client = NetHttpClient.new + conn = client.send(:create_connection, TARGET) + assert_nil(conn.proxy_address) + end +end + + +end