[前][次][番号順一覧][スレッド一覧]

ruby-changes:65532

From: Kazuki <ko1@a...>
Date: Tue, 16 Mar 2021 20:38:38 +0900 (JST)
Subject: [ruby-changes:65532] 67f5847c61 (master): [ruby/openssl] config: remove deprecated methods

https://git.ruby-lang.org/ruby.git/commit/?id=67f5847c61

From 67f5847c617e49a314400cb8f1ff1d559492682c Mon Sep 17 00:00:00 2001
From: Kazuki Yamaguchi <k@r...>
Date: Wed, 19 Feb 2020 04:44:31 +0000
Subject: [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 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#[]=

https://github.com/ruby/openssl/commit/9783d7f21c
---
 ext/openssl/lib/openssl/config.rb |  90 ---------------------------
 test/openssl/test_config.rb       | 128 +++++---------------------------------
 2 files changed, 16 insertions(+), 202 deletions(-)

diff --git a/ext/openssl/lib/openssl/config.rb b/ext/openssl/lib/openssl/config.rb
index 9a0b787..46e1711 100644
--- a/ext/openssl/lib/openssl/config.rb
+++ b/ext/openssl/lib/openssl/config.rb
@@ -298,50 +298,6 @@ module OpenSSL https://github.com/ruby/ruby/blob/trunk/ext/openssl/lib/openssl/config.rb#L298
     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
     #
     # Given the following configurating file being loaded:
@@ -361,46 +317,6 @@ module OpenSSL https://github.com/ruby/ruby/blob/trunk/ext/openssl/lib/openssl/config.rb#L317
       @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 https://github.com/ruby/ruby/blob/trunk/ext/openssl/lib/openssl/config.rb#L404
       @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
diff --git a/test/openssl/test_config.rb b/test/openssl/test_config.rb
index f65392c..984a115 100644
--- a/test/openssl/test_config.rb
+++ b/test/openssl/test_config.rb
@@ -214,28 +214,6 @@ __EOC__ https://github.com/ruby/ruby/blob/trunk/test/openssl/test_config.rb#L214
     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__ https://github.com/ruby/ruby/blob/trunk/test/openssl/test_config.rb#L221
     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
-
-  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
+    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
+
+      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__ https://github.com/ruby/ruby/blob/trunk/test/openssl/test_config.rb#L255
     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
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]