net-http-persistent 2.9.4 → 3.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.

Potentially problematic release.


This version of net-http-persistent might be problematic. Click here for more details.

@@ -1,112 +0,0 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'net/http/persistent'
4
- have_ssl =
5
- begin
6
- require 'openssl'
7
- require 'webrick'
8
- require 'webrick/ssl'
9
- true
10
- rescue LoadError
11
- false
12
- end
13
-
14
- ##
15
- # This test is based on (and contains verbatim code from) the Net::HTTP tests
16
- # in ruby
17
-
18
- class TestNetHttpPersistentSSLReuse < Minitest::Test
19
-
20
- class NullWriter
21
- def <<(s) end
22
- def puts(*args) end
23
- def print(*args) end
24
- def printf(*args) end
25
- end
26
-
27
- def setup
28
- @name = OpenSSL::X509::Name.parse 'CN=localhost/DC=localdomain'
29
-
30
- @key = OpenSSL::PKey::RSA.new 1024
31
-
32
- @cert = OpenSSL::X509::Certificate.new
33
- @cert.version = 2
34
- @cert.serial = 0
35
- @cert.not_before = Time.now
36
- @cert.not_after = Time.now + 300
37
- @cert.public_key = @key.public_key
38
- @cert.subject = @name
39
- @cert.issuer = @name
40
-
41
- @cert.sign @key, OpenSSL::Digest::SHA1.new
42
-
43
- @host = 'localhost'
44
- @port = 10082
45
-
46
- config = {
47
- :BindAddress => @host,
48
- :Port => @port,
49
- :Logger => WEBrick::Log.new(NullWriter.new),
50
- :AccessLog => [],
51
- :ShutDownSocketWithoutClose => true,
52
- :ServerType => Thread,
53
- :SSLEnable => true,
54
- :SSLCertificate => @cert,
55
- :SSLPrivateKey => @key,
56
- :SSLStartImmediately => true,
57
- }
58
-
59
- @server = WEBrick::HTTPServer.new config
60
-
61
- @server.mount_proc '/' do |req, res|
62
- res.body = "ok"
63
- end
64
-
65
- @server.start
66
-
67
- begin
68
- TCPSocket.open(@host, @port).close
69
- rescue Errno::ECONNREFUSED
70
- sleep 0.2
71
- n_try_max -= 1
72
- raise 'cannot spawn server; give up' if n_try_max < 0
73
- retry
74
- end
75
- end
76
-
77
- def teardown
78
- if @server then
79
- @server.shutdown
80
- sleep 0.01 until @server.status == :Stop
81
- end
82
- end
83
-
84
- def test_ssl_connection_reuse
85
- store = OpenSSL::X509::Store.new
86
- store.add_cert @cert
87
-
88
- @http = Net::HTTP::Persistent::SSLReuse.new @host, @port
89
- @http.cert_store = store
90
- @http.ssl_version = :SSLv3 if @http.respond_to? :ssl_version=
91
- @http.use_ssl = true
92
- @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
93
-
94
- @http.start
95
- @http.get '/'
96
- @http.finish
97
-
98
- @http.start
99
- @http.get '/'
100
- @http.finish
101
-
102
- @http.start
103
- @http.get '/'
104
-
105
- socket = @http.instance_variable_get :@socket
106
- ssl_socket = socket.io
107
-
108
- assert ssl_socket.session_reused?
109
- end
110
-
111
- end if have_ssl
112
-