1begin
2  require 'net/https'
3rescue LoadError
4end
5require 'test/unit'
6
7class HTTPSProxyTest < Test::Unit::TestCase
8  def test_https_proxy_authentication
9    begin
10      OpenSSL
11    rescue LoadError
12      skip 'autoload problem. see [ruby-dev:45021][Bug #5786]'
13    end
14
15    t = nil
16    TCPServer.open("127.0.0.1", 0) {|serv|
17      _, port, _, _ = serv.addr
18      t = Thread.new {
19        proxy = Net::HTTP.Proxy("127.0.0.1", port, 'user', 'password')
20        http = proxy.new("foo.example.org", 8000)
21        http.use_ssl = true
22        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
23        begin
24          http.start
25        rescue EOFError
26        end
27      }
28      sock = serv.accept
29      proxy_request = sock.gets("\r\n\r\n")
30      assert_equal(
31        "CONNECT foo.example.org:8000 HTTP/1.1\r\n" +
32        "Host: foo.example.org:8000\r\n" +
33        "Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==\r\n" +
34        "\r\n",
35        proxy_request,
36        "[ruby-dev:25673]")
37      sock.close
38    }
39  ensure
40    t.join if t
41  end
42end if defined?(OpenSSL)
43
44