summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEvgeni Golov <[email protected]>2022-05-09 15:04:01 +0200
committergit <[email protected]>2024-07-11 01:56:08 +0000
commitbc1b4235fb0b859122ae15b865bf1a15e7d2050f (patch)
tree736d7fcba7fa470a3d558fecbef6b047cfb91350 /test
parent70bdc0f777f9c2fe7bcee8bbab7b510589c28f93 (diff)
[ruby/net-http] implement talking SSL to the proxy too
https://bugs.ruby-lang.org/issues/16482 https://github.com/ruby/net-http/commit/ae2d83f88b
Diffstat (limited to 'test')
-rw-r--r--test/net/http/test_https_proxy.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/net/http/test_https_proxy.rb b/test/net/http/test_https_proxy.rb
index 4c2a92ccd6..d7da0cef13 100644
--- a/test/net/http/test_https_proxy.rb
+++ b/test/net/http/test_https_proxy.rb
@@ -43,5 +43,53 @@ class HTTPSProxyTest < Test::Unit::TestCase
assert_join_threads([client_thread, server_thread])
}
end
+
+ def test_https_proxy_ssl_connection
+ begin
+ OpenSSL
+ rescue LoadError
+ omit 'autoload problem. see [ruby-dev:45021][Bug #5786]'
+ end
+
+ tcpserver = TCPServer.new("127.0.0.1", 0)
+ ctx = OpenSSL::SSL::SSLContext.new
+ ctx.key = OpenSSL::PKey::RSA.new 2048
+ ctx.cert = OpenSSL::X509::Certificate.new
+ ctx.cert.subject = OpenSSL::X509::Name.new [['CN', 'localhost']]
+ ctx.cert.issuer = ctx.cert.subject
+ ctx.cert.public_key = ctx.key
+ ctx.cert.not_before = Time.now
+ ctx.cert.not_after = Time.now + 60 * 60 * 24
+ ctx.cert.sign ctx.key, OpenSSL::Digest::SHA1.new
+ serv = OpenSSL::SSL::SSLServer.new(tcpserver, ctx)
+
+ _, port, _, _ = serv.addr
+ client_thread = Thread.new {
+ proxy = Net::HTTP.Proxy("127.0.0.1", port, 'user', 'password', true)
+ http = proxy.new("foo.example.org", 8000)
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ begin
+ http.start
+ rescue EOFError
+ end
+ }
+ server_thread = Thread.new {
+ sock = serv.accept
+ begin
+ proxy_request = sock.gets("\r\n\r\n")
+ assert_equal(
+ "CONNECT foo.example.org:8000 HTTP/1.1\r\n" +
+ "Host: foo.example.org:8000\r\n" +
+ "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==\r\n" +
+ "\r\n",
+ proxy_request,
+ "[ruby-core:96672]")
+ ensure
+ sock.close
+ end
+ }
+ assert_join_threads([client_thread, server_thread])
+ end
end if defined?(OpenSSL)