httpi 2.0.0.rc1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,70 +0,0 @@
1
- require "webrick/https"
2
- require "logger"
3
- require "cgi"
4
-
5
- # https://github.com/asakusarb/odrk-http-client
6
- class SSLServer < WEBrick::HTTPServer
7
- DIR = File.dirname(__FILE__)
8
-
9
- def initialize(host, port)
10
- @logger = Logger.new($stderr)
11
- @logger.level = Logger::Severity::FATAL
12
-
13
- super(
14
- :BindAddress => host,
15
- :Logger => logger,
16
- :Port => port,
17
- :AccessLog => [],
18
- :DocumentRoot => DIR,
19
- :SSLEnable => true,
20
- :SSLCACertificateFile => File.join(DIR, "fixtures", "ca.pem"),
21
- :SSLCertificate => cert("server.cert"),
22
- :SSLPrivateKey => key("server.key"),
23
- :SSLVerifyClient => nil, #OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT|OpenSSL::SSL::VERIFY_PEER,
24
- :SSLClientCA => nil,
25
- :SSLCertName => nil
26
- )
27
-
28
- self.mount(
29
- "/hello",
30
- WEBrick::HTTPServlet::ProcHandler.new(method("do_hello").to_proc)
31
- )
32
-
33
- @server_thread = start_server_thread(self)
34
- end
35
-
36
- def shutdown
37
- super
38
- @server_thread.join if defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
39
- end
40
-
41
- private
42
-
43
- def cert(filename)
44
- OpenSSL::X509::Certificate.new File.read(File.join(DIR, "fixtures", filename))
45
- end
46
-
47
- def key(filename)
48
- OpenSSL::PKey::RSA.new File.read(File.join(DIR, "fixtures", filename))
49
- end
50
-
51
- def start_server_thread(server)
52
- t = Thread.new { server.start }
53
-
54
- while server.status != :Running
55
- Thread.pass
56
- unless t.alive?
57
- t.join
58
- raise
59
- end
60
- end
61
-
62
- t
63
- end
64
-
65
- def do_hello(req, res)
66
- res["Content-Type"] = "text/plain"
67
- res.body = "hello ssl"
68
- end
69
-
70
- end
@@ -1,102 +0,0 @@
1
- require "spec_helper"
2
- require "httpi"
3
- require "integration/ssl_server"
4
-
5
- describe "SSL authentication" do
6
-
7
- before :all do
8
- WebMock.allow_net_connect!
9
-
10
- @host = "localhost"
11
- @port = 17171
12
- @ssl_port = 17172
13
- @proxy_port = 17173
14
-
15
- @url = "http://#{@host}:#{@port}/"
16
- @ssl_url = "https://localhost:#{@ssl_port}/"
17
- @ssl_fake_url = "https://127.0.0.1:#{@ssl_port}/"
18
- @proxy_url = "http://#{@host}:#{@proxy_port}/"
19
-
20
- @ssl_server = SSLServer.new(@host, @ssl_port)
21
- end
22
-
23
- def teardown
24
- @ssl_server.shutdown if @ssl_server
25
- end
26
-
27
- HTTPI::Adapter::ADAPTERS.keys.each do |adapter|
28
- context "with #{adapter}" do
29
-
30
- if adapter == :em_http && RUBY_VERSION =~ /1\.8/
31
- # em_http depends on fibers
32
- elsif adapter == :curb && RUBY_PLATFORM =~ /java/
33
- # curb does not run on jruby
34
- elsif adapter == :em_http && RUBY_VERSION >= "1.9.0" && RUBY_PLATFORM =~ /java/
35
- it "fails for whatever reason"
36
- else
37
-
38
- if adapter == :em_http && RUBY_VERSION >= "1.9.0"
39
- # dependencies are loaded upon request, so we need to manually require this
40
- require "em-synchrony"
41
-
42
- around(:each) do |example|
43
- EM.synchrony do
44
- example.run
45
- EM.stop
46
- end
47
- end
48
- end
49
-
50
- # 105 ssl
51
- if adapter == :httpclient || adapter == :curb
52
- it "raises when no certificate was set up" do
53
- expect { HTTPI.post(@ssl_url + "hello", "", adapter) }.
54
- to raise_error(HTTPI::SSLError)
55
- end
56
- else
57
- if adapter == :net_http && RUBY_VERSION >= "1.9"
58
- it "raises in 1.9, but does not raise in 1.8"
59
- else
60
- it "does not raise when no certificate was set up" do
61
- expect { HTTPI.post(@ssl_url + "hello", "", adapter) }.
62
- to_not raise_error(HTTPI::SSLError)
63
- end
64
- end
65
- end
66
-
67
- # 106 ssl ca
68
- it "works when set up properly" do
69
- unless adapter == :em_http
70
- ca_file = File.expand_path("../fixtures/ca_all.pem", __FILE__)
71
- request = HTTPI::Request.new(@ssl_url + "hello")
72
- request.auth.ssl.ca_cert_file = ca_file
73
-
74
- response = HTTPI.get(request, adapter)
75
- expect(response.body).to eq("hello ssl")
76
- end
77
- end
78
-
79
- # 107 ssl hostname
80
- if adapter == :em_http
81
- it "raises when configured for ssl client auth" do
82
- ca_file = File.expand_path("../fixtures/ca_all.pem", __FILE__)
83
- request = HTTPI::Request.new(@ssl_fake_url + "hello")
84
- request.auth.ssl.ca_cert_file = ca_file
85
-
86
- expect { HTTPI.get(request, adapter) }.
87
- to raise_error(HTTPI::NotSupportedError, "EM-HTTP-Request does not support SSL client auth")
88
- end
89
- else
90
- it "raises when the server could not be verified" do
91
- ca_file = File.expand_path("../fixtures/ca_all.pem", __FILE__)
92
- request = HTTPI::Request.new(@ssl_fake_url + "hello")
93
- request.auth.ssl.ca_cert_file = ca_file
94
-
95
- expect { HTTPI.get(request, adapter) }.to raise_error(HTTPI::SSLError)
96
- end
97
- end
98
-
99
- end
100
- end
101
- end
102
- end