Skip to content

Commit 9783d7f

Browse files
committed
config: remove deprecated methods
Remove 4 deprecated methods. The following two methods have been marked as deprecated since 2003, by r4531 (ruby.git commit 78ff3833fb67c8005a9b851037e74b3eea940aa3). - OpenSSL::Config#value - OpenSSL::Config#section Other two methods are removed because the corresponding functions disappeared in OpenSSL 1.1.0. - OpenSSL::Config#add_value - OpenSSL::Config#[]=
1 parent 41587f6 commit 9783d7f

File tree

2 files changed

+16
-202
lines changed

2 files changed

+16
-202
lines changed

lib/openssl/config.rb

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -297,50 +297,6 @@ def get_value(section, key)
297297
get_key_string(section, key)
298298
end
299299

300-
##
301-
#
302-
# *Deprecated*
303-
#
304-
# Use #get_value instead
305-
def value(arg1, arg2 = nil) # :nodoc:
306-
warn('Config#value is deprecated; use Config#get_value')
307-
if arg2.nil?
308-
section, key = 'default', arg1
309-
else
310-
section, key = arg1, arg2
311-
end
312-
section ||= 'default'
313-
section = 'default' if section.empty?
314-
get_key_string(section, key)
315-
end
316-
317-
##
318-
# *Deprecated in v2.2.0*. This method will be removed in a future release.
319-
#
320-
# Set the target _key_ with a given _value_ under a specific _section_.
321-
#
322-
# Given the following configurating file being loaded:
323-
#
324-
# config = OpenSSL::Config.load('foo.cnf')
325-
# #=> #<OpenSSL::Config sections=["default"]>
326-
# puts config.to_s
327-
# #=> [ default ]
328-
# # foo=bar
329-
#
330-
# You can set the value of _foo_ under the _default_ section to a new
331-
# value:
332-
#
333-
# config.add_value('default', 'foo', 'buzz')
334-
# #=> "buzz"
335-
# puts config.to_s
336-
# #=> [ default ]
337-
# # foo=buzz
338-
#
339-
def add_value(section, key, value)
340-
check_modify
341-
(@data[section] ||= {})[key] = value
342-
end
343-
344300
##
345301
# Get a specific _section_ from the current configuration
346302
#
@@ -361,46 +317,6 @@ def [](section)
361317
@data[section] || {}
362318
end
363319

364-
##
365-
# Deprecated
366-
#
367-
# Use #[] instead
368-
def section(name) # :nodoc:
369-
warn('Config#section is deprecated; use Config#[]')
370-
@data[name] || {}
371-
end
372-
373-
##
374-
# *Deprecated in v2.2.0*. This method will be removed in a future release.
375-
#
376-
# Sets a specific _section_ name with a Hash _pairs_.
377-
#
378-
# Given the following configuration being created:
379-
#
380-
# config = OpenSSL::Config.new
381-
# #=> #<OpenSSL::Config sections=[]>
382-
# config['default'] = {"foo"=>"bar","baz"=>"buz"}
383-
# #=> {"foo"=>"bar", "baz"=>"buz"}
384-
# puts config.to_s
385-
# #=> [ default ]
386-
# # foo=bar
387-
# # baz=buz
388-
#
389-
# It's important to note that this will essentially merge any of the keys
390-
# in _pairs_ with the existing _section_. For example:
391-
#
392-
# config['default']
393-
# #=> {"foo"=>"bar", "baz"=>"buz"}
394-
# config['default'] = {"foo" => "changed"}
395-
# #=> {"foo"=>"changed"}
396-
# config['default']
397-
# #=> {"foo"=>"changed", "baz"=>"buz"}
398-
#
399-
def []=(section, pairs)
400-
check_modify
401-
set_section(section, pairs)
402-
end
403-
404320
def set_section(section, pairs) # :nodoc:
405321
hash = @data[section] ||= {}
406322
pairs.each do |key, value|
@@ -488,12 +404,6 @@ def initialize_copy(other)
488404
@data = other.data.dup
489405
end
490406

491-
def check_modify
492-
warn "#{caller(2, 1)[0]}: warning: do not modify OpenSSL::Config; this " \
493-
"method is deprecated and will be removed in a future release."
494-
raise TypeError.new("Insecure: can't modify OpenSSL config") if frozen?
495-
end
496-
497407
def get_key_string(section, key)
498408
Config.get_key_string(@data, section, key)
499409
end

test/openssl/test_config.rb

Lines changed: 16 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -214,94 +214,26 @@ def test_get_value_ENV
214214
assert_equal(ENV[key], @it.get_value('ENV', key))
215215
end
216216

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-
239217
def test_aref
240218
assert_equal({'HOME' => '.'}, @it['default'])
241219
assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it['CA_default'])
242220
assert_equal({}, @it['no_such_section'])
243221
assert_equal({}, @it[''])
244222
end
245223

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-
255224
def test_sections
256225
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 ]\nfoo=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+
}
305237
end
306238

307239
def test_each
@@ -323,40 +255,12 @@ def test_inspect
323255
assert_match(/#<OpenSSL::Config sections=\[.*\]>/, @it.inspect)
324256
end
325257

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-
340258
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)
360264
end
361265

362266
private

0 commit comments

Comments
 (0)