mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_ssl_server.rb: assert_self_signed_cert
* test/webrick/test_ssl_server.rb (assert_self_signed_cert): extract common assertion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2cb362b51f
commit
4a46404a71
1 changed files with 9 additions and 13 deletions
|
@ -13,24 +13,20 @@ class TestWEBrickSSLServer < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_self_signed_cert_server
|
def test_self_signed_cert_server
|
||||||
config = {
|
assert_self_signed_cert(
|
||||||
:SSLEnable => true,
|
:SSLEnable => true,
|
||||||
:SSLCertName => [["C", "JP"], ["O", "www.ruby-lang.org"], ["CN", "Ruby"]]
|
:SSLCertName => [["C", "JP"], ["O", "www.ruby-lang.org"], ["CN", "Ruby"]],
|
||||||
}
|
)
|
||||||
TestWEBrick.start_server(Echo, config){|server, addr, port, log|
|
|
||||||
sock = OpenSSL::SSL::SSLSocket.new(TCPSocket.new(addr, port))
|
|
||||||
sock.connect
|
|
||||||
sock.puts(server.ssl_context.cert.subject.to_s)
|
|
||||||
assert_equal("/C=JP/O=www.ruby-lang.org/CN=Ruby\n", sock.gets, log.call)
|
|
||||||
sock.close
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_self_signed_cert_server_with_string
|
def test_self_signed_cert_server_with_string
|
||||||
config = {
|
assert_self_signed_cert(
|
||||||
:SSLEnable => true,
|
:SSLEnable => true,
|
||||||
:SSLCertName => "/C=JP/O=www.ruby-lang.org/CN=Ruby"
|
:SSLCertName => "/C=JP/O=www.ruby-lang.org/CN=Ruby",
|
||||||
}
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_self_signed_cert(config)
|
||||||
TestWEBrick.start_server(Echo, config){|server, addr, port, log|
|
TestWEBrick.start_server(Echo, config){|server, addr, port, log|
|
||||||
sock = OpenSSL::SSL::SSLSocket.new(TCPSocket.new(addr, port))
|
sock = OpenSSL::SSL::SSLSocket.new(TCPSocket.new(addr, port))
|
||||||
sock.connect
|
sock.connect
|
||||||
|
|
Loading…
Add table
Reference in a new issue