OSDN Git Service

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