ruby-changes:48135
From: knu <ko1@a...>
Date: Sat, 21 Oct 2017 18:53:57 +0900 (JST)
Subject: [ruby-changes:48135] knu:r60249 (trunk): Make ACL::ACLEntry not suppress IPAddr::InvalidPrefixError
knu 2017-10-21 18:53:52 +0900 (Sat, 21 Oct 2017) New Revision: 60249 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60249 Log: Make ACL::ACLEntry not suppress IPAddr::InvalidPrefixError This is because it would be a user error because a pattern containing a slash shouldn't be a host name pattern but an IP address pattern. Modified files: trunk/NEWS trunk/lib/drb/acl.rb trunk/test/drb/test_acl.rb Index: test/drb/test_acl.rb =================================================================== --- test/drb/test_acl.rb (revision 60248) +++ test/drb/test_acl.rb (revision 60249) @@ -66,9 +66,9 @@ class ACLEntryTest < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/drb/test_acl.rb#L66 assert_not_operator(a, :match, @hosts['localhost']) assert_operator(a, :match, @hosts['yum']) - a = ACL::ACLEntry.new('192.168.0.1/255.255.0.255') + a = ACL::ACLEntry.new('192.168.1.0/255.255.255.0') assert_not_operator(a, :match, @hosts['localhost']) - assert_not_operator(a, :match, @hosts['yum']) + assert_operator(a, :match, @hosts['yum']) assert_operator(a, :match, @hosts['x68k']) a = ACL::ACLEntry.new('192.168.1.0/24') @@ -81,10 +81,14 @@ class ACLEntryTest < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/drb/test_acl.rb#L81 assert_not_operator(a, :match, @hosts['yum']) assert_not_operator(a, :match, @hosts['x68k']) - a = ACL::ACLEntry.new('127.0.0.1/255.0.0.255') + a = ACL::ACLEntry.new('127.0.0.0/255.0.0.0') assert_operator(a, :match, @hosts['localhost']) assert_not_operator(a, :match, @hosts['yum']) assert_not_operator(a, :match, @hosts['x68k']) + + assert_raise(IPAddr::InvalidPrefixError) { + ACL::ACLEntry.new('192.168.0.0/33') + } end def test_name @@ -136,10 +140,12 @@ class ACLListTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/drb/test_acl.rb#L140 end def test_1 - a = build(%w(192.0.0.1/255.0.0.255 yum.*.jp)) - assert_operator(a, :match, @hosts['yum']) + a = build(%w(192.168.1.0/255.255.255.252 yum.*.jp)) assert_operator(a, :match, @hosts['x68k']) - assert_not_operator(a, :match, @hosts['lc630']) + assert_operator(a, :match, @hosts['lc630']) + assert_operator(a, :match, @hosts['lib30']) + assert_not_operator(a, :match, @hosts['ns00']) + assert_operator(a, :match, @hosts['yum']) end def test_2 Index: lib/drb/acl.rb =================================================================== --- lib/drb/acl.rb (revision 60248) +++ lib/drb/acl.rb (revision 60249) @@ -49,6 +49,9 @@ class ACL https://github.com/ruby/ruby/blob/trunk/lib/drb/acl.rb#L49 # +str+ may be "*" or "all" to match any address, an IP address string # to match a specific address, an IP address mask per IPAddr, or one # containing "*" to match part of an IPv4 address. + # + # IPAddr::InvalidPrefixError may be raised when an IP network + # address with an invalid netmask/prefix is given. def initialize(str) if str == '*' or str == 'all' @@ -58,6 +61,10 @@ class ACL https://github.com/ruby/ruby/blob/trunk/lib/drb/acl.rb#L61 else begin @pat = [:ip, IPAddr.new(str)] + rescue IPAddr::InvalidPrefixError + # In this case, `str` shouldn't be a host name pattern + # because it contains a slash. + raise rescue ArgumentError @pat = [:name, dot_pat(str)] end Index: NEWS =================================================================== --- NEWS (revision 60248) +++ NEWS (revision 60249) @@ -134,6 +134,9 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L134 * Add Bundler to Standard Library. [Feature #12733] +* DRb + * ACL::ACLEntry.new no longer suppresses IPAddr::InvalidPrefixError. + * ERB * Add ERB#result_with_hash to render a template with local variables passed with a Hash object. [Feature #8631] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/