ruby-changes:37899
From: hsbt <ko1@a...>
Date: Mon, 16 Mar 2015 17:43:46 +0900 (JST)
Subject: [ruby-changes:37899] hsbt:r49980 (trunk): * lib/webrick/server.rb: Fix regression bug in WEBrick's
hsbt 2015-03-16 17:43:28 +0900 (Mon, 16 Mar 2015) New Revision: 49980 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49980 Log: * lib/webrick/server.rb: Fix regression bug in WEBrick's :DoNotReverseLookup config option implementation. [fix GH-731] Patch by @vais * test/webrick/test_do_not_reverse_lookup.rb: ditto. Added files: trunk/test/webrick/test_do_not_reverse_lookup.rb Modified files: trunk/ChangeLog trunk/lib/webrick/server.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49979) +++ ChangeLog (revision 49980) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Mar 16 17:43:21 2015 SHIBATA Hiroshi <shibata.hiroshi@g...> + + * lib/webrick/server.rb: Fix regression bug in WEBrick's + :DoNotReverseLookup config option implementation. + [fix GH-731] Patch by @vais + * test/webrick/test_do_not_reverse_lookup.rb: ditto. + Sat Mar 14 20:05:23 2015 Kazuki Tanaka <gogotanaka@r...> * math.c (math_gamma): optimization for passed small integer. Index: lib/webrick/server.rb =================================================================== --- lib/webrick/server.rb (revision 49979) +++ lib/webrick/server.rb (revision 49980) @@ -179,7 +179,9 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L179 svrs[0].each{|svr| @tokens.pop # blocks while no token is there. if sock = accept_client(svr) - sock.do_not_reverse_lookup = config[:DoNotReverseLookup] + unless config[:DoNotReverseLookup].nil? + sock.do_not_reverse_lookup = !!config[:DoNotReverseLookup] + end th = start_thread(sock, &block) th[:WEBrickThread] = true thgroup.add(th) Index: test/webrick/test_do_not_reverse_lookup.rb =================================================================== --- test/webrick/test_do_not_reverse_lookup.rb (revision 0) +++ test/webrick/test_do_not_reverse_lookup.rb (revision 49980) @@ -0,0 +1,70 @@ https://github.com/ruby/ruby/blob/trunk/test/webrick/test_do_not_reverse_lookup.rb#L1 +require "test/unit" +require "webrick" +require_relative "utils" + +class TestDoNotReverseLookup < Test::Unit::TestCase + class DNRL < WEBrick::GenericServer + def run(sock) + sock << sock.do_not_reverse_lookup.to_s + end + end + + @@original_do_not_reverse_lookup_value = Socket.do_not_reverse_lookup + + def teardown + Socket.do_not_reverse_lookup = @@original_do_not_reverse_lookup_value + end + + def do_not_reverse_lookup?(config) + result = nil + TestWEBrick.start_server(DNRL, config) do |server, addr, port, log| + TCPSocket.open(addr, port) do |sock| + result = {'true' => true, 'false' => false}[sock.gets] + end + end + result + end + + # +--------------------------------------------------------------------------+ + # | Expected interaction between Socket.do_not_reverse_lookup | + # | and WEBrick::Config::General[:DoNotReverseLookup] | + # +----------------------------+---------------------------------------------+ + # | |WEBrick::Config::General[:DoNotReverseLookup]| + # +----------------------------+--------------+---------------+--------------+ + # |Socket.do_not_reverse_lookup| TRUE | FALSE | NIL | + # +----------------------------+--------------+---------------+--------------+ + # | TRUE | true | false | true | + # +----------------------------+--------------+---------------+--------------+ + # | FALSE | true | false | false | + # +----------------------------+--------------+---------------+--------------+ + + def test_socket_dnrl_true_server_dnrl_true + Socket.do_not_reverse_lookup = true + assert_equal(true, do_not_reverse_lookup?(:DoNotReverseLookup => true)) + end + + def test_socket_dnrl_true_server_dnrl_false + Socket.do_not_reverse_lookup = true + assert_equal(false, do_not_reverse_lookup?(:DoNotReverseLookup => false)) + end + + def test_socket_dnrl_true_server_dnrl_nil + Socket.do_not_reverse_lookup = true + assert_equal(true, do_not_reverse_lookup?(:DoNotReverseLookup => nil)) + end + + def test_socket_dnrl_false_server_dnrl_true + Socket.do_not_reverse_lookup = false + assert_equal(true, do_not_reverse_lookup?(:DoNotReverseLookup => true)) + end + + def test_socket_dnrl_false_server_dnrl_false + Socket.do_not_reverse_lookup = false + assert_equal(false, do_not_reverse_lookup?(:DoNotReverseLookup => false)) + end + + def test_socket_dnrl_false_server_dnrl_nil + Socket.do_not_reverse_lookup = false + assert_equal(false, do_not_reverse_lookup?(:DoNotReverseLookup => nil)) + end +end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/