2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2005-06-06 22:49:16 -04:00
|
|
|
begin
|
|
|
|
require 'net/https'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2005-06-03 12:11:40 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class HTTPSProxyTest < Test::Unit::TestCase
|
|
|
|
def test_https_proxy_authentication
|
2012-02-02 10:55:07 -05:00
|
|
|
begin
|
|
|
|
OpenSSL
|
|
|
|
rescue LoadError
|
|
|
|
skip 'autoload problem. see [ruby-dev:45021][Bug #5786]'
|
|
|
|
end
|
|
|
|
|
2005-06-03 16:40:39 -04:00
|
|
|
TCPServer.open("127.0.0.1", 0) {|serv|
|
2005-06-03 14:03:52 -04:00
|
|
|
_, port, _, _ = serv.addr
|
2014-11-11 08:08:01 -05:00
|
|
|
client_thread = Thread.new {
|
2005-06-03 14:03:52 -04:00
|
|
|
proxy = Net::HTTP.Proxy("127.0.0.1", port, 'user', 'password')
|
2005-06-03 12:11:40 -04:00
|
|
|
http = proxy.new("foo.example.org", 8000)
|
|
|
|
http.use_ssl = true
|
2005-06-03 12:49:56 -04:00
|
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
2007-12-15 06:12:20 -05:00
|
|
|
begin
|
|
|
|
http.start
|
|
|
|
rescue EOFError
|
|
|
|
end
|
2005-06-03 12:11:40 -04:00
|
|
|
}
|
2014-11-11 08:08:01 -05:00
|
|
|
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-dev:25673]")
|
|
|
|
ensure
|
|
|
|
sock.close
|
|
|
|
end
|
|
|
|
}
|
|
|
|
assert_join_threads([client_thread, server_thread])
|
2005-06-03 12:11:40 -04:00
|
|
|
}
|
|
|
|
end
|
2005-06-06 22:49:16 -04:00
|
|
|
end if defined?(OpenSSL)
|
2009-03-05 22:56:38 -05:00
|
|
|
|