@@ -214,94 +214,26 @@ def test_get_value_ENV
214
214
assert_equal ( ENV [ key ] , @it . get_value ( 'ENV' , key ) )
215
215
end
216
216
217
- def test_value
218
- # suppress deprecation warnings
219
- EnvUtil . suppress_warning do
220
- assert_equal ( 'CA_default' , @it . value ( 'ca' , 'default_ca' ) )
221
- assert_equal ( nil , @it . value ( 'ca' , 'no such key' ) )
222
- assert_equal ( nil , @it . value ( 'no such section' , 'no such key' ) )
223
- assert_equal ( '.' , @it . value ( '' , 'HOME' ) )
224
- assert_equal ( '.' , @it . value ( nil , 'HOME' ) )
225
- assert_equal ( '.' , @it . value ( 'HOME' ) )
226
- # fallback to 'default' ugly...
227
- assert_equal ( '.' , @it . value ( 'unknown' , 'HOME' ) )
228
- end
229
- end
230
-
231
- def test_value_ENV
232
- EnvUtil . suppress_warning do
233
- key = ENV . keys . first
234
- assert_not_nil ( key ) # make sure we have at least one ENV var.
235
- assert_equal ( ENV [ key ] , @it . value ( 'ENV' , key ) )
236
- end
237
- end
238
-
239
217
def test_aref
240
218
assert_equal ( { 'HOME' => '.' } , @it [ 'default' ] )
241
219
assert_equal ( { 'dir' => './demoCA' , 'certs' => './certs' } , @it [ 'CA_default' ] )
242
220
assert_equal ( { } , @it [ 'no_such_section' ] )
243
221
assert_equal ( { } , @it [ '' ] )
244
222
end
245
223
246
- def test_section
247
- EnvUtil . suppress_warning do
248
- assert_equal ( { 'HOME' => '.' } , @it . section ( 'default' ) )
249
- assert_equal ( { 'dir' => './demoCA' , 'certs' => './certs' } , @it . section ( 'CA_default' ) )
250
- assert_equal ( { } , @it . section ( 'no_such_section' ) )
251
- assert_equal ( { } , @it . section ( '' ) )
252
- end
253
- end
254
-
255
224
def test_sections
256
225
assert_equal ( [ 'CA_default' , 'ca' , 'default' ] , @it . sections . sort )
257
- # OpenSSL::Config#[]= is deprecated
258
- EnvUtil . suppress_warning do
259
- @it [ 'new_section' ] = { 'foo' => 'bar' }
260
- assert_equal ( [ 'CA_default' , 'ca' , 'default' , 'new_section' ] , @it . sections . sort )
261
- @it [ 'new_section' ] = { }
262
- assert_equal ( [ 'CA_default' , 'ca' , 'default' , 'new_section' ] , @it . sections . sort )
263
- end
264
- end
265
-
266
- def test_add_value
267
- # OpenSSL::Config#add_value is deprecated
268
- EnvUtil . suppress_warning do
269
- c = OpenSSL ::Config . new
270
- assert_equal ( "" , c . to_s )
271
- # add key
272
- c . add_value ( 'default' , 'foo' , 'bar' )
273
- assert_equal ( "[ default ]\n foo=bar\n \n " , c . to_s )
274
- # add another key
275
- c . add_value ( 'default' , 'baz' , 'qux' )
276
- assert_equal ( 'bar' , c [ 'default' ] [ 'foo' ] )
277
- assert_equal ( 'qux' , c [ 'default' ] [ 'baz' ] )
278
- # update the value
279
- c . add_value ( 'default' , 'baz' , 'quxxx' )
280
- assert_equal ( 'bar' , c [ 'default' ] [ 'foo' ] )
281
- assert_equal ( 'quxxx' , c [ 'default' ] [ 'baz' ] )
282
- # add section and key
283
- c . add_value ( 'section' , 'foo' , 'bar' )
284
- assert_equal ( 'bar' , c [ 'default' ] [ 'foo' ] )
285
- assert_equal ( 'quxxx' , c [ 'default' ] [ 'baz' ] )
286
- assert_equal ( 'bar' , c [ 'section' ] [ 'foo' ] )
287
- end
288
- end
289
-
290
- def test_aset
291
- # OpenSSL::Config#[]= is deprecated
292
- EnvUtil . suppress_warning do
293
- @it [ 'foo' ] = { 'bar' => 'baz' }
294
- assert_equal ( { 'bar' => 'baz' } , @it [ 'foo' ] )
295
- @it [ 'foo' ] = { 'bar' => 'qux' , 'baz' => 'quxx' }
296
- assert_equal ( { 'bar' => 'qux' , 'baz' => 'quxx' } , @it [ 'foo' ] )
297
-
298
- # OpenSSL::Config is add only for now.
299
- @it [ 'foo' ] = { 'foo' => 'foo' }
300
- assert_equal ( { 'foo' => 'foo' , 'bar' => 'qux' , 'baz' => 'quxx' } , @it [ 'foo' ] )
301
- # you cannot override or remove any section and key.
302
- @it [ 'foo' ] = { }
303
- assert_equal ( { 'foo' => 'foo' , 'bar' => 'qux' , 'baz' => 'quxx' } , @it [ 'foo' ] )
304
- end
226
+ Tempfile . create ( "openssl.cnf" ) { |f |
227
+ f . write File . read ( @tmpfile . path )
228
+ f . puts "[ new_section ]"
229
+ f . puts "foo = bar"
230
+ f . puts "[ empty_section ]"
231
+ f . close
232
+
233
+ c = OpenSSL ::Config . new ( f . path )
234
+ assert_equal ( [ 'CA_default' , 'ca' , 'default' , 'empty_section' , 'new_section' ] ,
235
+ c . sections . sort )
236
+ }
305
237
end
306
238
307
239
def test_each
@@ -323,40 +255,12 @@ def test_inspect
323
255
assert_match ( /#<OpenSSL::Config sections=\[ .*\] >/ , @it . inspect )
324
256
end
325
257
326
- def test_freeze
327
- @it . freeze
328
-
329
- # Modifying OpenSSL::Config produces a warning
330
- EnvUtil . suppress_warning do
331
- bug = '[ruby-core:18377]'
332
- # RuntimeError for 1.9, TypeError for 1.8
333
- e = assert_raise ( TypeError , bug ) do
334
- @it [ 'foo' ] = [ [ 'key' , 'wrong' ] ]
335
- end
336
- assert_match ( /can't modify/ , e . message , bug )
337
- end
338
- end
339
-
340
258
def test_dup
341
- assert ( !@it . sections . empty? )
342
- c = @it . dup
343
- assert_equal ( @it . sections . sort , c . sections . sort )
344
- # OpenSSL::Config#[]= is deprecated
345
- EnvUtil . suppress_warning do
346
- @it [ 'newsection' ] = { 'a' => 'b' }
347
- assert_not_equal ( @it . sections . sort , c . sections . sort )
348
- end
349
- end
350
-
351
- def test_clone
352
- assert ( !@it . sections . empty? )
353
- c = @it . clone
354
- assert_equal ( @it . sections . sort , c . sections . sort )
355
- # OpenSSL::Config#[]= is deprecated
356
- EnvUtil . suppress_warning do
357
- @it [ 'newsection' ] = { 'a' => 'b' }
358
- assert_not_equal ( @it . sections . sort , c . sections . sort )
359
- end
259
+ assert_equal ( [ 'CA_default' , 'ca' , 'default' ] , @it . sections . sort )
260
+ c1 = @it . dup
261
+ assert_equal ( @it . sections . sort , c1 . sections . sort )
262
+ c2 = @it . clone
263
+ assert_equal ( @it . sections . sort , c2 . sections . sort )
360
264
end
361
265
362
266
private
0 commit comments