jruby-openssl 0.7.5.dev → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +44 -14
  2. data/Manifest.txt +135 -80
  3. data/Rakefile +14 -6
  4. data/lib/{openssl.rb → 1.8/openssl.rb} +2 -11
  5. data/lib/{openssl → 1.8/openssl}/bn.rb +2 -2
  6. data/lib/{openssl → 1.8/openssl}/buffering.rb +3 -1
  7. data/lib/{openssl → 1.8/openssl}/cipher.rb +0 -0
  8. data/lib/{openssl → 1.8/openssl}/config.rb +1 -1
  9. data/lib/{openssl → 1.8/openssl}/digest.rb +2 -2
  10. data/lib/{openssl → 1.8/openssl}/pkcs7.rb +0 -0
  11. data/lib/{openssl/ssl.rb → 1.8/openssl/ssl-internal.rb} +2 -2
  12. data/lib/1.8/openssl/ssl.rb +1 -0
  13. data/lib/{openssl/x509.rb → 1.8/openssl/x509-internal.rb} +8 -9
  14. data/lib/1.8/openssl/x509.rb +1 -0
  15. data/lib/1.9/openssl.rb +22 -0
  16. data/lib/1.9/openssl/bn.rb +35 -0
  17. data/lib/1.9/openssl/buffering.rb +448 -0
  18. data/lib/1.9/openssl/cipher.rb +65 -0
  19. data/lib/1.9/openssl/config.rb +313 -0
  20. data/lib/1.9/openssl/digest.rb +72 -0
  21. data/lib/1.9/openssl/ssl-internal.rb +177 -0
  22. data/lib/1.9/openssl/ssl.rb +2 -0
  23. data/lib/1.9/openssl/x509-internal.rb +158 -0
  24. data/lib/1.9/openssl/x509.rb +2 -0
  25. data/lib/{jopenssl.jar → shared/jopenssl.jar} +0 -0
  26. data/lib/{jopenssl → shared/jopenssl}/version.rb +1 -1
  27. data/lib/shared/openssl.rb +18 -0
  28. data/lib/{openssl → shared/openssl}/dummy.rb +0 -0
  29. data/lib/{openssl → shared/openssl}/dummyssl.rb +0 -0
  30. data/lib/shared/openssl/ssl.rb +1 -0
  31. data/lib/shared/openssl/x509.rb +1 -0
  32. data/test/{openssl → 1.8}/ssl_server.rb +0 -0
  33. data/test/{openssl → 1.8}/test_asn1.rb +15 -0
  34. data/test/{openssl → 1.8}/test_cipher.rb +0 -0
  35. data/test/{openssl → 1.8}/test_config.rb +0 -0
  36. data/test/{openssl → 1.8}/test_digest.rb +0 -0
  37. data/test/{openssl → 1.8}/test_ec.rb +0 -0
  38. data/test/{openssl → 1.8}/test_hmac.rb +0 -0
  39. data/test/{openssl → 1.8}/test_ns_spki.rb +0 -0
  40. data/test/{openssl → 1.8}/test_pair.rb +10 -2
  41. data/test/{openssl → 1.8}/test_pkcs7.rb +0 -0
  42. data/test/{openssl → 1.8}/test_pkey_rsa.rb +0 -0
  43. data/test/{openssl → 1.8}/test_ssl.rb +17 -20
  44. data/test/{openssl → 1.8}/test_x509cert.rb +0 -0
  45. data/test/{openssl → 1.8}/test_x509crl.rb +0 -0
  46. data/test/{openssl → 1.8}/test_x509ext.rb +0 -0
  47. data/test/{openssl → 1.8}/test_x509name.rb +0 -0
  48. data/test/{openssl → 1.8}/test_x509req.rb +0 -0
  49. data/test/{openssl → 1.8}/test_x509store.rb +0 -0
  50. data/test/{openssl → 1.8}/utils.rb +0 -0
  51. data/test/1.9/ssl_server.rb +81 -0
  52. data/test/1.9/test_asn1.rb +589 -0
  53. data/test/1.9/test_bn.rb +23 -0
  54. data/test/1.9/test_buffering.rb +88 -0
  55. data/test/1.9/test_cipher.rb +107 -0
  56. data/test/1.9/test_config.rb +288 -0
  57. data/test/1.9/test_digest.rb +118 -0
  58. data/test/1.9/test_engine.rb +15 -0
  59. data/test/1.9/test_hmac.rb +32 -0
  60. data/test/1.9/test_ns_spki.rb +50 -0
  61. data/test/1.9/test_ocsp.rb +47 -0
  62. data/test/1.9/test_pair.rb +257 -0
  63. data/test/1.9/test_pkcs12.rb +209 -0
  64. data/test/1.9/test_pkcs7.rb +151 -0
  65. data/test/1.9/test_pkey_dh.rb +72 -0
  66. data/test/1.9/test_pkey_dsa.rb +224 -0
  67. data/test/1.9/test_pkey_ec.rb +182 -0
  68. data/test/1.9/test_pkey_rsa.rb +244 -0
  69. data/test/1.9/test_ssl.rb +455 -0
  70. data/test/1.9/test_ssl_session.rb +327 -0
  71. data/test/1.9/test_x509cert.rb +217 -0
  72. data/test/1.9/test_x509crl.rb +221 -0
  73. data/test/1.9/test_x509ext.rb +69 -0
  74. data/test/1.9/test_x509name.rb +296 -0
  75. data/test/1.9/test_x509req.rb +150 -0
  76. data/test/1.9/test_x509store.rb +229 -0
  77. data/test/1.9/utils.rb +304 -0
  78. data/test/fixture/purpose/ca/ca_config.rb +1 -1
  79. data/test/fixture/purpose/ca/gen_cert.rb +128 -0
  80. data/test/fixture/purpose/ca/newcerts/4_cert.pem +19 -0
  81. data/test/fixture/purpose/ca/serial +1 -1
  82. data/test/fixture/purpose/sslserver_no_dsig_in_keyUsage.pem +19 -0
  83. data/test/ruby/envutil.rb +208 -0
  84. data/test/ruby/ut_eof.rb +128 -0
  85. data/test/test_java.rb +1 -1
  86. data/test/test_openssl.rb +1 -1
  87. data/test/test_pkcs7.rb +16 -0
  88. data/test/test_pkey_dsa.rb +180 -0
  89. data/test/test_pkey_rsa.rb +298 -0
  90. data/test/test_ssl.rb +1 -1
  91. data/test/test_x509store.rb +8 -0
  92. metadata +121 -75
  93. data/test/test_pkey.rb +0 -204
