Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/soap/netHttpClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions test/soap/test_nethttpclient.rb
Original file line number Diff line number Diff line change
@@ -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
Loading