jruby-openssl-maven 0.7.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. data/History.txt +171 -0
  2. data/License.txt +30 -0
  3. data/Manifest.txt +115 -0
  4. data/README.txt +13 -0
  5. data/Rakefile +79 -0
  6. data/lib/jopenssl.jar +0 -0
  7. data/lib/jopenssl/version.rb +5 -0
  8. data/lib/openssl.rb +76 -0
  9. data/lib/openssl/bn.rb +35 -0
  10. data/lib/openssl/buffering.rb +239 -0
  11. data/lib/openssl/cipher.rb +65 -0
  12. data/lib/openssl/config.rb +316 -0
  13. data/lib/openssl/digest.rb +61 -0
  14. data/lib/openssl/dummy.rb +33 -0
  15. data/lib/openssl/dummyssl.rb +14 -0
  16. data/lib/openssl/pkcs7.rb +25 -0
  17. data/lib/openssl/ssl.rb +179 -0
  18. data/lib/openssl/x509.rb +154 -0
  19. data/test/cert_with_ec_pk.cer +27 -0
  20. data/test/fixture/ca-bundle.crt +2794 -0
  21. data/test/fixture/ca_path/72fa7371.0 +19 -0
  22. data/test/fixture/ca_path/verisign.pem +19 -0
  23. data/test/fixture/cacert.pem +23 -0
  24. data/test/fixture/cert_localhost.pem +19 -0
  25. data/test/fixture/common.pem +48 -0
  26. data/test/fixture/imaps/cacert.pem +60 -0
  27. data/test/fixture/imaps/server.crt +61 -0
  28. data/test/fixture/imaps/server.key +15 -0
  29. data/test/fixture/key_then_cert.pem +34 -0
  30. data/test/fixture/keypair.pem +27 -0
  31. data/test/fixture/localhost_keypair.pem +18 -0
  32. data/test/fixture/max.pem +29 -0
  33. data/test/fixture/purpose/b70a5bc1.0 +24 -0
  34. data/test/fixture/purpose/ca/PASSWD_OF_CA_KEY_IS_1234 +0 -0
  35. data/test/fixture/purpose/ca/ca_config.rb +37 -0
  36. data/test/fixture/purpose/ca/cacert.pem +24 -0
  37. data/test/fixture/purpose/ca/newcerts/2_cert.pem +19 -0
  38. data/test/fixture/purpose/ca/newcerts/3_cert.pem +19 -0
  39. data/test/fixture/purpose/ca/private/cakeypair.pem +30 -0
  40. data/test/fixture/purpose/ca/serial +1 -0
  41. data/test/fixture/purpose/cacert.pem +24 -0
  42. data/test/fixture/purpose/scripts/gen_cert.rb +127 -0
  43. data/test/fixture/purpose/scripts/gen_csr.rb +50 -0
  44. data/test/fixture/purpose/scripts/init_ca.rb +66 -0
  45. data/test/fixture/purpose/sslclient.pem +19 -0
  46. data/test/fixture/purpose/sslclient/csr.pem +10 -0
  47. data/test/fixture/purpose/sslclient/keypair.pem +15 -0
  48. data/test/fixture/purpose/sslclient/sslclient.pem +19 -0
  49. data/test/fixture/purpose/sslserver.pem +19 -0
  50. data/test/fixture/purpose/sslserver/csr.pem +10 -0
  51. data/test/fixture/purpose/sslserver/keypair.pem +15 -0
  52. data/test/fixture/purpose/sslserver/sslserver.pem +19 -0
  53. data/test/fixture/selfcert.pem +23 -0
  54. data/test/fixture/verisign.pem +19 -0
  55. data/test/fixture/verisign_c3.pem +14 -0
  56. data/test/java/pkcs7_mime_enveloped.message +19 -0
  57. data/test/java/pkcs7_mime_signed.message +30 -0
  58. data/test/java/pkcs7_multipart_signed.message +45 -0
  59. data/test/java/test_java_attribute.rb +25 -0
  60. data/test/java/test_java_bio.rb +42 -0
  61. data/test/java/test_java_mime.rb +173 -0
  62. data/test/java/test_java_pkcs7.rb +772 -0
  63. data/test/java/test_java_smime.rb +177 -0
  64. data/test/openssl/ssl_server.rb +99 -0
  65. data/test/openssl/test_asn1.rb +197 -0
  66. data/test/openssl/test_cipher.rb +193 -0
  67. data/test/openssl/test_config.rb +290 -0
  68. data/test/openssl/test_digest.rb +88 -0
  69. data/test/openssl/test_ec.rb +128 -0
  70. data/test/openssl/test_hmac.rb +46 -0
  71. data/test/openssl/test_ns_spki.rb +59 -0
  72. data/test/openssl/test_pair.rb +141 -0
  73. data/test/openssl/test_pkcs7.rb +489 -0
  74. data/test/openssl/test_pkey_rsa.rb +49 -0
  75. data/test/openssl/test_ssl.rb +1035 -0
  76. data/test/openssl/test_x509cert.rb +277 -0
  77. data/test/openssl/test_x509crl.rb +253 -0
  78. data/test/openssl/test_x509ext.rb +99 -0
  79. data/test/openssl/test_x509name.rb +290 -0
  80. data/test/openssl/test_x509req.rb +195 -0
  81. data/test/openssl/test_x509store.rb +246 -0
  82. data/test/openssl/utils.rb +144 -0
  83. data/test/ref/a.out +0 -0
  84. data/test/ref/compile.rb +8 -0
  85. data/test/ref/pkcs1 +0 -0
  86. data/test/ref/pkcs1.c +21 -0
  87. data/test/test_all.rb +1 -0
  88. data/test/test_certificate.rb +123 -0
  89. data/test/test_cipher.rb +197 -0
  90. data/test/test_imaps.rb +107 -0
  91. data/test/test_integration.rb +144 -0
  92. data/test/test_java.rb +98 -0
  93. data/test/test_openssl.rb +4 -0
  94. data/test/test_parse_certificate.rb +27 -0
  95. data/test/test_pkcs7.rb +40 -0
  96. data/test/test_pkey.rb +204 -0
  97. data/test/test_ssl.rb +97 -0
  98. data/test/test_x509store.rb +160 -0
  99. data/test/ut_eof.rb +128 -0
  100. metadata +161 -0