@@ -11,7 +11,7 @@ class CAConfig
11
11
  CA_CERT_DAYS = 20 * 365
12
12
  CA_RSA_KEY_LENGTH = 2048
13
13
 
14
- CERT_DAYS = 19 * 365
14
+ CERT_DAYS = 18 * 365
15
15
  CERT_KEY_LENGTH_MIN = 1024
16
16
  CERT_KEY_LENGTH_MAX = 2048
17
17
  CDP_LOCATION = nil
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'openssl'
4
+ require 'ca_config'
5
+ require 'fileutils'
6
+ require 'getopts'
7
+
8
+ include OpenSSL
9
+
10
+ def usage
11
+ myname = File::basename($0)
12
+ $stderr.puts "Usage: #{myname} [--type (client|server|ca|ocsp)] [--out certfile] csr_file"
13
+ exit
14
+ end
15
+
16
+ getopts nil, 'type:client', 'out:', 'force'
17
+
18
+ cert_type = $OPT_type
19
+ out_file = $OPT_out || 'cert.pem'
20
+ csr_file = ARGV.shift or usage
21
+ ARGV.empty? or usage
22
+
23
+ csr = X509::Request.new(File.open(csr_file).read)
24
+ unless csr.verify(csr.public_key)
25
+ raise "CSR sign verification failed."
26
+ end
27
+ p csr.public_key
28
+ if csr.public_key.n.num_bits < CAConfig::CERT_KEY_LENGTH_MIN
29
+ raise "Key length too short"
30
+ end
31
+ if csr.public_key.n.num_bits > CAConfig::CERT_KEY_LENGTH_MAX
32
+ raise "Key length too long"
33
+ end
34
+ if csr.subject.to_a[0, CAConfig::NAME.size] != CAConfig::NAME
35
+ unless $OPT_force
36
+ p csr.subject.to_a
37
+ p CAConfig::NAME
38
+ raise "DN does not match"
39
+ end
40
+ end
41
+
42
+ # Only checks signature here. You must verify CSR according to your CP/CPS.
43
+
44
+ $stdout.sync = true
45
+
46
+ # CA setup
47
+
48
+ ca_file = CAConfig::CERT_FILE
49
+ puts "Reading CA cert (from #{ca_file})"
50
+ ca = X509::Certificate.new(File.read(ca_file))
51
+
52
+ ca_keypair_file = CAConfig::KEYPAIR_FILE
53
+ puts "Reading CA keypair (from #{ca_keypair_file})"
54
+ ca_keypair = PKey::RSA.new(File.read(ca_keypair_file), &CAConfig::PASSWD_CB)
55
+
56
+ serial = File.open(CAConfig::SERIAL_FILE, "r").read.chomp.hex
57
+ File.open(CAConfig::SERIAL_FILE, "w") do |f|
58
+ f << sprintf("%04X", serial + 1)
59
+ end
60
+
61
+ # Generate new cert
62
+
63
+ cert = X509::Certificate.new
64
+ from = Time.now # + 30 * 60 # Wait 30 minutes.
65
+ cert.subject = csr.subject
66
+ cert.issuer = ca.subject
67
+ cert.not_before = from
68
+ cert.not_after = from + CAConfig::CERT_DAYS * 24 * 60 * 60
69
+ cert.public_key = csr.public_key
70
+ cert.serial = serial
71
+ cert.version = 2 # X509v3
72
+
73
+ basic_constraint = nil
74
+ key_usage = []
75
+ ext_key_usage = []
76
+ case cert_type
77
+ when "ca"
78
+ basic_constraint = "CA:TRUE"
79
+ key_usage << "cRLSign" << "keyCertSign"
80
+ when "terminalsubca"
81
+ basic_constraint = "CA:TRUE,pathlen:0"
82
+ key_usage << "cRLSign" << "keyCertSign"
83
+ when "server"
84
+ basic_constraint = "CA:FALSE"
85
+ #key_usage << "digitalSignature" << "keyEncipherment"
86
+ key_usage << "keyEncipherment"
87
+ ext_key_usage << "serverAuth"
88
+ when "ocsp"
89
+ basic_constraint = "CA:FALSE"
90
+ key_usage << "nonRepudiation" << "digitalSignature"
91
+ ext_key_usage << "serverAuth" << "OCSPSigning"
92
+ when "client"
93
+ basic_constraint = "CA:FALSE"
94
+ key_usage << "nonRepudiation" << "digitalSignature" << "keyEncipherment"
95
+ ext_key_usage << "clientAuth" << "emailProtection"
96
+ else
97
+ raise "unknonw cert type \"#{cert_type}\" is specified."
98
+ end
99
+
100
+ ef = X509::ExtensionFactory.new
101
+ ef.subject_certificate = cert
102
+ ef.issuer_certificate = ca
103
+ ex = []
104
+ ex << ef.create_extension("basicConstraints", basic_constraint, true)
105
+ ex << ef.create_extension("nsComment","Ruby/OpenSSL Generated Certificate")
106
+ ex << ef.create_extension("subjectKeyIdentifier", "hash")
107
+ #ex << ef.create_extension("nsCertType", "client,email")
108
+ ex << ef.create_extension("keyUsage", key_usage.join(",")) unless key_usage.empty?
109
+ #ex << ef.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
110
+ #ex << ef.create_extension("authorityKeyIdentifier", "keyid:always")
111
+ ex << ef.create_extension("extendedKeyUsage", ext_key_usage.join(",")) unless ext_key_usage.empty?
112
+
113
+ ex << ef.create_extension("crlDistributionPoints", CAConfig::CDP_LOCATION) if CAConfig::CDP_LOCATION
114
+ ex << ef.create_extension("authorityInfoAccess", "OCSP;" << CAConfig::OCSP_LOCATION) if CAConfig::OCSP_LOCATION
115
+ cert.extensions = ex
116
+ cert.sign(ca_keypair, OpenSSL::Digest::SHA1.new)
117
+
118
+ # For backup
119
+
120
+ cert_file = CAConfig::NEW_CERTS_DIR + "/#{cert.serial}_cert.pem"
121
+ File.open(cert_file, "w", 0644) do |f|
122
+ f << cert.to_pem
123
+ end
124
+
125
+ puts "Writing cert.pem..."
126
+ FileUtils.copy(cert_file, out_file)
127
+
128
+ puts "DONE. (Generated certificate for '#{cert.subject}')"
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDBjCCAe6gAwIBAgIBBDANBgkqhkiG9w0BAQUFADBMMQswCQYDVQQGEwJKUDEa
3
+ MBgGA1UECgwRd3d3LnJ1YnktbGFuZy5vcmcxFDASBgNVBAsMC2RldmVsb3BtZW50
4
+ MQswCQYDVQQDDAJDQTAeFw0xMTEyMTQwNDQxNTNaFw0yOTEyMDkwNDQxNTNaMD0x
5
+ CzAJBgNVBAYTAkpQMRowGAYDVQQKDBF3d3cucnVieS1sYW5nLm9yZzESMBAGA1UE
6
+ AwwJc3Nsc2VydmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDgYsazavfR
7
+ a72yK4qfnIjOrDT9Uv2ToL4swbE86PXY5N+YvUig3fVmNJo72rT5JlAODs+MtJJU
8
+ aJ8HsczlGdrhjTWyT/0fyoY/rC4mi5UFASBCbaoaviDPgbhI6ehBY6d5vEYQOW79
9
+ fL95KIa+OyGzUNYy+EkSxJmvt/8EJYtqIwIDAQABo4GFMIGCMAwGA1UdEwEB/wQC
10
+ MAAwMQYJYIZIAYb4QgENBCQWIlJ1YnkvT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlm
11
+ aWNhdGUwHQYDVR0OBBYEFJsUyGU/R4muSKVIeckJElcBNbipMAsGA1UdDwQEAwIF
12
+ IDATBgNVHSUEDDAKBggrBgEFBQcDATANBgkqhkiG9w0BAQUFAAOCAQEArdmTvG5H
13
+ elHkiHWp/yFdiIrbUHfDsAmB1jN7Zhte9yWzUuaVKR6GS6FzL4zU6dgAA3UNroVK
14
+ MuyeL5Cejsck2+HgOvAtwTJFjP4c8YwdlYuycvMkk5EbaByY1h59ZvV1J+GxmoDA
15
+ uO3iTqGrKwrFDK59yuxhdn1yyGTwYTBAdvllfSmTmfnbOkV/faF8gpRvrenx3lLK
16
+ eAVhBCzAw2cblXKJEvly+wzAXykS6jagtrnHm5ilt2R5zPzS1wNJlzBq4laI+pZU
17
+ timqb2wMA9TLd4FCKqK4HwiUKyAR7eknxtdskQ0/2DBAiOoh1Gl5hwnrDAlb73vA
18
+ DDOusxgmoBZS4w==
19
+ -----END CERTIFICATE-----
@@ -1 +1 @@
1
- 0004
1
+ 0005
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDBjCCAe6gAwIBAgIBBDANBgkqhkiG9w0BAQUFADBMMQswCQYDVQQGEwJKUDEa
3
+ MBgGA1UECgwRd3d3LnJ1YnktbGFuZy5vcmcxFDASBgNVBAsMC2RldmVsb3BtZW50
4
+ MQswCQYDVQQDDAJDQTAeFw0xMTEyMTQwNDQxNTNaFw0yOTEyMDkwNDQxNTNaMD0x
5
+ CzAJBgNVBAYTAkpQMRowGAYDVQQKDBF3d3cucnVieS1sYW5nLm9yZzESMBAGA1UE
6
+ AwwJc3Nsc2VydmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDgYsazavfR
7
+ a72yK4qfnIjOrDT9Uv2ToL4swbE86PXY5N+YvUig3fVmNJo72rT5JlAODs+MtJJU
8
+ aJ8HsczlGdrhjTWyT/0fyoY/rC4mi5UFASBCbaoaviDPgbhI6ehBY6d5vEYQOW79
9
+ fL95KIa+OyGzUNYy+EkSxJmvt/8EJYtqIwIDAQABo4GFMIGCMAwGA1UdEwEB/wQC
10
+ MAAwMQYJYIZIAYb4QgENBCQWIlJ1YnkvT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlm
11
+ aWNhdGUwHQYDVR0OBBYEFJsUyGU/R4muSKVIeckJElcBNbipMAsGA1UdDwQEAwIF
12
+ IDATBgNVHSUEDDAKBggrBgEFBQcDATANBgkqhkiG9w0BAQUFAAOCAQEArdmTvG5H
13
+ elHkiHWp/yFdiIrbUHfDsAmB1jN7Zhte9yWzUuaVKR6GS6FzL4zU6dgAA3UNroVK
14
+ MuyeL5Cejsck2+HgOvAtwTJFjP4c8YwdlYuycvMkk5EbaByY1h59ZvV1J+GxmoDA
15
+ uO3iTqGrKwrFDK59yuxhdn1yyGTwYTBAdvllfSmTmfnbOkV/faF8gpRvrenx3lLK
16
+ eAVhBCzAw2cblXKJEvly+wzAXykS6jagtrnHm5ilt2R5zPzS1wNJlzBq4laI+pZU
17
+ timqb2wMA9TLd4FCKqK4HwiUKyAR7eknxtdskQ0/2DBAiOoh1Gl5hwnrDAlb73vA
18
+ DDOusxgmoBZS4w==
19
+ -----END CERTIFICATE-----
@@ -0,0 +1,208 @@
1
+ require "open3"
2
+ require "timeout"
3
+
4
+ module EnvUtil
5
+ def rubybin
6
+ unless ENV["RUBYOPT"]
7
+
8
+ end
9
+ if ruby = ENV["RUBY"]
10
+ return ruby
11
+ end
12
+ ruby = "ruby"
13
+ rubyexe = ruby+".exe"
14
+ 3.times do
15
+ if File.exist? ruby and File.executable? ruby and !File.directory? ruby
16
+ return File.expand_path(ruby)
17
+ end
18
+ if File.exist? rubyexe and File.executable? rubyexe
19
+ return File.expand_path(rubyexe)
20
+ end
21
+ ruby = File.join("..", ruby)
22
+ end
23
+ if defined?(RbConfig.ruby)
24
+ RbConfig.ruby
25
+ else
26
+ "ruby"
27
+ end
28
+ end
29
+ module_function :rubybin
30
+
31
+ LANG_ENVS = %w"LANG LC_ALL LC_CTYPE"
32
+
33
+ def invoke_ruby(args, stdin_data="", capture_stdout=false, capture_stderr=false, opt={})
34
+ in_c, in_p = IO.pipe
35
+ out_p, out_c = IO.pipe if capture_stdout
36
+ err_p, err_c = IO.pipe if capture_stderr && capture_stderr != :merge_to_stdout
37
+ opt = opt.dup
38
+ opt[:in] = in_c
39
+ opt[:out] = out_c if capture_stdout
40
+ opt[:err] = capture_stderr == :merge_to_stdout ? out_c : err_c if capture_stderr
41
+ if enc = opt.delete(:encoding)
42
+ out_p.set_encoding(enc) if out_p
43
+ err_p.set_encoding(enc) if err_p
44
+ end
45
+ c = "C"
46
+ child_env = {}
47
+ LANG_ENVS.each {|lc| child_env[lc] = c}
48
+ if Array === args and Hash === args.first
49
+ child_env.update(args.shift)
50
+ end
51
+ args = [args] if args.kind_of?(String)
52
+ pid = spawn(child_env, EnvUtil.rubybin, *args, opt)
53
+ in_c.close
54
+ out_c.close if capture_stdout
55
+ err_c.close if capture_stderr && capture_stderr != :merge_to_stdout
56
+ if block_given?
57
+ return yield in_p, out_p, err_p
58
+ else
59
+ th_stdout = Thread.new { out_p.read } if capture_stdout
60
+ th_stderr = Thread.new { err_p.read } if capture_stderr && capture_stderr != :merge_to_stdout
61
+ in_p.write stdin_data.to_str
62
+ in_p.close
63
+ timeout = opt.fetch(:timeout, 10)
64
+ if (!th_stdout || th_stdout.join(timeout)) && (!th_stderr || th_stderr.join(timeout))
65
+ stdout = th_stdout.value if capture_stdout
66
+ stderr = th_stderr.value if capture_stderr && capture_stderr != :merge_to_stdout
67
+ else
68
+ raise Timeout::Error
69
+ end
70
+ out_p.close if capture_stdout
71
+ err_p.close if capture_stderr && capture_stderr != :merge_to_stdout
72
+ Process.wait pid
73
+ status = $?
74
+ return stdout, stderr, status
75
+ end
76
+ ensure
77
+ [in_c, in_p, out_c, out_p, err_c, err_p].each do |io|
78
+ io.close if io && !io.closed?
79
+ end
80
+ [th_stdout, th_stderr].each do |th|
81
+ (th.kill; th.join) if th
82
+ end
83
+ end
84
+ module_function :invoke_ruby
85
+
86
+ alias rubyexec invoke_ruby
87
+ class << self
88
+ alias rubyexec invoke_ruby
89
+ end
90
+
91
+ def verbose_warning
92
+ class << (stderr = "")
93
+ alias write <<
94
+ end
95
+ stderr, $stderr, verbose, $VERBOSE = $stderr, stderr, $VERBOSE, true
96
+ yield stderr
97
+ ensure
98
+ stderr, $stderr, $VERBOSE = $stderr, stderr, verbose
99
+ return stderr
100
+ end
101
+ module_function :verbose_warning
102
+
103
+ def suppress_warning
104
+ verbose, $VERBOSE = $VERBOSE, nil
105
+ yield
106
+ ensure
107
+ $VERBOSE = verbose
108
+ end
109
+ module_function :suppress_warning
110
+
111
+ def under_gc_stress
112
+ stress, GC.stress = GC.stress, true
113
+ yield
114
+ ensure
115
+ GC.stress = stress
116
+ end
117
+ module_function :under_gc_stress
118
+ end
119
+
120
+ module Test
121
+ module Unit
122
+ module Assertions
123
+ public
124
+ def assert_normal_exit(testsrc, message = '', opt = {})
125
+ if opt.include?(:child_env)
126
+ opt = opt.dup
127
+ child_env = [opt.delete(:child_env)] || []
128
+ else
129
+ child_env = []
130
+ end
131
+ out, _, status = EnvUtil.invoke_ruby(child_env + %W'-W0', testsrc, true, :merge_to_stdout, opt)
132
+ pid = status.pid
133
+ faildesc = proc do
134
+ signo = status.termsig
135
+ signame = Signal.list.invert[signo]
136
+ sigdesc = "signal #{signo}"
137
+ if signame
138
+ sigdesc = "SIG#{signame} (#{sigdesc})"
139
+ end
140
+ if status.coredump?
141
+ sigdesc << " (core dumped)"
142
+ end
143
+ full_message = ''
144
+ if !message.empty?
145
+ full_message << message << "\n"
146
+ end
147
+ full_message << "pid #{pid} killed by #{sigdesc}"
148
+ if !out.empty?
149
+ out << "\n" if /\n\z/ !~ out
150
+ full_message << "\n#{out.gsub(/^/, '| ')}"
151
+ end
152
+ full_message
153
+ end
154
+ assert !status.signaled?, faildesc
155
+ end
156
+
157
+ def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil, opt={})
158
+ stdout, stderr, status = EnvUtil.invoke_ruby(args, test_stdin, true, true, opt)
159
+ if block_given?
160
+ yield(stdout.lines.map {|l| l.chomp }, stderr.lines.map {|l| l.chomp })
161
+ else
162
+ if test_stdout.is_a?(Regexp)
163
+ assert_match(test_stdout, stdout, message)
164
+ else
165
+ assert_equal(test_stdout, stdout.lines.map {|l| l.chomp }, message)
166
+ end
167
+ if test_stderr.is_a?(Regexp)
168
+ assert_match(test_stderr, stderr, message)
169
+ else
170
+ assert_equal(test_stderr, stderr.lines.map {|l| l.chomp }, message)
171
+ end
172
+ status
173
+ end
174
+ end
175
+
176
+ def assert_ruby_status(args, test_stdin="", message=nil, opt={})
177
+ _, _, status = EnvUtil.invoke_ruby(args, test_stdin, false, false, opt)
178
+ m = message ? "#{message} (#{status.inspect})" : "ruby exit status is not success: #{status.inspect}"
179
+ assert(status.success?, m)
180
+ end
181
+
182
+ def assert_warn(msg)
183
+ stderr = EnvUtil.verbose_warning { yield }
184
+ assert(msg === stderr, "warning message #{stderr.inspect} is expected to match #{msg.inspect}")
185
+ end
186
+
187
+ end
188
+ end
189
+ end
190
+
191
+ begin
192
+ require 'rbconfig'
193
+ rescue LoadError
194
+ else
195
+ module RbConfig
196
+ @ruby = EnvUtil.rubybin
197
+ class << self
198
+ undef ruby if method_defined?(:ruby)
199
+ attr_reader :ruby
200
+ end
201
+ dir = File.dirname(ruby)
202
+ name = File.basename(ruby, CONFIG['EXEEXT'])
203
+ CONFIG['bindir'] = dir
204
+ CONFIG['ruby_install_name'] = name
205
+ CONFIG['RUBY_INSTALL_NAME'] = name
206
+ Gem::ConfigMap[:bindir] = dir if defined?(Gem::ConfigMap)
207
+ end
208
+ end
@@ -0,0 +1,128 @@
1
+ require 'test/unit'
2
+
3
+ module TestEOF
4
+ def test_eof_0
5
+ open_file("") {|f|
6
+ assert_equal("", f.read(0))
7
+ assert_equal("", f.read(0))
8
+ assert_equal("", f.read)
9
+ assert_equal("", f.read(0))
10
+ assert_equal("", f.read(0))
11
+ }
12
+ open_file("") {|f|
13
+ assert_nil(f.read(1))
14
+ assert_equal("", f.read)
15
+ assert_nil(f.read(1))
16
+ }
17
+ open_file("") {|f|
18
+ s = "x"
19
+ assert_equal("", f.read(nil, s))
20
+ assert_equal("", s)
21
+ }
22
+ open_file("") {|f|
23
+ s = "x"
24
+ assert_nil(f.read(10, s))
25
+ assert_equal("", s)
26
+ }
27
+ end
28
+
29
+ def test_eof_0_rw
30
+ return unless respond_to? :open_file_rw
31
+ open_file_rw("") {|f|
32
+ assert_equal("", f.read)
33
+ assert_equal("", f.read)
34
+ assert_equal(0, f.syswrite(""))
35
+ assert_equal("", f.read)
36
+ }
37
+ end
38
+
39
+ def test_eof_1
40
+ open_file("a") {|f|
41
+ assert_equal("", f.read(0))
42
+ assert_equal("a", f.read(1))
43
+ assert_equal("" , f.read(0))
44
+ assert_equal("" , f.read(0))
45
+ assert_equal("", f.read)
46
+ assert_equal("", f.read(0))
47
+ assert_equal("", f.read(0))
48
+ }
49
+ open_file("a") {|f|
50
+ assert_equal("a", f.read(1))
51
+ assert_nil(f.read(1))
52
+ }
53
+ open_file("a") {|f|
54
+ assert_equal("a", f.read(2))
55
+ assert_nil(f.read(1))
56
+ assert_equal("", f.read)
57
+ assert_nil(f.read(1))
58
+ }
59
+ open_file("a") {|f|
60
+ assert_equal("a", f.read)
61
+ assert_nil(f.read(1))
62
+ assert_equal("", f.read)
63
+ assert_nil(f.read(1))
64
+ }
65
+ open_file("a") {|f|
66
+ assert_equal("a", f.read(2))
67
+ assert_equal("", f.read)
68
+ assert_equal("", f.read)
69
+ }
70
+ open_file("a") {|f|
71
+ assert_equal("a", f.read)
72
+ assert_equal("", f.read(0))
73
+ }
74
+ open_file("a") {|f|
75
+ s = "x"
76
+ assert_equal("a", f.read(nil, s))
77
+ assert_equal("a", s)
78
+ }
79
+ open_file("a") {|f|
80
+ s = "x"
81
+ assert_equal("a", f.read(10, s))
82
+ assert_equal("a", s)
83
+ }
84
+ end
85
+
86
+ def test_eof_2
87
+ open_file("") {|f|
88
+ assert_equal("", f.read)
89
+ assert(f.eof?)
90
+ }
91
+ end
92
+
93
+ def test_eof_3
94
+ open_file("") {|f|
95
+ assert(f.eof?)
96
+ }
97
+ end
98
+
99
+ module Seek
100
+ def open_file_seek(content, pos)
101
+ open_file(content) do |f|
102
+ f.seek(pos)
103
+ yield f
104
+ end
105
+ end
106
+
107
+ def test_eof_0_seek
108
+ open_file_seek("", 10) {|f|
109
+ assert_equal(10, f.pos)
110
+ assert_equal("", f.read(0))
111
+ assert_equal("", f.read)
112
+ assert_equal("", f.read(0))
113
+ assert_equal("", f.read)
114
+ }
115
+ end
116
+
117
+ def test_eof_1_seek
118
+ open_file_seek("a", 10) {|f|
119
+ assert_equal("", f.read)
120
+ assert_equal("", f.read)
121
+ }
122
+ open_file_seek("a", 1) {|f|
123
+ assert_equal("", f.read)
124
+ assert_equal("", f.read)
125
+ }
126
+ end
127
+ end
128
+ end