1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

webrick: don't use OpenSSL::TestUtils from webrick tests

Follow net/http and open-uri. Don't rely on the constants/methods from
OpenSSL::TestUtils.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
rhe 2016-11-29 15:48:47 +00:00
parent 0cc0080a49
commit db31f2fafb

View file

@ -6,7 +6,6 @@ require "webrick/httpproxy"
begin begin
require "webrick/ssl" require "webrick/ssl"
require "net/https" require "net/https"
require File.expand_path("../openssl/utils.rb", File.dirname(__FILE__))
rescue LoadError rescue LoadError
# test_connect will be skipped # test_connect will be skipped
end end
@ -124,12 +123,19 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
exts = [ exts = [
["keyUsage", "keyEncipherment,digitalSignature", true], ["keyUsage", "keyEncipherment,digitalSignature", true],
] ]
cert = OpenSSL::TestUtils.issue_cert( cert = OpenSSL::X509::Certificate.new
subject, key, 1, Time.now, Time.now + 3600, exts, cert.version = 2
nil, nil, OpenSSL::Digest::SHA1.new cert.serial = 1
) cert.subject = subject
cert.issuer = subject
cert.public_key = key
cert.not_before = Time.now - 3600
cert.not_after = Time.now + 3600
ef = OpenSSL::X509::ExtensionFactory.new(cert, cert)
exts.each {|args| cert.add_extension(ef.create_extension(*args)) }
cert.sign(key, "sha1")
return cert return cert
end if defined?(OpenSSL::TestUtils) end if defined?(OpenSSL::SSL)
def test_connect def test_connect
# Testing CONNECT to proxy server # Testing CONNECT to proxy server
@ -139,7 +145,7 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
# 2. ---- establish SSL session ---> # 2. ---- establish SSL session --->
# 3. ------- GET or POST ----------> # 3. ------- GET or POST ---------->
# #
key = OpenSSL::TestUtils::TEST_KEY_RSA1024 key = TEST_KEY_RSA2048
cert = make_certificate(key, "127.0.0.1") cert = make_certificate(key, "127.0.0.1")
s_config = { s_config = {
:SSLEnable =>true, :SSLEnable =>true,
@ -178,7 +184,7 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
} }
} }
} }
end if defined?(OpenSSL::TestUtils) end if defined?(OpenSSL::SSL)
def test_upstream_proxy def test_upstream_proxy
# Testing GET or POST through the upstream proxy server # Testing GET or POST through the upstream proxy server
@ -246,7 +252,7 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
assert_equal(3, proxy_handler_called, up_log.call + log.call) assert_equal(3, proxy_handler_called, up_log.call + log.call)
assert_equal(3, request_handler_called, up_log.call + log.call) assert_equal(3, request_handler_called, up_log.call + log.call)
if defined?(OpenSSL::TestUtils) if defined?(OpenSSL::SSL)
# Testing CONNECT to the upstream proxy server # Testing CONNECT to the upstream proxy server
# #
# client -------> proxy -------> proxy -------> https # client -------> proxy -------> proxy -------> https
@ -254,7 +260,7 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
# 2. -------- establish SSL session ------> # 2. -------- establish SSL session ------>
# 3. ---------- GET or POST --------------> # 3. ---------- GET or POST -------------->
# #
key = OpenSSL::TestUtils::TEST_KEY_RSA1024 key = TEST_KEY_RSA2048
cert = make_certificate(key, "127.0.0.1") cert = make_certificate(key, "127.0.0.1")
s_config = { s_config = {
:SSLEnable =>true, :SSLEnable =>true,
@ -287,4 +293,36 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
} }
} }
end end
if defined?(OpenSSL::SSL)
TEST_KEY_RSA2048 = OpenSSL::PKey.read <<-_end_of_pem_
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAuV9ht9J7k4NBs38jOXvvTKY9gW8nLICSno5EETR1cuF7i4pN
s9I1QJGAFAX0BEO4KbzXmuOvfCpD3CU+Slp1enenfzq/t/e/1IRW0wkJUJUFQign
4CtrkJL+P07yx18UjyPlBXb81ApEmAB5mrJVSrWmqbjs07JbuS4QQGGXLc+Su96D
kYKmSNVjBiLxVVSpyZfAY3hD37d60uG+X8xdW5v68JkRFIhdGlb6JL8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