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
|
|
|
|
|
2007-11-14 02:17:18 -05:00
|
|
|
t = nil
|
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
|
2005-06-03 12:11:40 -04:00
|
|
|
t = 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
|
|
|
}
|
|
|
|
sock = serv.accept
|
|
|
|
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",
|
2005-06-03 13:14:06 -04:00
|
|
|
proxy_request,
|
|
|
|
"[ruby-dev:25673]")
|
2007-12-15 06:04:30 -05:00
|
|
|
sock.close
|
2005-06-03 12:11:40 -04:00
|
|
|
}
|
2007-11-14 02:17:18 -05:00
|
|
|
ensure
|
2007-12-15 06:12:20 -05:00
|
|
|
t.join if t
|
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
|
|
|
|