mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test/net/http/test_https.rb (test_get_SNI_failure): stop proxy settings
Because the test fails under HTTP proxy settings.20191210
T000004Z.fail.html.gz ``` 1) Failure: TestNetHTTPS#test_get_SNI_failure [/export/home/users/chkbuild/cb-gcc/tmp/build/20191210T000004Z/ruby/test/net/http/test_https.rb:81]: [OpenSSL::SSL::SSLError] exception expected, not #<Net::HTTPServerException: 403 "Forbidden">. ``` The new SNI feature introduced at54072e329c
may need to be improved for HTTP proxy environment.
This commit is contained in:
parent
6a22b2a091
commit
660388f6c5
3 changed files with 45 additions and 43 deletions
|
@ -34,7 +34,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_Proxy_from_ENV
|
def test_class_Proxy_from_ENV
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
ENV['http_proxy'] = 'http://proxy.example:8000'
|
ENV['http_proxy'] = 'http://proxy.example:8000'
|
||||||
|
|
||||||
# These are ignored on purpose. See Bug 4388 and Feature 6546
|
# These are ignored on purpose. See Bug 4388 and Feature 6546
|
||||||
|
@ -115,7 +115,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_address
|
def test_proxy_address
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
http = Net::HTTP.new 'hostname.example', nil, 'proxy.example'
|
http = Net::HTTP.new 'hostname.example', nil, 'proxy.example'
|
||||||
assert_equal 'proxy.example', http.proxy_address
|
assert_equal 'proxy.example', http.proxy_address
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_address_no_proxy
|
def test_proxy_address_no_proxy
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
http = Net::HTTP.new 'hostname.example', nil, 'proxy.example', nil, nil, nil, 'example'
|
http = Net::HTTP.new 'hostname.example', nil, 'proxy.example', nil, nil, nil, 'example'
|
||||||
assert_nil http.proxy_address
|
assert_nil http.proxy_address
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_from_env_ENV
|
def test_proxy_from_env_ENV
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
ENV['http_proxy'] = 'http://proxy.example:8000'
|
ENV['http_proxy'] = 'http://proxy.example:8000'
|
||||||
|
|
||||||
assert_equal false, Net::HTTP.proxy_class?
|
assert_equal false, Net::HTTP.proxy_class?
|
||||||
|
@ -146,7 +146,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_address_ENV
|
def test_proxy_address_ENV
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
ENV['http_proxy'] = 'http://proxy.example:8000'
|
ENV['http_proxy'] = 'http://proxy.example:8000'
|
||||||
|
|
||||||
http = Net::HTTP.new 'hostname.example'
|
http = Net::HTTP.new 'hostname.example'
|
||||||
|
@ -156,13 +156,13 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_eh_no_proxy
|
def test_proxy_eh_no_proxy
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
assert_equal false, Net::HTTP.new('hostname.example', nil, nil).proxy?
|
assert_equal false, Net::HTTP.new('hostname.example', nil, nil).proxy?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_eh_ENV
|
def test_proxy_eh_ENV
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
ENV['http_proxy'] = 'http://proxy.example:8000'
|
ENV['http_proxy'] = 'http://proxy.example:8000'
|
||||||
|
|
||||||
http = Net::HTTP.new 'hostname.example'
|
http = Net::HTTP.new 'hostname.example'
|
||||||
|
@ -172,7 +172,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_eh_ENV_with_user
|
def test_proxy_eh_ENV_with_user
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
ENV['http_proxy'] = 'http://foo:bar@proxy.example:8000'
|
ENV['http_proxy'] = 'http://foo:bar@proxy.example:8000'
|
||||||
|
|
||||||
http = Net::HTTP.new 'hostname.example'
|
http = Net::HTTP.new 'hostname.example'
|
||||||
|
@ -189,13 +189,13 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_eh_ENV_none_set
|
def test_proxy_eh_ENV_none_set
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
assert_equal false, Net::HTTP.new('hostname.example').proxy?
|
assert_equal false, Net::HTTP.new('hostname.example').proxy?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_eh_ENV_no_proxy
|
def test_proxy_eh_ENV_no_proxy
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
ENV['http_proxy'] = 'http://proxy.example:8000'
|
ENV['http_proxy'] = 'http://proxy.example:8000'
|
||||||
ENV['no_proxy'] = 'hostname.example'
|
ENV['no_proxy'] = 'hostname.example'
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_port
|
def test_proxy_port
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
http = Net::HTTP.new 'example', nil, 'proxy.example'
|
http = Net::HTTP.new 'example', nil, 'proxy.example'
|
||||||
assert_equal 'proxy.example', http.proxy_address
|
assert_equal 'proxy.example', http.proxy_address
|
||||||
assert_equal 80, http.proxy_port
|
assert_equal 80, http.proxy_port
|
||||||
|
@ -216,7 +216,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_port_ENV
|
def test_proxy_port_ENV
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
ENV['http_proxy'] = 'http://proxy.example:8000'
|
ENV['http_proxy'] = 'http://proxy.example:8000'
|
||||||
|
|
||||||
http = Net::HTTP.new 'hostname.example'
|
http = Net::HTTP.new 'hostname.example'
|
||||||
|
@ -226,7 +226,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_newobj
|
def test_newobj
|
||||||
clean_http_proxy_env do
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
ENV['http_proxy'] = 'http://proxy.example:8000'
|
ENV['http_proxy'] = 'http://proxy.example:8000'
|
||||||
|
|
||||||
http = Net::HTTP.newobj 'hostname.example'
|
http = Net::HTTP.newobj 'hostname.example'
|
||||||
|
@ -235,25 +235,6 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_http_proxy_env
|
|
||||||
orig = {
|
|
||||||
'http_proxy' => ENV['http_proxy'],
|
|
||||||
'http_proxy_user' => ENV['http_proxy_user'],
|
|
||||||
'http_proxy_pass' => ENV['http_proxy_pass'],
|
|
||||||
'no_proxy' => ENV['no_proxy'],
|
|
||||||
}
|
|
||||||
|
|
||||||
orig.each_key do |key|
|
|
||||||
ENV.delete key
|
|
||||||
end
|
|
||||||
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
orig.each do |key, value|
|
|
||||||
ENV[key] = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_failure_message_includes_failed_domain_and_port
|
def test_failure_message_includes_failed_domain_and_port
|
||||||
# hostname to be included in the error message
|
# hostname to be included in the error message
|
||||||
host = Struct.new(:to_s).new("<example>")
|
host = Struct.new(:to_s).new("<example>")
|
||||||
|
@ -262,7 +243,7 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
def host.to_str; raise SocketError, "open failure"; end
|
def host.to_str; raise SocketError, "open failure"; end
|
||||||
uri = Struct.new(:scheme, :hostname, :port).new("http", host, port)
|
uri = Struct.new(:scheme, :hostname, :port).new("http", host, port)
|
||||||
assert_raise_with_message(SocketError, /#{host}:#{port}/) do
|
assert_raise_with_message(SocketError, /#{host}:#{port}/) do
|
||||||
clean_http_proxy_env{ Net::HTTP.get(uri) }
|
TestNetHTTPUtils.clean_http_proxy_env{ Net::HTTP.get(uri) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -68,17 +68,19 @@ class TestNetHTTPS < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_get_SNI_failure
|
def test_get_SNI_failure
|
||||||
http = Net::HTTP.new("invalid_servername", config("port"))
|
TestNetHTTPUtils.clean_http_proxy_env do
|
||||||
http.ipaddr = config('host')
|
http = Net::HTTP.new("invalid_servername", config("port"))
|
||||||
http.use_ssl = true
|
http.ipaddr = config('host')
|
||||||
http.cert_store = TEST_STORE
|
http.use_ssl = true
|
||||||
certs = []
|
http.cert_store = TEST_STORE
|
||||||
http.verify_callback = Proc.new do |preverify_ok, store_ctx|
|
certs = []
|
||||||
certs << store_ctx.current_cert
|
http.verify_callback = Proc.new do |preverify_ok, store_ctx|
|
||||||
preverify_ok
|
certs << store_ctx.current_cert
|
||||||
|
preverify_ok
|
||||||
|
end
|
||||||
|
@log_tester = lambda {|_| }
|
||||||
|
assert_raise(OpenSSL::SSL::SSLError){ http.start }
|
||||||
end
|
end
|
||||||
@log_tester = lambda {|_| }
|
|
||||||
assert_raise(OpenSSL::SSL::SSLError){ http.start }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_post
|
def test_post
|
||||||
|
|
|
@ -107,4 +107,23 @@ module TestNetHTTPUtils
|
||||||
def print(*args) end
|
def print(*args) end
|
||||||
def printf(*args) end
|
def printf(*args) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.clean_http_proxy_env
|
||||||
|
orig = {
|
||||||
|
'http_proxy' => ENV['http_proxy'],
|
||||||
|
'http_proxy_user' => ENV['http_proxy_user'],
|
||||||
|
'http_proxy_pass' => ENV['http_proxy_pass'],
|
||||||
|
'no_proxy' => ENV['no_proxy'],
|
||||||
|
}
|
||||||
|
|
||||||
|
orig.each_key do |key|
|
||||||
|
ENV.delete key
|
||||||
|
end
|
||||||
|
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
orig.each do |key, value|
|
||||||
|
ENV[key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue