зеркало из https://github.com/github/ruby.git
[ruby/openssl] config: remove deprecated methods
Remove 4 deprecated methods.
The following two methods have been marked as deprecated since 2003,
by r4531 (ruby.git commit 78ff3833fb
).
- 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#[]=
https://github.com/ruby/openssl/commit/9783d7f21c
This commit is contained in:
Родитель
4d8bce227c
Коммит
67f5847c61
|
@ -297,50 +297,6 @@ module OpenSSL
|
|||
get_key_string(section, key)
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# *Deprecated*
|
||||
#
|
||||
# Use #get_value instead
|
||||
def value(arg1, arg2 = nil) # :nodoc:
|
||||
warn('Config#value is deprecated; use Config#get_value')
|
||||
if arg2.nil?
|
||||
section, key = 'default', arg1
|
||||
else
|
||||
section, key = arg1, arg2
|
||||
end
|
||||
section ||= 'default'
|
||||
section = 'default' if section.empty?
|
||||
get_key_string(section, key)
|
||||
end
|
||||
|
||||
##
|
||||
# *Deprecated in v2.2.0*. This method will be removed in a future release.
|
||||
#
|
||||
# Set the target _key_ with a given _value_ under a specific _section_.
|
||||
#
|
||||
# Given the following configurating file being loaded:
|
||||
#
|
||||
# config = OpenSSL::Config.load('foo.cnf')
|
||||
# #=> #<OpenSSL::Config sections=["default"]>
|
||||
# puts config.to_s
|
||||
# #=> [ default ]
|
||||
# # foo=bar
|
||||
#
|
||||
# You can set the value of _foo_ under the _default_ section to a new
|
||||
# value:
|
||||
#
|
||||
# config.add_value('default', 'foo', 'buzz')
|
||||
# #=> "buzz"
|
||||
# puts config.to_s
|
||||
# #=> [ default ]
|
||||
# # foo=buzz
|
||||
#
|
||||
def add_value(section, key, value)
|
||||
check_modify
|
||||
(@data[section] ||= {})[key] = value
|
||||
end
|
||||
|
||||
##
|
||||
# Get a specific _section_ from the current configuration
|
||||
#
|
||||
|
@ -361,46 +317,6 @@ module OpenSSL
|
|||
@data[section] || {}
|
||||
end
|
||||
|
||||
##
|
||||
# Deprecated
|
||||
#
|
||||
# Use #[] instead
|
||||
def section(name) # :nodoc:
|
||||
warn('Config#section is deprecated; use Config#[]')
|
||||
@data[name] || {}
|
||||
end
|
||||
|
||||
##
|
||||
# *Deprecated in v2.2.0*. This method will be removed in a future release.
|
||||
#
|
||||
# Sets a specific _section_ name with a Hash _pairs_.
|
||||
#
|
||||
# Given the following configuration being created:
|
||||
#
|
||||
# config = OpenSSL::Config.new
|
||||
# #=> #<OpenSSL::Config sections=[]>
|
||||
# config['default'] = {"foo"=>"bar","baz"=>"buz"}
|
||||
# #=> {"foo"=>"bar", "baz"=>"buz"}
|
||||
# puts config.to_s
|
||||
# #=> [ default ]
|
||||
# # foo=bar
|
||||
# # baz=buz
|
||||
#
|
||||
# It's important to note that this will essentially merge any of the keys
|
||||
# in _pairs_ with the existing _section_. For example:
|
||||
#
|
||||
# config['default']
|
||||
# #=> {"foo"=>"bar", "baz"=>"buz"}
|
||||
# config['default'] = {"foo" => "changed"}
|
||||
# #=> {"foo"=>"changed"}
|
||||
# config['default']
|
||||
# #=> {"foo"=>"changed", "baz"=>"buz"}
|
||||
#
|
||||
def []=(section, pairs)
|
||||
check_modify
|
||||
set_section(section, pairs)
|
||||
end
|
||||
|
||||
def set_section(section, pairs) # :nodoc:
|
||||
hash = @data[section] ||= {}
|
||||
pairs.each do |key, value|
|
||||
|
@ -488,12 +404,6 @@ module OpenSSL
|
|||
@data = other.data.dup
|
||||
end
|
||||
|
||||
def check_modify
|
||||
warn "#{caller(2, 1)[0]}: warning: do not modify OpenSSL::Config; this " \
|
||||
"method is deprecated and will be removed in a future release."
|
||||
raise TypeError.new("Insecure: can't modify OpenSSL config") if frozen?
|
||||
end
|
||||
|
||||
def get_key_string(section, key)
|
||||
Config.get_key_string(@data, section, key)
|
||||
end
|
||||
|
|
|
@ -214,28 +214,6 @@ __EOC__
|
|||
assert_equal(ENV[key], @it.get_value('ENV', key))
|
||||
end
|
||||
|
||||
def test_value
|
||||
# suppress deprecation warnings
|
||||
EnvUtil.suppress_warning do
|
||||
assert_equal('CA_default', @it.value('ca', 'default_ca'))
|
||||
assert_equal(nil, @it.value('ca', 'no such key'))
|
||||
assert_equal(nil, @it.value('no such section', 'no such key'))
|
||||
assert_equal('.', @it.value('', 'HOME'))
|
||||
assert_equal('.', @it.value(nil, 'HOME'))
|
||||
assert_equal('.', @it.value('HOME'))
|
||||
# fallback to 'default' ugly...
|
||||
assert_equal('.', @it.value('unknown', 'HOME'))
|
||||
end
|
||||
end
|
||||
|
||||
def test_value_ENV
|
||||
EnvUtil.suppress_warning do
|
||||
key = ENV.keys.first
|
||||
assert_not_nil(key) # make sure we have at least one ENV var.
|
||||
assert_equal(ENV[key], @it.value('ENV', key))
|
||||
end
|
||||
end
|
||||
|
||||
def test_aref
|
||||
assert_equal({'HOME' => '.'}, @it['default'])
|
||||
assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it['CA_default'])
|
||||
|
@ -243,65 +221,19 @@ __EOC__
|
|||
assert_equal({}, @it[''])
|
||||
end
|
||||
|
||||
def test_section
|
||||
EnvUtil.suppress_warning do
|
||||
assert_equal({'HOME' => '.'}, @it.section('default'))
|
||||
assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it.section('CA_default'))
|
||||
assert_equal({}, @it.section('no_such_section'))
|
||||
assert_equal({}, @it.section(''))
|
||||
end
|
||||
end
|
||||
|
||||
def test_sections
|
||||
assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
|
||||
# OpenSSL::Config#[]= is deprecated
|
||||
EnvUtil.suppress_warning do
|
||||
@it['new_section'] = {'foo' => 'bar'}
|
||||
assert_equal(['CA_default', 'ca', 'default', 'new_section'], @it.sections.sort)
|
||||
@it['new_section'] = {}
|
||||
assert_equal(['CA_default', 'ca', 'default', 'new_section'], @it.sections.sort)
|
||||
end
|
||||
end
|
||||
Tempfile.create("openssl.cnf") { |f|
|
||||
f.write File.read(@tmpfile.path)
|
||||
f.puts "[ new_section ]"
|
||||
f.puts "foo = bar"
|
||||
f.puts "[ empty_section ]"
|
||||
f.close
|
||||
|
||||
def test_add_value
|
||||
# OpenSSL::Config#add_value is deprecated
|
||||
EnvUtil.suppress_warning do
|
||||
c = OpenSSL::Config.new
|
||||
assert_equal("", c.to_s)
|
||||
# add key
|
||||
c.add_value('default', 'foo', 'bar')
|
||||
assert_equal("[ default ]\nfoo=bar\n\n", c.to_s)
|
||||
# add another key
|
||||
c.add_value('default', 'baz', 'qux')
|
||||
assert_equal('bar', c['default']['foo'])
|
||||
assert_equal('qux', c['default']['baz'])
|
||||
# update the value
|
||||
c.add_value('default', 'baz', 'quxxx')
|
||||
assert_equal('bar', c['default']['foo'])
|
||||
assert_equal('quxxx', c['default']['baz'])
|
||||
# add section and key
|
||||
c.add_value('section', 'foo', 'bar')
|
||||
assert_equal('bar', c['default']['foo'])
|
||||
assert_equal('quxxx', c['default']['baz'])
|
||||
assert_equal('bar', c['section']['foo'])
|
||||
end
|
||||
end
|
||||
|
||||
def test_aset
|
||||
# OpenSSL::Config#[]= is deprecated
|
||||
EnvUtil.suppress_warning do
|
||||
@it['foo'] = {'bar' => 'baz'}
|
||||
assert_equal({'bar' => 'baz'}, @it['foo'])
|
||||
@it['foo'] = {'bar' => 'qux', 'baz' => 'quxx'}
|
||||
assert_equal({'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
|
||||
|
||||
# OpenSSL::Config is add only for now.
|
||||
@it['foo'] = {'foo' => 'foo'}
|
||||
assert_equal({'foo' => 'foo', 'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
|
||||
# you cannot override or remove any section and key.
|
||||
@it['foo'] = {}
|
||||
assert_equal({'foo' => 'foo', 'bar' => 'qux', 'baz' => 'quxx'}, @it['foo'])
|
||||
end
|
||||
c = OpenSSL::Config.new(f.path)
|
||||
assert_equal(['CA_default', 'ca', 'default', 'empty_section', 'new_section'],
|
||||
c.sections.sort)
|
||||
}
|
||||
end
|
||||
|
||||
def test_each
|
||||
|
@ -323,40 +255,12 @@ __EOC__
|
|||
assert_match(/#<OpenSSL::Config sections=\[.*\]>/, @it.inspect)
|
||||
end
|
||||
|
||||
def test_freeze
|
||||
@it.freeze
|
||||
|
||||
# Modifying OpenSSL::Config produces a warning
|
||||
EnvUtil.suppress_warning do
|
||||
bug = '[ruby-core:18377]'
|
||||
# RuntimeError for 1.9, TypeError for 1.8
|
||||
e = assert_raise(TypeError, bug) do
|
||||
@it['foo'] = [['key', 'wrong']]
|
||||
end
|
||||
assert_match(/can't modify/, e.message, bug)
|
||||
end
|
||||
end
|
||||
|
||||
def test_dup
|
||||
assert(!@it.sections.empty?)
|
||||
c = @it.dup
|
||||
assert_equal(@it.sections.sort, c.sections.sort)
|
||||
# OpenSSL::Config#[]= is deprecated
|
||||
EnvUtil.suppress_warning do
|
||||
@it['newsection'] = {'a' => 'b'}
|
||||
assert_not_equal(@it.sections.sort, c.sections.sort)
|
||||
end
|
||||
end
|
||||
|
||||
def test_clone
|
||||
assert(!@it.sections.empty?)
|
||||
c = @it.clone
|
||||
assert_equal(@it.sections.sort, c.sections.sort)
|
||||
# OpenSSL::Config#[]= is deprecated
|
||||
EnvUtil.suppress_warning do
|
||||
@it['newsection'] = {'a' => 'b'}
|
||||
assert_not_equal(@it.sections.sort, c.sections.sort)
|
||||
end
|
||||
assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
|
||||
c1 = @it.dup
|
||||
assert_equal(@it.sections.sort, c1.sections.sort)
|
||||
c2 = @it.clone
|
||||
assert_equal(@it.sections.sort, c2.sections.sort)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Загрузка…
Ссылка в новой задаче