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
@@ -0,0 +1,23 @@
1
+ require_relative 'utils'
2
+
3
+ if defined?(OpenSSL)
4
+
5
+ class OpenSSL::TestBN < Test::Unit::TestCase
6
+ def test_integer_to_bn
7
+ assert_equal(999.to_bn, OpenSSL::BN.new(999.to_s(16), 16))
8
+ assert_equal((2 ** 107 - 1).to_bn, OpenSSL::BN.new((2 ** 107 - 1).to_s(16), 16))
9
+ end
10
+
11
+ def test_prime_p
12
+ assert_equal(true, OpenSSL::BN.new((2 ** 107 - 1).to_s(16), 16).prime?)
13
+ assert_equal(true, OpenSSL::BN.new((2 ** 127 - 1).to_s(16), 16).prime?(1))
14
+ end
15
+
16
+ def test_cmp_nil
17
+ bn = OpenSSL::BN.new('1')
18
+ assert_equal(false, bn == nil)
19
+ assert_equal(true, bn != nil)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,88 @@
1
+ require_relative 'utils'
2
+ require 'stringio'
3
+
4
+ class OpenSSL::TestBuffering < Test::Unit::TestCase
5
+
6
+ class IO
7
+ include OpenSSL::Buffering
8
+
9
+ attr_accessor :sync
10
+
11
+ def initialize
12
+ @io = ""
13
+ def @io.sync
14
+ true
15
+ end
16
+
17
+ super
18
+
19
+ @sync = false
20
+ end
21
+
22
+ def string
23
+ @io
24
+ end
25
+
26
+ def sysread(size)
27
+ str = @io.slice!(0, size)
28
+ raise EOFError if str.empty?
29
+ str
30
+ end
31
+
32
+ def syswrite(str)
33
+ @io << str
34
+ str.size
35
+ end
36
+ end
37
+
38
+ def setup
39
+ @io = IO.new
40
+ end
41
+
42
+ def test_flush
43
+ @io.write 'a'
44
+
45
+ refute @io.sync
46
+ assert_empty @io.string
47
+
48
+ assert_equal @io, @io.flush
49
+
50
+ refute @io.sync
51
+ assert_equal 'a', @io.string
52
+ end
53
+
54
+ def test_flush_error
55
+ @io.write 'a'
56
+
57
+ refute @io.sync
58
+ assert_empty @io.string
59
+
60
+ def @io.syswrite *a
61
+ raise SystemCallError, 'fail'
62
+ end
63
+
64
+ assert_raises SystemCallError do
65
+ @io.flush
66
+ end
67
+
68
+ refute @io.sync, 'sync must not change'
69
+ end
70
+
71
+ def test_getc
72
+ @io.syswrite('abc')
73
+ res = []
74
+ assert_equal(?a, @io.getc)
75
+ assert_equal(?b, @io.getc)
76
+ assert_equal(?c, @io.getc)
77
+ end
78
+
79
+ def test_each_byte
80
+ @io.syswrite('abc')
81
+ res = []
82
+ @io.each_byte do |c|
83
+ res << c
84
+ end
85
+ assert_equal([97, 98, 99], res)
86
+ end
87
+
88
+ end if defined?(OpenSSL)
@@ -0,0 +1,107 @@
1
+ require_relative 'utils'
2
+
3
+ if defined?(OpenSSL)
4
+
5
+ class OpenSSL::TestCipher < Test::Unit::TestCase
6
+ def setup
7
+ @c1 = OpenSSL::Cipher::Cipher.new("DES-EDE3-CBC")
8
+ @c2 = OpenSSL::Cipher::DES.new(:EDE3, "CBC")
9
+ @key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
10
+ @iv = "\0\0\0\0\0\0\0\0"
11
+ @hexkey = "0000000000000000000000000000000000000000000000"
12
+ @hexiv = "0000000000000000"
13
+ @data = "DATA"
14
+ end
15
+
16
+ def teardown
17
+ @c1 = @c2 = nil
18
+ end
19
+
20
+ def test_crypt
21
+ @c1.encrypt.pkcs5_keyivgen(@key, @iv)
22
+ @c2.encrypt.pkcs5_keyivgen(@key, @iv)
23
+ s1 = @c1.update(@data) + @c1.final
24
+ s2 = @c2.update(@data) + @c2.final
25
+ assert_equal(s1, s2, "encrypt")
26
+
27
+ @c1.decrypt.pkcs5_keyivgen(@key, @iv)
28
+ @c2.decrypt.pkcs5_keyivgen(@key, @iv)
29
+ assert_equal(@data, @c1.update(s1)+@c1.final, "decrypt")
30
+ assert_equal(@data, @c2.update(s2)+@c2.final, "decrypt")
31
+ end
32
+
33
+ def test_info
34
+ assert_equal("DES-EDE3-CBC", @c1.name, "name")
35
+ assert_equal("DES-EDE3-CBC", @c2.name, "name")
36
+ assert_kind_of(Fixnum, @c1.key_len, "key_len")
37
+ assert_kind_of(Fixnum, @c1.iv_len, "iv_len")
38
+ end
39
+
40
+ def test_dup
41
+ assert_equal(@c1.name, @c1.dup.name, "dup")
42
+ assert_equal(@c1.name, @c1.clone.name, "clone")
43
+ @c1.encrypt
44
+ @c1.key = @key
45
+ @c1.iv = @iv
46
+ tmpc = @c1.dup
47
+ s1 = @c1.update(@data) + @c1.final
48
+ s2 = tmpc.update(@data) + tmpc.final
49
+ assert_equal(s1, s2, "encrypt dup")
50
+ end
51
+
52
+ def test_reset
53
+ @c1.encrypt
54
+ @c1.key = @key
55
+ @c1.iv = @iv
56
+ s1 = @c1.update(@data) + @c1.final
57
+ @c1.reset
58
+ s2 = @c1.update(@data) + @c1.final
59
+ assert_equal(s1, s2, "encrypt reset")
60
+ end
61
+
62
+ def test_empty_data
63
+ @c1.encrypt
64
+ assert_raise(ArgumentError){ @c1.update("") }
65
+ end
66
+
67
+ def test_initialize
68
+ assert_raise(RuntimeError) {@c1.__send__(:initialize, "DES-EDE3-CBC")}
69
+ assert_raise(RuntimeError) {OpenSSL::Cipher.allocate.final}
70
+ end
71
+
72
+ if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00907000
73
+ def test_ciphers
74
+ OpenSSL::Cipher.ciphers.each{|name|
75
+ assert(OpenSSL::Cipher::Cipher.new(name).is_a?(OpenSSL::Cipher::Cipher))
76
+ }
77
+ end
78
+
79
+ # This test fails without unlimited US_export.policy
80
+ def test_AES
81
+ pt = File.read(__FILE__)
82
+ %w(ECB CBC CFB OFB).each{|mode|
83
+ c1 = OpenSSL::Cipher::AES256.new(mode)
84
+ c1.encrypt
85
+ c1.pkcs5_keyivgen("passwd")
86
+ ct = c1.update(pt) + c1.final
87
+
88
+ c2 = OpenSSL::Cipher::AES256.new(mode)
89
+ c2.decrypt
90
+ c2.pkcs5_keyivgen("passwd")
91
+ assert_equal(pt, c2.update(ct) + c2.final)
92
+ }
93
+ end
94
+
95
+ # In JRuby key must be provided first. (CipherError)
96
+ def NOT_test_AES_crush
97
+ 500.times do
98
+ assert_nothing_raised("[Bug #2768]") do
99
+ # it caused OpenSSL SEGV by uninitialized key
100
+ OpenSSL::Cipher::AES128.new("ECB").update "." * 17
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,288 @@
1
+ require_relative 'utils'
2
+
3
+ class OpenSSL::TestConfig < Test::Unit::TestCase
4
+ def setup
5
+ file = Tempfile.open("openssl.cnf")
6
+ file << <<__EOD__
7
+ HOME = .
8
+ [ ca ]
9
+ default_ca = CA_default
10
+ [ CA_default ]
11
+ dir = ./demoCA
12
+ certs = ./certs
13
+ __EOD__
14
+ file.close
15
+ @it = OpenSSL::Config.new(file.path)
16
+ end
17
+
18
+ def test_constants
19
+ assert(defined?(OpenSSL::Config::DEFAULT_CONFIG_FILE))
20
+ assert_nothing_raised do
21
+ OpenSSL::Config.load(OpenSSL::Config::DEFAULT_CONFIG_FILE)
22
+ end
23
+ end
24
+
25
+ def test_s_parse
26
+ c = OpenSSL::Config.parse('')
27
+ assert_equal("[ default ]\n\n", c.to_s)
28
+ c = OpenSSL::Config.parse(@it.to_s)
29
+ assert_equal(['CA_default', 'ca', 'default'], c.sections.sort)
30
+ end
31
+
32
+ def test_s_parse_format
33
+ c = OpenSSL::Config.parse(<<__EOC__)
34
+ baz =qx\t # "baz = qx"
35
+
36
+ foo::bar = baz # shortcut section::key format
37
+ default::bar = baz # ditto
38
+ a=\t \t # "a = ": trailing spaces are ignored
39
+ =b # " = b": empty key
40
+ =c # " = c": empty key (override the above line)
41
+ d= # "c = ": trailing comment is ignored
42
+
43
+ sq = 'foo''b\\'ar'
44
+ dq ="foo""''\\""
45
+ dq2 = foo""bar
46
+ esc=a\\r\\n\\b\\tb
47
+ foo\\bar = foo\\b\\\\ar
48
+ foo\\bar::foo\\bar = baz
49
+ [default1 default2]\t\t # space is allowed in section name
50
+ fo =b ar # space allowed in value
51
+ [emptysection]
52
+ [doller ]
53
+ foo=bar
54
+ bar = $(foo)
55
+ baz = 123$(default::bar)456${foo}798
56
+ qux = ${baz}
57
+ quxx = $qux.$qux
58
+ __EOC__
59
+ assert_equal(['default', 'default1 default2', 'doller', 'emptysection', 'foo', 'foo\\bar'], c.sections.sort)
60
+ assert_equal(['', 'a', 'bar', 'baz', 'd', 'dq', 'dq2', 'esc', 'foo\\bar', 'sq'], c['default'].keys.sort)
61
+ assert_equal('c', c['default'][''])
62
+ assert_equal('', c['default']['a'])
63
+ assert_equal('qx', c['default']['baz'])
64
+ assert_equal('', c['default']['d'])
65
+ assert_equal('baz', c['default']['bar'])
66
+ assert_equal("foob'ar", c['default']['sq'])
67
+ assert_equal("foo''\"", c['default']['dq'])
68
+ assert_equal("foobar", c['default']['dq2'])
69
+ assert_equal("a\r\n\b\tb", c['default']['esc'])
70
+ assert_equal("foo\b\\ar", c['default']['foo\\bar'])
71
+ assert_equal('baz', c['foo']['bar'])
72
+ assert_equal('baz', c['foo\\bar']['foo\\bar'])
73
+ assert_equal('b ar', c['default1 default2']['fo'])
74
+
75
+ # dolloer
76
+ assert_equal('bar', c['doller']['foo'])
77
+ assert_equal('bar', c['doller']['bar'])
78
+ assert_equal('123baz456bar798', c['doller']['baz'])
79
+ assert_equal('123baz456bar798', c['doller']['qux'])
80
+ assert_equal('123baz456bar798.123baz456bar798', c['doller']['quxx'])
81
+
82
+ excn = assert_raise(OpenSSL::ConfigError) do
83
+ OpenSSL::Config.parse("foo = $bar")
84
+ end
85
+ assert_equal("error in line 1: variable has no value", excn.message)
86
+
87
+ excn = assert_raise(OpenSSL::ConfigError) do
88
+ OpenSSL::Config.parse("foo = $(bar")
89
+ end
90
+ assert_equal("error in line 1: no close brace", excn.message)
91
+
92
+ excn = assert_raise(OpenSSL::ConfigError) do
93
+ OpenSSL::Config.parse("f o =b ar # no space in key")
94
+ end
95
+ assert_equal("error in line 1: missing equal sign", excn.message)
96
+
97
+ excn = assert_raise(OpenSSL::ConfigError) do
98
+ OpenSSL::Config.parse(<<__EOC__)
99
+ # comment 1 # comments
100
+
101
+ #
102
+ # comment 2
103
+ \t#comment 3
104
+ [second ]\t
105
+ [third # section not terminated
106
+ __EOC__
107
+ end
108
+ assert_equal("error in line 7: missing close square bracket", excn.message)
109
+ end
110
+
111
+ def test_s_load
112
+ # alias of new
113
+ c = OpenSSL::Config.load
114
+ assert_equal("", c.to_s)
115
+ assert_equal([], c.sections)
116
+ #
117
+ file = Tempfile.open("openssl.cnf")
118
+ file.close
119
+ c = OpenSSL::Config.load(file.path)
120
+ assert_equal("[ default ]\n\n", c.to_s)
121
+ assert_equal(['default'], c.sections)
122
+ end
123
+
124
+ def test_initialize
125
+ c = OpenSSL::Config.new
126
+ assert_equal("", c.to_s)
127
+ assert_equal([], c.sections)
128
+ end
129
+
130
+ def test_initialize_with_empty_file
131
+ file = Tempfile.open("openssl.cnf")
132
+ file.close
133
+ c = OpenSSL::Config.new(file.path)
134
+ assert_equal("[ default ]\n\n", c.to_s)
135
+ assert_equal(['default'], c.sections)
136
+ end
137
+
138
+ def test_initialize_with_example_file
139
+ assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
140
+ end
141
+
142
+ def test_get_value
143
+ assert_equal('CA_default', @it.get_value('ca', 'default_ca'))
144
+ assert_equal(nil, @it.get_value('ca', 'no such key'))
145
+ assert_equal(nil, @it.get_value('no such section', 'no such key'))
146
+ assert_equal('.', @it.get_value('', 'HOME'))
147
+ assert_raise(TypeError) do
148
+ @it.get_value(nil, 'HOME') # not allowed unlike Config#value
149
+ end
150
+ # fallback to 'default' ugly...
151
+ assert_equal('.', @it.get_value('unknown', 'HOME'))
152
+ end
153
+
154
+ def test_get_value_ENV
155
+ key = ENV.keys.first
156
+ assert_not_nil(key) # make sure we have at least one ENV var.
157
+ assert_equal(ENV[key], @it.get_value('ENV', key))
158
+ end
159
+
160
+ def test_value
161
+ # supress deprecation warnings
162
+ OpenSSL::TestUtils.silent do
163
+ assert_equal('CA_default', @it.value('ca', 'default_ca'))
164
+ assert_equal(nil, @it.value('ca', 'no such key'))
165
+ assert_equal(nil, @it.value('no such section', 'no such key'))
166
+ assert_equal('.', @it.value('', 'HOME'))
167
+ assert_equal('.', @it.value(nil, 'HOME'))
168
+ assert_equal('.', @it.value('HOME'))
169
+ # fallback to 'default' ugly...
170
+ assert_equal('.', @it.value('unknown', 'HOME'))
171
+ end
172
+ end
173
+
174
+ def test_value_ENV
175
+ OpenSSL::TestUtils.silent do
176
+ key = ENV.keys.first
177
+ assert_not_nil(key) # make sure we have at least one ENV var.
178
+ assert_equal(ENV[key], @it.value('ENV', key))
179
+ end
180
+ end
181
+
182
+ def test_aref
183
+ assert_equal({'HOME' => '.'}, @it['default'])
184
+ assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it['CA_default'])
185
+ assert_equal({}, @it['no_such_section'])
186
+ assert_equal({}, @it[''])
187
+ end
188
+
189
+ def test_section
190
+ OpenSSL::TestUtils.silent do
191
+ assert_equal({'HOME' => '.'}, @it.section('default'))
192
+ assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it.section('CA_default'))
193
+ assert_equal({}, @it.section('no_such_section'))
194
+ assert_equal({}, @it.section(''))
195
+ end
196
+ end
197
+
198
+ def test_sections
199
+ assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
200
+ @it['new_section'] = {'foo' => 'bar'}
201
+ assert_equal(['CA_default', 'ca', 'default', 'new_section'], @it.sections.sort)
202
+ @it['new_section'] = {}
203
+ assert_equal(['CA_default', 'ca', 'default', 'new_section'], @it.sections.sort)
204
+ end
205
+
206
+ def test_add_value
207
+ c = OpenSSL::Config.new
208
+ assert_equal("", c.to_s)
209
+ # add key
210
+ c.add_value('default', 'foo', 'bar')
211
+ assert_equal("[ default ]\nfoo=bar\n\n", c.to_s)
212
+ # add another key
213
+ c.add_value('default', 'baz', 'qux')
214
+ assert_equal('bar', c['default']['foo'])
215
+ assert_equal('qux', c['default']['baz'])
216
+ # update the value
217
+ c.add_value('default', 'baz', 'quxxx')
218
+ assert_equal('bar', c['default']['foo'])
219
+ assert_equal('quxxx', c['default']['baz'])
220
+ # add section and key
221
+ c.add_value('section', 'foo', 'bar')
222
+ assert_equal('bar', c['default']['foo'])
223
+ assert_equal('quxxx', c['default']['baz'])
224
+ assert_equal('bar', c['section']['foo'])
225
+ end
226
+
227
+ def test_aset
228
+ @it['foo'] = {'bar' => 'baz'}
229
+ assert_equal({'bar' => 'baz'}, @it['foo'])
230
+ @it['foo'] = {'bar' => 'qux', 'baz' => 'quxx'}
231
+ assert_equal({'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
232
+
233
+ # OpenSSL::Config is add only for now.
234
+ @it['foo'] = {'foo' => 'foo'}
235
+ assert_equal({'foo' => 'foo', 'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
236
+ # you cannot override or remove any section and key.
237
+ @it['foo'] = {}
238
+ assert_equal({'foo' => 'foo', 'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
239
+ end
240
+
241
+ def test_each
242
+ # each returns [section, key, value] array.
243
+ ary = @it.map { |e| e }.sort { |a, b| a[0] <=> b[0] }
244
+ assert_equal(4, ary.size)
245
+ assert_equal('CA_default', ary[0][0])
246
+ assert_equal('CA_default', ary[1][0])
247
+ assert_equal(["ca", "default_ca", "CA_default"], ary[2])
248
+ assert_equal(["default", "HOME", "."], ary[3])
249
+ end
250
+
251
+ def test_to_s
252
+ c = OpenSSL::Config.parse("[empty]\n")
253
+ assert_equal("[ default ]\n\n[ empty ]\n\n", c.to_s)
254
+ end
255
+
256
+ def test_inspect
257
+ assert_match(/#<OpenSSL::Config sections=\[.*\]>/, @it.inspect)
258
+ end
259
+
260
+ def test_freeze
261
+ c = OpenSSL::Config.new
262
+ c['foo'] = [['key', 'value']]
263
+ c.freeze
264
+
265
+ bug = '[ruby-core:18377]'
266
+ # RuntimeError for 1.9, TypeError for 1.8
267
+ e = assert_raise(TypeError, bug) do
268
+ c['foo'] = [['key', 'wrong']]
269
+ end
270
+ assert_match(/can't modify/, e.message, bug)
271
+ end
272
+
273
+ def test_dup
274
+ assert(!@it.sections.empty?)
275
+ c = @it.dup
276
+ assert_equal(@it.sections.sort, c.sections.sort)
277
+ @it['newsection'] = {'a' => 'b'}
278
+ assert_not_equal(@it.sections.sort, c.sections.sort)
279
+ end
280
+
281
+ def test_clone
282
+ assert(!@it.sections.empty?)
283
+ c = @it.clone
284
+ assert_equal(@it.sections.sort, c.sections.sort)
285
+ @it['newsection'] = {'a' => 'b'}
286
+ assert_not_equal(@it.sections.sort, c.sections.sort)
287
+ end
288
+ end if defined?(OpenSSL)