2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2007-12-31 09:17:41 -05:00
|
|
|
require "test/unit"
|
|
|
|
require "net/http"
|
|
|
|
require "webrick"
|
|
|
|
require "webrick/httpproxy"
|
|
|
|
begin
|
|
|
|
require "webrick/ssl"
|
|
|
|
require "net/https"
|
|
|
|
rescue LoadError
|
|
|
|
# test_connect will be skipped
|
|
|
|
end
|
|
|
|
require File.expand_path("utils.rb", File.dirname(__FILE__))
|
|
|
|
|
|
|
|
class TestWEBrickHTTPProxy < Test::Unit::TestCase
|
2016-01-05 01:09:17 -05:00
|
|
|
def teardown
|
|
|
|
WEBrick::Utils::TimeoutHandler.terminate
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2007-12-31 09:17:41 -05:00
|
|
|
def test_fake_proxy
|
|
|
|
assert_nil(WEBrick::FakeProxyURI.scheme)
|
|
|
|
assert_nil(WEBrick::FakeProxyURI.host)
|
|
|
|
assert_nil(WEBrick::FakeProxyURI.port)
|
|
|
|
assert_nil(WEBrick::FakeProxyURI.path)
|
|
|
|
assert_nil(WEBrick::FakeProxyURI.userinfo)
|
|
|
|
assert_raise(NoMethodError){ WEBrick::FakeProxyURI.foo }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_proxy
|
|
|
|
# Testing GET or POST to the proxy server
|
|
|
|
# Note that the proxy server works as the origin server.
|
|
|
|
# +------+
|
2009-03-05 22:56:38 -05:00
|
|
|
# V |
|
2007-12-31 09:17:41 -05:00
|
|
|
# client -------> proxy ---+
|
|
|
|
# GET / POST GET / POST
|
|
|
|
#
|
|
|
|
proxy_handler_called = request_handler_called = 0
|
|
|
|
config = {
|
|
|
|
:ServerName => "localhost.localdomain",
|
|
|
|
:ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1 },
|
2011-01-11 19:37:12 -05:00
|
|
|
:RequestCallback => Proc.new{|req, res| request_handler_called += 1 }
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
TestWEBrick.start_httpproxy(config){|server, addr, port, log|
|
2007-12-31 09:17:41 -05:00
|
|
|
server.mount_proc("/"){|req, res|
|
|
|
|
res.body = "#{req.request_method} #{req.path} #{req.body}"
|
|
|
|
}
|
|
|
|
http = Net::HTTP.new(addr, port, addr, port)
|
|
|
|
|
|
|
|
req = Net::HTTP::Get.new("/")
|
|
|
|
http.request(req){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call)
|
|
|
|
assert_equal("GET / ", res.body, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(1, proxy_handler_called, log.call)
|
|
|
|
assert_equal(2, request_handler_called, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
|
|
|
req = Net::HTTP::Head.new("/")
|
|
|
|
http.request(req){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call)
|
|
|
|
assert_nil(res.body, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(2, proxy_handler_called, log.call)
|
|
|
|
assert_equal(4, request_handler_called, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
|
|
|
req = Net::HTTP::Post.new("/")
|
|
|
|
req.body = "post-data"
|
2018-08-07 09:08:53 -04:00
|
|
|
req.content_type = "application/x-www-form-urlencoded"
|
2007-12-31 09:17:41 -05:00
|
|
|
http.request(req){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call)
|
|
|
|
assert_equal("POST / post-data", res.body, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(3, proxy_handler_called, log.call)
|
|
|
|
assert_equal(6, request_handler_called, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_proxy
|
|
|
|
# Testing GET or POST to the proxy server without proxy request.
|
|
|
|
#
|
|
|
|
# client -------> proxy
|
|
|
|
# GET / POST
|
|
|
|
#
|
|
|
|
proxy_handler_called = request_handler_called = 0
|
|
|
|
config = {
|
|
|
|
:ServerName => "localhost.localdomain",
|
|
|
|
:ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1 },
|
2011-01-11 19:37:12 -05:00
|
|
|
:RequestCallback => Proc.new{|req, res| request_handler_called += 1 }
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
TestWEBrick.start_httpproxy(config){|server, addr, port, log|
|
2007-12-31 09:17:41 -05:00
|
|
|
server.mount_proc("/"){|req, res|
|
|
|
|
res.body = "#{req.request_method} #{req.path} #{req.body}"
|
|
|
|
}
|
|
|
|
http = Net::HTTP.new(addr, port)
|
|
|
|
|
|
|
|
req = Net::HTTP::Get.new("/")
|
|
|
|
http.request(req){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_nil(res["via"], log.call)
|
|
|
|
assert_equal("GET / ", res.body, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(0, proxy_handler_called, log.call)
|
|
|
|
assert_equal(1, request_handler_called, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
|
|
|
req = Net::HTTP::Head.new("/")
|
|
|
|
http.request(req){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_nil(res["via"], log.call)
|
|
|
|
assert_nil(res.body, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(0, proxy_handler_called, log.call)
|
|
|
|
assert_equal(2, request_handler_called, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
|
|
|
req = Net::HTTP::Post.new("/")
|
2018-08-07 09:08:53 -04:00
|
|
|
req.content_type = "application/x-www-form-urlencoded"
|
2007-12-31 09:17:41 -05:00
|
|
|
req.body = "post-data"
|
|
|
|
http.request(req){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_nil(res["via"], log.call)
|
|
|
|
assert_equal("POST / post-data", res.body, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(0, proxy_handler_called, log.call)
|
|
|
|
assert_equal(3, request_handler_called, log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-04-03 06:22:45 -04:00
|
|
|
def test_big_bodies
|
|
|
|
require 'digest/md5'
|
|
|
|
rand_str = File.read(__FILE__)
|
|
|
|
rand_str.freeze
|
|
|
|
nr = 1024 ** 2 / rand_str.size # bigger works, too
|
|
|
|
exp = Digest::MD5.new
|
|
|
|
nr.times { exp.update(rand_str) }
|
|
|
|
exp = exp.hexdigest
|
|
|
|
TestWEBrick.start_httpserver do |o_server, o_addr, o_port, o_log|
|
|
|
|
o_server.mount_proc('/') do |req, res|
|
|
|
|
case req.request_method
|
|
|
|
when 'GET'
|
|
|
|
res['content-type'] = 'application/octet-stream'
|
|
|
|
if req.path == '/length'
|
|
|
|
res['content-length'] = (nr * rand_str.size).to_s
|
|
|
|
else
|
|
|
|
res.chunked = true
|
|
|
|
end
|
|
|
|
res.body = ->(socket) { nr.times { socket.write(rand_str) } }
|
|
|
|
when 'POST'
|
|
|
|
dig = Digest::MD5.new
|
|
|
|
req.body { |buf| dig.update(buf); buf.clear }
|
|
|
|
res['content-type'] = 'text/plain'
|
|
|
|
res['content-length'] = '32'
|
|
|
|
res.body = dig.hexdigest
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
http = Net::HTTP.new(o_addr, o_port)
|
|
|
|
IO.pipe do |rd, wr|
|
|
|
|
headers = {
|
|
|
|
'Content-Type' => 'application/octet-stream',
|
|
|
|
'Transfer-Encoding' => 'chunked',
|
|
|
|
}
|
|
|
|
post = Net::HTTP::Post.new('/', headers)
|
|
|
|
th = Thread.new { nr.times { wr.write(rand_str) }; wr.close }
|
|
|
|
post.body_stream = rd
|
|
|
|
http.request(post) do |res|
|
|
|
|
assert_equal 'text/plain', res['content-type']
|
|
|
|
assert_equal 32, res.content_length
|
|
|
|
assert_equal exp, res.body
|
|
|
|
end
|
|
|
|
assert_nil th.value
|
|
|
|
end
|
|
|
|
|
|
|
|
TestWEBrick.start_httpproxy do |p_server, p_addr, p_port, p_log|
|
|
|
|
http = Net::HTTP.new(o_addr, o_port, p_addr, p_port)
|
|
|
|
http.request_get('/length') do |res|
|
|
|
|
assert_equal(nr * rand_str.size, res.content_length)
|
|
|
|
dig = Digest::MD5.new
|
|
|
|
res.read_body { |buf| dig.update(buf); buf.clear }
|
|
|
|
assert_equal exp, dig.hexdigest
|
|
|
|
end
|
|
|
|
http.request_get('/') do |res|
|
|
|
|
assert_predicate res, :chunked?
|
|
|
|
dig = Digest::MD5.new
|
|
|
|
res.read_body { |buf| dig.update(buf); buf.clear }
|
|
|
|
assert_equal exp, dig.hexdigest
|
|
|
|
end
|
|
|
|
|
|
|
|
IO.pipe do |rd, wr|
|
|
|
|
headers = {
|
|
|
|
'Content-Type' => 'application/octet-stream',
|
|
|
|
'Content-Length' => (nr * rand_str.size).to_s,
|
|
|
|
}
|
|
|
|
post = Net::HTTP::Post.new('/', headers)
|
|
|
|
th = Thread.new { nr.times { wr.write(rand_str) }; wr.close }
|
|
|
|
post.body_stream = rd
|
|
|
|
http.request(post) do |res|
|
|
|
|
assert_equal 'text/plain', res['content-type']
|
|
|
|
assert_equal 32, res.content_length
|
|
|
|
assert_equal exp, res.body
|
|
|
|
end
|
|
|
|
assert_nil th.value
|
|
|
|
end
|
|
|
|
|
|
|
|
IO.pipe do |rd, wr|
|
|
|
|
headers = {
|
|
|
|
'Content-Type' => 'application/octet-stream',
|
|
|
|
'Transfer-Encoding' => 'chunked',
|
|
|
|
}
|
|
|
|
post = Net::HTTP::Post.new('/', headers)
|
|
|
|
th = Thread.new { nr.times { wr.write(rand_str) }; wr.close }
|
|
|
|
post.body_stream = rd
|
|
|
|
http.request(post) do |res|
|
|
|
|
assert_equal 'text/plain', res['content-type']
|
|
|
|
assert_equal 32, res.content_length
|
|
|
|
assert_equal exp, res.body
|
|
|
|
end
|
|
|
|
assert_nil th.value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-12-31 09:17:41 -05:00
|
|
|
def make_certificate(key, cn)
|
|
|
|
subject = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=#{cn}")
|
|
|
|
exts = [
|
|
|
|
["keyUsage", "keyEncipherment,digitalSignature", true],
|
|
|
|
]
|
2016-11-29 10:48:47 -05:00
|
|
|
cert = OpenSSL::X509::Certificate.new
|
|
|
|
cert.version = 2
|
|
|
|
cert.serial = 1
|
|
|
|
cert.subject = subject
|
|
|
|
cert.issuer = subject
|
|
|
|
cert.public_key = key
|
|
|
|
cert.not_before = Time.now - 3600
|
|
|
|
cert.not_after = Time.now + 3600
|
|
|
|
ef = OpenSSL::X509::ExtensionFactory.new(cert, cert)
|
|
|
|
exts.each {|args| cert.add_extension(ef.create_extension(*args)) }
|
|
|
|
cert.sign(key, "sha1")
|
2007-12-31 09:17:41 -05:00
|
|
|
return cert
|
2016-11-29 10:48:47 -05:00
|
|
|
end if defined?(OpenSSL::SSL)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
|
|
|
def test_connect
|
|
|
|
# Testing CONNECT to proxy server
|
|
|
|
#
|
|
|
|
# client -----------> proxy -----------> https
|
|
|
|
# 1. CONNECT establish TCP
|
|
|
|
# 2. ---- establish SSL session --->
|
|
|
|
# 3. ------- GET or POST ---------->
|
|
|
|
#
|
2016-11-29 10:48:47 -05:00
|
|
|
key = TEST_KEY_RSA2048
|
2007-12-31 09:17:41 -05:00
|
|
|
cert = make_certificate(key, "127.0.0.1")
|
|
|
|
s_config = {
|
|
|
|
:SSLEnable =>true,
|
|
|
|
:ServerName => "localhost",
|
|
|
|
:SSLCertificate => cert,
|
|
|
|
:SSLPrivateKey => key,
|
|
|
|
}
|
|
|
|
config = {
|
|
|
|
:ServerName => "localhost.localdomain",
|
2011-01-11 19:37:12 -05:00
|
|
|
:RequestCallback => Proc.new{|req, res|
|
2007-12-31 09:17:41 -05:00
|
|
|
assert_equal("CONNECT", req.request_method)
|
|
|
|
},
|
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port, s_log|
|
2007-12-31 09:17:41 -05:00
|
|
|
s_server.mount_proc("/"){|req, res|
|
|
|
|
res.body = "SSL #{req.request_method} #{req.path} #{req.body}"
|
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
TestWEBrick.start_httpproxy(config){|server, addr, port, log|
|
2007-12-31 09:17:41 -05:00
|
|
|
http = Net::HTTP.new("127.0.0.1", s_port, addr, port)
|
|
|
|
http.use_ssl = true
|
|
|
|
http.verify_callback = Proc.new do |preverify_ok, store_ctx|
|
|
|
|
store_ctx.current_cert.to_der == cert.to_der
|
|
|
|
end
|
|
|
|
|
|
|
|
req = Net::HTTP::Get.new("/")
|
2013-04-02 02:28:13 -04:00
|
|
|
req["Content-Type"] = "application/x-www-form-urlencoded"
|
2007-12-31 09:17:41 -05:00
|
|
|
http.request(req){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal("SSL GET / ", res.body, s_log.call + log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
req = Net::HTTP::Post.new("/")
|
2013-04-02 02:28:13 -04:00
|
|
|
req["Content-Type"] = "application/x-www-form-urlencoded"
|
2007-12-31 09:17:41 -05:00
|
|
|
req.body = "post-data"
|
|
|
|
http.request(req){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal("SSL POST / post-data", res.body, s_log.call + log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-29 10:48:47 -05:00
|
|
|
end if defined?(OpenSSL::SSL)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
|
|
|
def test_upstream_proxy
|
|
|
|
# Testing GET or POST through the upstream proxy server
|
|
|
|
# Note that the upstream proxy server works as the origin server.
|
|
|
|
# +------+
|
2009-03-05 22:56:38 -05:00
|
|
|
# V |
|
2007-12-31 09:17:41 -05:00
|
|
|
# client -------> proxy -------> proxy ---+
|
|
|
|
# GET / POST GET / POST GET / POST
|
|
|
|
#
|
|
|
|
up_proxy_handler_called = up_request_handler_called = 0
|
|
|
|
proxy_handler_called = request_handler_called = 0
|
|
|
|
up_config = {
|
|
|
|
:ServerName => "localhost.localdomain",
|
|
|
|
:ProxyContentHandler => Proc.new{|req, res| up_proxy_handler_called += 1},
|
2011-01-11 19:37:12 -05:00
|
|
|
:RequestCallback => Proc.new{|req, res| up_request_handler_called += 1}
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
TestWEBrick.start_httpproxy(up_config){|up_server, up_addr, up_port, up_log|
|
2007-12-31 09:17:41 -05:00
|
|
|
up_server.mount_proc("/"){|req, res|
|
|
|
|
res.body = "#{req.request_method} #{req.path} #{req.body}"
|
|
|
|
}
|
|
|
|
config = {
|
|
|
|
:ServerName => "localhost.localdomain",
|
|
|
|
:ProxyURI => URI.parse("http://localhost:#{up_port}"),
|
|
|
|
:ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1},
|
2011-01-11 19:37:12 -05:00
|
|
|
:RequestCallback => Proc.new{|req, res| request_handler_called += 1},
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
TestWEBrick.start_httpproxy(config){|server, addr, port, log|
|
2007-12-31 09:17:41 -05:00
|
|
|
http = Net::HTTP.new(up_addr, up_port, addr, port)
|
|
|
|
|
|
|
|
req = Net::HTTP::Get.new("/")
|
|
|
|
http.request(req){|res|
|
2010-10-01 04:04:37 -04:00
|
|
|
skip res.message unless res.code == '200'
|
2007-12-31 09:17:41 -05:00
|
|
|
via = res["via"].split(/,\s+/)
|
2008-10-29 07:48:35 -04:00
|
|
|
assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call)
|
|
|
|
assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
assert_equal("GET / ", res.body)
|
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(1, up_proxy_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(2, up_request_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(1, proxy_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(1, request_handler_called, up_log.call + log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
|
|
|
req = Net::HTTP::Head.new("/")
|
|
|
|
http.request(req){|res|
|
|
|
|
via = res["via"].split(/,\s+/)
|
2008-10-29 07:48:35 -04:00
|
|
|
assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call)
|
|
|
|
assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call)
|
|
|
|
assert_nil(res.body, up_log.call + log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(2, up_proxy_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(4, up_request_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(2, proxy_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(2, request_handler_called, up_log.call + log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
|
|
|
req = Net::HTTP::Post.new("/")
|
|
|
|
req.body = "post-data"
|
2018-08-07 09:08:53 -04:00
|
|
|
req.content_type = "application/x-www-form-urlencoded"
|
2007-12-31 09:17:41 -05:00
|
|
|
http.request(req){|res|
|
|
|
|
via = res["via"].split(/,\s+/)
|
2008-10-29 07:48:35 -04:00
|
|
|
assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call)
|
|
|
|
assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call)
|
|
|
|
assert_equal("POST / post-data", res.body, up_log.call + log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal(3, up_proxy_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(6, up_request_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(3, proxy_handler_called, up_log.call + log.call)
|
|
|
|
assert_equal(3, request_handler_called, up_log.call + log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
|
2016-11-29 10:48:47 -05:00
|
|
|
if defined?(OpenSSL::SSL)
|
2007-12-31 09:17:41 -05:00
|
|
|
# Testing CONNECT to the upstream proxy server
|
|
|
|
#
|
|
|
|
# client -------> proxy -------> proxy -------> https
|
|
|
|
# 1. CONNECT CONNECT establish TCP
|
|
|
|
# 2. -------- establish SSL session ------>
|
|
|
|
# 3. ---------- GET or POST -------------->
|
|
|
|
#
|
2016-11-29 10:48:47 -05:00
|
|
|
key = TEST_KEY_RSA2048
|
2007-12-31 09:17:41 -05:00
|
|
|
cert = make_certificate(key, "127.0.0.1")
|
|
|
|
s_config = {
|
|
|
|
:SSLEnable =>true,
|
|
|
|
:ServerName => "localhost",
|
|
|
|
:SSLCertificate => cert,
|
|
|
|
:SSLPrivateKey => key,
|
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port, s_log|
|
2010-01-25 18:12:50 -05:00
|
|
|
s_server.mount_proc("/"){|req2, res|
|
|
|
|
res.body = "SSL #{req2.request_method} #{req2.path} #{req2.body}"
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
2008-10-29 07:48:35 -04:00
|
|
|
http = Net::HTTP.new("127.0.0.1", s_port, addr, port, up_log.call + log.call + s_log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
http.use_ssl = true
|
|
|
|
http.verify_callback = Proc.new do |preverify_ok, store_ctx|
|
|
|
|
store_ctx.current_cert.to_der == cert.to_der
|
|
|
|
end
|
|
|
|
|
2010-01-25 18:12:50 -05:00
|
|
|
req2 = Net::HTTP::Get.new("/")
|
|
|
|
http.request(req2){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal("SSL GET / ", res.body, up_log.call + log.call + s_log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
|
|
|
|
2010-01-25 18:12:50 -05:00
|
|
|
req2 = Net::HTTP::Post.new("/")
|
|
|
|
req2.body = "post-data"
|
2018-08-07 09:08:53 -04:00
|
|
|
req2.content_type = "application/x-www-form-urlencoded"
|
2010-01-25 18:12:50 -05:00
|
|
|
http.request(req2){|res|
|
2008-10-29 07:48:35 -04:00
|
|
|
assert_equal("SSL POST / post-data", res.body, up_log.call + log.call + s_log.call)
|
2007-12-31 09:17:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2016-11-29 10:48:47 -05:00
|
|
|
|
|
|
|
if defined?(OpenSSL::SSL)
|
|
|
|
TEST_KEY_RSA2048 = OpenSSL::PKey.read <<-_end_of_pem_
|
|
|
|
-----BEGIN RSA PRIVATE KEY-----
|
|
|
|
MIIEpAIBAAKCAQEAuV9ht9J7k4NBs38jOXvvTKY9gW8nLICSno5EETR1cuF7i4pN
|
|
|
|
s9I1QJGAFAX0BEO4KbzXmuOvfCpD3CU+Slp1enenfzq/t/e/1IRW0wkJUJUFQign
|
|
|
|
4CtrkJL+P07yx18UjyPlBXb81ApEmAB5mrJVSrWmqbjs07JbuS4QQGGXLc+Su96D
|
|
|
|
kYKmSNVjBiLxVVSpyZfAY3hD37d60uG+X8xdW5v68JkRFIhdGlb6JL8fllf/A/bl
|
|
|
|
NwdJOhVr9mESHhwGjwfSeTDPf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