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