summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-17 08:04:19 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-17 08:04:19 +0000
commit3691ea5cf42b333a8607df1d2f6d9e22d747d5a1 (patch)
treedb2155a4df5af607c65554f1928ad1a825e7713f
parent9c1e33fc452bfc545eac51a8579d4f3a7f7872b8 (diff)
* test/openssl/ssl_server.rb: try to listen ports from 20443 to 20542
while failed in getting a TCPServer. * test/openssl/test_x509name.rb: remove version dependence about nickname of OIDs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/openssl/ssl_server.rb12
-rw-r--r--test/openssl/test_ssl.rb30
-rw-r--r--test/openssl/test_x509name.rb35
3 files changed, 39 insertions, 38 deletions
diff --git a/test/openssl/ssl_server.rb b/test/openssl/ssl_server.rb
index 699a181256..5e1303379f 100644
--- a/test/openssl/ssl_server.rb
+++ b/test/openssl/ssl_server.rb
@@ -46,12 +46,22 @@ ctx.key = ssl_key
ctx.verify_mode = verify_mode
Socket.do_not_reverse_lookup = true
-tcps = TCPServer.new("0.0.0.0", port)
+tcps = nil
+100.times{|i|
+ begin
+ tcps = TCPServer.new("0.0.0.0", port+i)
+ port = port + i
+ break
+ rescue Errno::EADDRINUSE
+ next
+ end
+}
ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
ssls.start_immediately = start_immediately
$stdout.sync = true
$stdout.puts Process.pid
+$stdout.puts port
loop do
ssl = ssls.accept
diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb
index dbc8f13902..c7bf15d82a 100644
--- a/test/openssl/test_ssl.rb
+++ b/test/openssl/test_ssl.rb
@@ -58,20 +58,24 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
OpenSSL::TestUtils.issue_crl(*arg)
end
- def start_server(port, verify_mode, start_immediately, &block)
+ def start_server(port0, verify_mode, start_immediately, &block)
server = nil
begin
cmd = [RUBY]
cmd << "-d" if $DEBUG
- cmd << SSL_SERVER << port.to_s << verify_mode.to_s
+ cmd << SSL_SERVER << port0.to_s << verify_mode.to_s
cmd << (start_immediately ? "yes" : "no")
server = IO.popen(cmd, "w+")
server.write(@ca_cert.to_pem)
server.write(@svr_cert.to_pem)
server.write(@svr_key.to_pem)
pid = Integer(server.gets)
- $stderr.printf("%s started: pid=%d\n", SSL_SERVER, pid) if $DEBUG
- block.call(server)
+ if port = server.gets
+ if $DEBUG
+ $stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, pid, port)
+ end
+ block.call(server, port.to_i)
+ end
ensure
if server
Process.kill(:KILL, pid)
@@ -90,15 +94,15 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
end
def test_connect_and_close
- start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){
- sock = TCPSocket.new("127.0.0.1", PORT)
+ start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){|s, p|
+ sock = TCPSocket.new("127.0.0.1", p)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
assert(ssl.connect)
ssl.close
assert(!sock.closed?)
sock.close
- sock = TCPSocket.new("127.0.0.1", PORT)
+ sock = TCPSocket.new("127.0.0.1", p)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true # !!
assert(ssl.connect)
@@ -108,8 +112,8 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
end
def test_read_and_write
- start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){
- sock = TCPSocket.new("127.0.0.1", PORT)
+ start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){|s, p|
+ sock = TCPSocket.new("127.0.0.1", p)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
ssl.connect
@@ -152,8 +156,8 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
end
def test_starttls
- start_server(PORT, OpenSSL::SSL::VERIFY_NONE, false){|s|
- sock = TCPSocket.new("127.0.0.1", PORT)
+ start_server(PORT, OpenSSL::SSL::VERIFY_NONE, false){|s, p|
+ sock = TCPSocket.new("127.0.0.1", p)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
str = "x" * 1000 + "\n"
@@ -175,10 +179,10 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
end
def test_parallel
- start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){
+ start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){|s, p|
ssls = []
10.times{
- sock = TCPSocket.new("127.0.0.1", PORT)
+ sock = TCPSocket.new("127.0.0.1", p)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.connect
ssl.sync_close = true
diff --git a/test/openssl/test_x509name.rb b/test/openssl/test_x509name.rb
index 8d6d9cb534..fb5a1ae4ff 100644
--- a/test/openssl/test_x509name.rb
+++ b/test/openssl/test_x509name.rb
@@ -7,6 +7,11 @@ require "test/unit"
if defined?(OpenSSL)
class OpenSSL::TestX509Name < Test::Unit::TestCase
+ OpenSSL::ASN1::ObjectId.register(
+ "1.2.840.113549.1.9.1", "emailAddress", "emailAddress")
+ OpenSSL::ASN1::ObjectId.register(
+ "2.5.4.5", "serialNumber", "serialNumber")
+
def setup
@obj_type_tmpl = Hash.new(OpenSSL::ASN1::PRINTABLESTRING)
@obj_type_tmpl.update(OpenSSL::X509::Name::OBJECT_TYPE_TEMPLATE)
@@ -76,21 +81,12 @@ class OpenSSL::TestX509Name < Test::Unit::TestCase
]
name = OpenSSL::X509::Name.new(dn)
ary = name.to_a
- if OpenSSL::OPENSSL_VERSION_NUMBER < 0x00907000
- assert_equal("/DC=org/DC=ruby-lang/CN=GOTOU Yuuzou/Email=gotoyuzo@ruby-lang.org/SN=123", name.to_s)
- else
- assert_equal("/DC=org/DC=ruby-lang/CN=GOTOU Yuuzou/emailAddress=gotoyuzo@ruby-lang.org/serialNumber=123", name.to_s)
- end
+ assert_equal("/DC=org/DC=ruby-lang/CN=GOTOU Yuuzou/emailAddress=gotoyuzo@ruby-lang.org/serialNumber=123", name.to_s)
assert_equal("DC", ary[0][0])
assert_equal("DC", ary[1][0])
assert_equal("CN", ary[2][0])
- if OpenSSL::OPENSSL_VERSION_NUMBER < 0x00907000
- assert_equal("Email", ary[3][0])
- assert_equal("SN", ary[4][0])
- else
- assert_equal("emailAddress", ary[3][0])
- assert_equal("serialNumber", ary[4][0])
- end
+ assert_equal("emailAddress", ary[3][0])
+ assert_equal("serialNumber", ary[4][0])
assert_equal("org", ary[0][1])
assert_equal("ruby-lang", ary[1][1])
assert_equal("GOTOU Yuuzou", ary[2][1])
@@ -248,21 +244,12 @@ class OpenSSL::TestX509Name < Test::Unit::TestCase
name = OpenSSL::X509::Name.new
dn.each{|attr| name.add_entry(*attr) }
ary = name.to_a
- if OpenSSL::OPENSSL_VERSION_NUMBER < 0x00907000
- assert_equal("/DC=org/DC=ruby-lang/CN=GOTOU Yuuzou/Email=gotoyuzo@ruby-lang.org/SN=123", name.to_s)
- else
- assert_equal("/DC=org/DC=ruby-lang/CN=GOTOU Yuuzou/emailAddress=gotoyuzo@ruby-lang.org/serialNumber=123", name.to_s)
- end
+ assert_equal("/DC=org/DC=ruby-lang/CN=GOTOU Yuuzou/emailAddress=gotoyuzo@ruby-lang.org/serialNumber=123", name.to_s)
assert_equal("DC", ary[0][0])
assert_equal("DC", ary[1][0])
assert_equal("CN", ary[2][0])
- if OpenSSL::OPENSSL_VERSION_NUMBER < 0x00907000
- assert_equal("Email", ary[3][0])
- assert_equal("SN", ary[4][0])
- else
- assert_equal("emailAddress", ary[3][0])
- assert_equal("serialNumber", ary[4][0])
- end
+ assert_equal("emailAddress", ary[3][0])
+ assert_equal("serialNumber", ary[4][0])
assert_equal("org", ary[0][1])
assert_equal("ruby-lang", ary[1][1])
assert_equal("GOTOU Yuuzou", ary[2][1])