@@ -0,0 +1,193 @@
1
+ begin
2
+ require "openssl"
3
+ rescue LoadError
4
+ end
5
+ require "test/unit"
6
+
7
+ if defined?(OpenSSL)
8
+
9
+ class OpenSSL::TestCipher < Test::Unit::TestCase
10
+ def setup
11
+ @c1 = OpenSSL::Cipher::Cipher.new("DES-EDE3-CBC")
12
+ @c2 = OpenSSL::Cipher::DES.new(:EDE3, "CBC")
13
+ @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"
14
+ @iv = "\0\0\0\0\0\0\0\0"
15
+ @iv1 = "\1\1\1\1\1\1\1\1"
16
+ @hexkey = "0000000000000000000000000000000000000000000000"
17
+ @hexiv = "0000000000000000"
18
+ @data = "DATA"
19
+ end
20
+
21
+ def teardown
22
+ @c1 = @c2 = nil
23
+ end
24
+
25
+ def test_crypt
26
+ @c1.encrypt.pkcs5_keyivgen(@key, @iv)
27
+ @c2.encrypt.pkcs5_keyivgen(@key, @iv)
28
+ s1 = @c1.update(@data) + @c1.final
29
+ s2 = @c2.update(@data) + @c2.final
30
+ assert_equal(s1, s2, "encrypt")
31
+
32
+ @c1.decrypt.pkcs5_keyivgen(@key, @iv)
33
+ @c2.decrypt.pkcs5_keyivgen(@key, @iv)
34
+ assert_equal(@data, @c1.update(s1)+@c1.final, "decrypt")
35
+ assert_equal(@data, @c2.update(s2)+@c2.final, "decrypt")
36
+ end
37
+
38
+ def test_info
39
+ assert_equal("DES-EDE3-CBC", @c1.name, "name")
40
+ assert_equal("DES-EDE3-CBC", @c2.name, "name")
41
+ assert_kind_of(Fixnum, @c1.key_len, "key_len")
42
+ assert_kind_of(Fixnum, @c1.iv_len, "iv_len")
43
+ end
44
+
45
+ def test_dup
46
+ assert_equal(@c1.name, @c1.dup.name, "dup")
47
+ assert_equal(@c1.name, @c1.clone.name, "clone")
48
+ @c1.encrypt
49
+ @c1.key = @key
50
+ @c1.iv = @iv
51
+ tmpc = @c1.dup
52
+ s1 = @c1.update(@data) + @c1.final
53
+ s2 = tmpc.update(@data) + tmpc.final
54
+ assert_equal(s1, s2, "encrypt dup")
55
+ end
56
+
57
+ def test_reset
58
+ @c1.encrypt
59
+ @c1.key = @key
60
+ @c1.iv = @iv
61
+ s1 = @c1.update(@data) + @c1.final
62
+ @c1.reset
63
+ s2 = @c1.update(@data) + @c1.final
64
+ assert_equal(s1, s2, "encrypt reset")
65
+ end
66
+
67
+ def test_set_iv
68
+ @c1.encrypt
69
+ @c1.key = @key
70
+ @c1.iv = @iv
71
+ s1 = @c1.update(@data) + @c1.final
72
+ @c1.iv = @iv1
73
+ s1 += @c1.update(@data) + @c1.final
74
+ @c1.reset
75
+ @c1.iv = @iv
76
+ s2 = @c1.update(@data) + @c1.final
77
+ @c1.iv = @iv1
78
+ s2 += @c1.update(@data) + @c1.final
79
+ assert_equal(s1, s2, "encrypt reset")
80
+ end
81
+
82
+ def test_empty_data
83
+ @c1.encrypt
84
+ assert_raise(ArgumentError){ @c1.update("") }
85
+ end
86
+
87
+ def test_disable_padding(padding=0)
88
+ # assume a padding size of 8
89
+ # encrypt the data with padding
90
+ @c1.encrypt
91
+ @c1.key = @key
92
+ @c1.iv = @iv
93
+ encrypted_data = @c1.update(@data) + @c1.final
94
+ assert_equal(8, encrypted_data.size)
95
+ # decrypt with padding disabled
96
+ @c1.decrypt
97
+ @c1.padding = padding
98
+ decrypted_data = @c1.update(encrypted_data) + @c1.final
99
+ # check that the result contains the padding
100
+ assert_equal(8, decrypted_data.size)
101
+ assert_equal(@data, decrypted_data[0...@data.size])
102
+ end
103
+
104
+ if RUBY_PLATFORM =~ /java/
105
+ # JRuby extension - using Java padding types
106
+
107
+ def test_disable_padding_javastyle
108
+ test_disable_padding('NoPadding')
109
+ end
110
+
111
+ def test_iso10126_padding
112
+ @c1.encrypt
113
+ @c1.key = @key
114
+ @c1.iv = @iv
115
+ @c1.padding = 'ISO10126Padding'
116
+ encrypted_data = @c1.update(@data) + @c1.final
117
+ # decrypt with padding disabled to see the padding
118
+ @c1.decrypt
119
+ @c1.padding = 0
120
+ decrypted_data = @c1.update(encrypted_data) + @c1.final
121
+ assert_equal(@data, decrypted_data[0...@data.size])
122
+ # last byte should be the amount of padding
123
+ assert_equal(4, decrypted_data[-1])
124
+ end
125
+
126
+ def test_iso10126_padding_boundry
127
+ @data = 'HELODATA' # 8 bytes, same as padding size
128
+ @c1.encrypt
129
+ @c1.key = @key
130
+ @c1.iv = @iv
131
+ @c1.padding = 'ISO10126Padding'
132
+ encrypted_data = @c1.update(@data) + @c1.final
133
+ # decrypt with padding disabled to see the padding
134
+ @c1.decrypt
135
+ @c1.padding = 0
136
+ decrypted_data = @c1.update(encrypted_data) + @c1.final
137
+ assert_equal(@data, decrypted_data[0...@data.size])
138
+ # padding should be one whole block
139
+ assert_equal(8, decrypted_data[-1])
140
+ end
141
+ end
142
+
143
+ if OpenSSL::OPENSSL_VERSION_NUMBER > 0x00907000
144
+ def test_ciphers
145
+ OpenSSL::Cipher.ciphers.each{|name|
146
+ assert(OpenSSL::Cipher::Cipher.new(name).is_a?(OpenSSL::Cipher::Cipher))
147
+ }
148
+ end
149
+
150
+ def test_AES
151
+ pt = File.read(__FILE__)
152
+ %w(ECB CBC CFB OFB).each{|mode|
153
+ c1 = OpenSSL::Cipher::AES256.new(mode)
154
+ c1.encrypt
155
+ assert_nothing_raised('This test fails w/o Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files') do
156
+ c1.pkcs5_keyivgen("passwd")
157
+ end
158
+ ct = c1.update(pt) + c1.final
159
+
160
+ c2 = OpenSSL::Cipher::AES256.new(mode)
161
+ c2.decrypt
162
+ c2.pkcs5_keyivgen("passwd")
163
+ assert_equal(pt, c2.update(ct) + c2.final)
164
+ }
165
+ end
166
+ end
167
+
168
+ # JRUBY-4028
169
+ def test_jruby_4028
170
+ key = "0599E113A7EE32A9"
171
+ data = "1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%2Fmix-stage.oracle.com%2F~00"
172
+ c1 = OpenSSL::Cipher::Cipher.new("DES-CBC")
173
+ c1.padding = 0
174
+ c1.iv = "0" * 8
175
+ c1.encrypt
176
+ c1.key = key
177
+ e = c1.update data
178
+ e << c1.final
179
+
180
+ c2 = OpenSSL::Cipher::Cipher.new("DES-CBC")
181
+ c2.padding = 0
182
+ c2.iv = "0" * 8
183
+ c2.decrypt
184
+ c2.key = key
185
+ d = c2.update e
186
+ d << c2.final
187
+
188
+ assert_equal "\342\320B.\300&X\310\344\253\025\215\017*\22015\344\024D\342\213\361\336\311\271\326\016\243\214\026\2545\002\237,\017s\202\316&Ew\323\221H\376\200\304\201\365\332Im\240\361\037\246\3536\001A2\341\324o0\350\364%=\325\330\240\324u\225\304h\277\272\361f\024\324\352\336\353N\002/]C\370!\003)\212oa\225\207\333\340\245\207\024\351\037\327[\212\001{\216\f\315\345\372\v\226\r\233?\002\vJK", e
189
+ assert_equal data, d
190
+ end
191
+ end
192
+
193
+ end
@@ -0,0 +1,290 @@
1
+ require 'openssl'
2
+ require "test/unit"
3
+ require 'tempfile'
4
+ require File.join(File.dirname(__FILE__), "utils.rb")
5
+
6
+ class OpenSSL::TestConfig < Test::Unit::TestCase
7
+ def setup
8
+ file = Tempfile.open("openssl.cnf")
9
+ file << <<__EOD__
10
+ HOME = .
11
+ [ ca ]
12
+ default_ca = CA_default
13
+ [ CA_default ]
14
+ dir = ./demoCA
15
+ certs = ./certs
16
+ __EOD__
17
+ file.close
18
+ @it = OpenSSL::Config.new(file.path)
19
+ end
20
+
21
+ def TODO_test_constants
22
+ assert(defined?(OpenSSL::Config::DEFAULT_CONFIG_FILE))
23
+ assert_nothing_raised do
24
+ OpenSSL::Config.load(OpenSSL::Config::DEFAULT_CONFIG_FILE)
25
+ end
26
+ end
27
+
28
+ def test_s_parse
29
+ c = OpenSSL::Config.parse('')
30
+ assert_equal("[ default ]\n\n", c.to_s)
31
+ c = OpenSSL::Config.parse(@it.to_s)
32
+ assert_equal(['CA_default', 'ca', 'default'], c.sections.sort)
33
+ end
34
+
35
+ def test_s_parse_format
36
+ c = OpenSSL::Config.parse(<<__EOC__)
37
+ baz =qx\t # "baz = qx"
38
+
39
+ foo::bar = baz # shortcut section::key format
40
+ default::bar = baz # ditto
41
+ a=\t \t # "a = ": trailing spaces are ignored
42
+ =b # " = b": empty key
43
+ =c # " = c": empty key (override the above line)
44
+ d= # "c = ": trailing comment is ignored
45
+
46
+ sq = 'foo''b\\'ar'
47
+ dq ="foo""''\\""
48
+ dq2 = foo""bar
49
+ esc=a\\r\\n\\b\\tb
50
+ foo\\bar = foo\\b\\\\ar
51
+ foo\\bar::foo\\bar = baz
52
+ [default1 default2]\t\t # space is allowed in section name
53
+ fo =b ar # space allowed in value
54
+ [emptysection]
55
+ [doller ]
56
+ foo=bar
57
+ bar = $(foo)
58
+ baz = 123$(default::bar)456${foo}798
59
+ qux = ${baz}
60
+ quxx = $qux.$qux
61
+ __EOC__
62
+ assert_equal(['default', 'default1 default2', 'doller', 'emptysection', 'foo', 'foo\\bar'], c.sections.sort)
63
+ assert_equal(['', 'a', 'bar', 'baz', 'd', 'dq', 'dq2', 'esc', 'foo\\bar', 'sq'], c['default'].keys.sort)
64
+ assert_equal('c', c['default'][''])
65
+ assert_equal('', c['default']['a'])
66
+ assert_equal('qx', c['default']['baz'])
67
+ assert_equal('', c['default']['d'])
68
+ assert_equal('baz', c['default']['bar'])
69
+ assert_equal("foob'ar", c['default']['sq'])
70
+ assert_equal("foo''\"", c['default']['dq'])
71
+ assert_equal("foobar", c['default']['dq2'])
72
+ assert_equal("a\r\n\b\tb", c['default']['esc'])
73
+ assert_equal("foo\b\\ar", c['default']['foo\\bar'])
74
+ assert_equal('baz', c['foo']['bar'])
75
+ assert_equal('baz', c['foo\\bar']['foo\\bar'])
76
+ assert_equal('b ar', c['default1 default2']['fo'])
77
+
78
+ # dolloer
79
+ assert_equal('bar', c['doller']['foo'])
80
+ assert_equal('bar', c['doller']['bar'])
81
+ assert_equal('123baz456bar798', c['doller']['baz'])
82
+ assert_equal('123baz456bar798', c['doller']['qux'])
83
+ assert_equal('123baz456bar798.123baz456bar798', c['doller']['quxx'])
84
+
85
+ excn = assert_raise(OpenSSL::ConfigError) do
86
+ OpenSSL::Config.parse("foo = $bar")
87
+ end
88
+ assert_equal("error in line 1: variable has no value", excn.message)
89
+
90
+ excn = assert_raise(OpenSSL::ConfigError) do
91
+ OpenSSL::Config.parse("foo = $(bar")
92
+ end
93
+ assert_equal("error in line 1: no close brace", excn.message)
94
+
95
+ excn = assert_raise(OpenSSL::ConfigError) do
96
+ OpenSSL::Config.parse("f o =b ar # no space in key")
97
+ end
98
+ assert_equal("error in line 1: missing equal sign", excn.message)
99
+
100
+ excn = assert_raise(OpenSSL::ConfigError) do
101
+ OpenSSL::Config.parse(<<__EOC__)
102
+ # comment 1 # comments
103
+
104
+ #
105
+ # comment 2
106
+ \t#comment 3
107
+ [second ]\t
108
+ [third # section not terminated
109
+ __EOC__
110
+ end
111
+ assert_equal("error in line 7: missing close square bracket", excn.message)
112
+ end
113
+
114
+ def test_s_load
115
+ # alias of new
116
+ c = OpenSSL::Config.load
117
+ assert_equal("", c.to_s)
118
+ assert_equal([], c.sections)
119
+ #
120
+ file = Tempfile.open("openssl.cnf")
121
+ file.close
122
+ c = OpenSSL::Config.load(file.path)
123
+ assert_equal("[ default ]\n\n", c.to_s)
124
+ assert_equal(['default'], c.sections)
125
+ end
126
+
127
+ def test_initialize
128
+ c = OpenSSL::Config.new
129
+ assert_equal("", c.to_s)
130
+ assert_equal([], c.sections)
131
+ end
132
+
133
+ def test_initialize_with_empty_file
134
+ file = Tempfile.open("openssl.cnf")
135
+ file.close
136
+ c = OpenSSL::Config.new(file.path)
137
+ assert_equal("[ default ]\n\n", c.to_s)
138
+ assert_equal(['default'], c.sections)
139
+ end
140
+
141
+ def test_initialize_with_example_file
142
+ assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
143
+ end
144
+
145
+ def test_get_value
146
+ assert_equal('CA_default', @it.get_value('ca', 'default_ca'))
147
+ assert_equal(nil, @it.get_value('ca', 'no such key'))
148
+ assert_equal(nil, @it.get_value('no such section', 'no such key'))
149
+ assert_equal('.', @it.get_value('', 'HOME'))
150
+ assert_raise(TypeError) do
151
+ @it.get_value(nil, 'HOME') # not allowed unlike Config#value
152
+ end
153
+ # fallback to 'default' ugly...
154
+ assert_equal('.', @it.get_value('unknown', 'HOME'))
155
+ end
156
+
157
+ def test_get_value_ENV
158
+ key = ENV.keys.first
159
+ assert_not_nil(key) # make sure we have at least one ENV var.
160
+ assert_equal(ENV[key], @it.get_value('ENV', key))
161
+ end
162
+
163
+ def test_value
164
+ # supress deprecation warnings
165
+ OpenSSL::TestUtils.silent do
166
+ assert_equal('CA_default', @it.value('ca', 'default_ca'))
167
+ assert_equal(nil, @it.value('ca', 'no such key'))
168
+ assert_equal(nil, @it.value('no such section', 'no such key'))
169
+ assert_equal('.', @it.value('', 'HOME'))
170
+ assert_equal('.', @it.value(nil, 'HOME'))
171
+ assert_equal('.', @it.value('HOME'))
172
+ # fallback to 'default' ugly...
173
+ assert_equal('.', @it.value('unknown', 'HOME'))
174
+ end
175
+ end
176
+
177
+ def test_value_ENV
178
+ OpenSSL::TestUtils.silent do
179
+ key = ENV.keys.first
180
+ assert_not_nil(key) # make sure we have at least one ENV var.
181
+ assert_equal(ENV[key], @it.value('ENV', key))
182
+ end
183
+ end
184
+
185
+ def test_aref
186
+ assert_equal({'HOME' => '.'}, @it['default'])
187
+ assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it['CA_default'])
188
+ assert_equal({}, @it['no_such_section'])
189
+ assert_equal({}, @it[''])
190
+ end
191
+
192
+ def test_section
193
+ OpenSSL::TestUtils.silent do
194
+ assert_equal({'HOME' => '.'}, @it.section('default'))
195
+ assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it.section('CA_default'))
196
+ assert_equal({}, @it.section('no_such_section'))
197
+ assert_equal({}, @it.section(''))
198
+ end
199
+ end
200
+
201
+ def test_sections
202
+ assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
203
+ @it['new_section'] = {'foo' => 'bar'}
204
+ assert_equal(['CA_default', 'ca', 'default', 'new_section'], @it.sections.sort)
205
+ @it['new_section'] = {}
206
+ assert_equal(['CA_default', 'ca', 'default', 'new_section'], @it.sections.sort)
207
+ end
208
+
209
+ def test_add_value
210
+ c = OpenSSL::Config.new
211
+ assert_equal("", c.to_s)
212
+ # add key
213
+ c.add_value('default', 'foo', 'bar')
214
+ assert_equal("[ default ]\nfoo=bar\n\n", c.to_s)
215
+ # add another key
216
+ c.add_value('default', 'baz', 'qux')
217
+ assert_equal('bar', c['default']['foo'])
218
+ assert_equal('qux', c['default']['baz'])
219
+ # update the value
220
+ c.add_value('default', 'baz', 'quxxx')
221
+ assert_equal('bar', c['default']['foo'])
222
+ assert_equal('quxxx', c['default']['baz'])
223
+ # add section and key
224
+ c.add_value('section', 'foo', 'bar')
225
+ assert_equal('bar', c['default']['foo'])
226
+ assert_equal('quxxx', c['default']['baz'])
227
+ assert_equal('bar', c['section']['foo'])
228
+ end
229
+
230
+ def test_aset
231
+ @it['foo'] = {'bar' => 'baz'}
232
+ assert_equal({'bar' => 'baz'}, @it['foo'])
233
+ @it['foo'] = {'bar' => 'qux', 'baz' => 'quxx'}
234
+ assert_equal({'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
235
+
236
+ # OpenSSL::Config is add only for now.
237
+ @it['foo'] = {'foo' => 'foo'}
238
+ assert_equal({'foo' => 'foo', 'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
239
+ # you cannot override or remove any section and key.
240
+ @it['foo'] = {}
241
+ assert_equal({'foo' => 'foo', 'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
242
+ end
243
+
244
+ def test_each
245
+ # each returns [section, key, value] array.
246
+ ary = @it.map { |e| e }.sort { |a, b| a[0] <=> b[0] }
247
+ assert_equal(4, ary.size)
248
+ assert_equal('CA_default', ary[0][0])
249
+ assert_equal('CA_default', ary[1][0])
250
+ assert_equal(["ca", "default_ca", "CA_default"], ary[2])
251
+ assert_equal(["default", "HOME", "."], ary[3])
252
+ end
253
+
254
+ def test_to_s
255
+ c = OpenSSL::Config.parse("[empty]\n")
256
+ assert_equal("[ default ]\n\n[ empty ]\n\n", c.to_s)
257
+ end
258
+
259
+ def test_inspect
260
+ assert_match(/#<OpenSSL::Config sections=\[.*\]>/, @it.inspect)
261
+ end
262
+
263
+ def test_freeze
264
+ c = OpenSSL::Config.new
265
+ c['foo'] = [['key', 'value']]
266
+ c.freeze
267
+
268
+ # [ruby-core:18377]
269
+ # RuntimeError for 1.9, TypeError for 1.8
270
+ assert_raise(TypeError, /frozen/) do
271
+ c['foo'] = [['key', 'wrong']]
272
+ end
273
+ end
274
+
275
+ def test_dup
276
+ assert(!@it.sections.empty?)
277
+ c = @it.dup
278
+ assert_equal(@it.sections.sort, c.sections.sort)
279
+ @it['newsection'] = {'a' => 'b'}
280
+ assert_not_equal(@it.sections.sort, c.sections.sort)
281
+ end
282
+
283
+ def test_clone
284
+ assert(!@it.sections.empty?)
285
+ c = @it.clone
286
+ assert_equal(@it.sections.sort, c.sections.sort)
287
+ @it['newsection'] = {'a' => 'b'}
288
+ assert_not_equal(@it.sections.sort, c.sections.sort)
289
+ end
290
+ end