ruby-changes:20620
From: nahi <ko1@a...>
Date: Mon, 25 Jul 2011 22:28:51 +0900 (JST)
Subject: [ruby-changes:20620] nahi:r32668 (ruby_1_9_3): * backport r32666 from trunk.
nahi 2011-07-25 22:25:27 +0900 (Mon, 25 Jul 2011) New Revision: 32668 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32668 Log: * backport r32666 from trunk. * lib/xmlrpc/client.rb: Fix possible HTTP header formatting failure by 'Basic' header. Long username caused the base64 String truncation in HTTP header which is not allowed. See #5046. * test/xmlrpc/test_webrick_server.rb: test it. Added files: branches/ruby_1_9_3/test/xmlrpc/htpasswd Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/lib/xmlrpc/client.rb branches/ruby_1_9_3/test/xmlrpc/test_webrick_server.rb Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 32667) +++ ruby_1_9_3/ChangeLog (revision 32668) @@ -1,3 +1,13 @@ +Mon Jul 25 22:24:09 2011 Hiroshi Nakamura <nahi@r...> + + * backport r32666 from trunk. + + * lib/xmlrpc/client.rb: Fix possible HTTP header formatting failure by + 'Basic' header. Long username caused the base64 String truncation in + HTTP header which is not allowed. See #5046. + + * test/xmlrpc/test_webrick_server.rb: test it. + Mon Jul 25 15:36:07 2011 Hiroshi Nakamura <nahi@r...> * ext/openssl/lib/openssl/{x509.rb,ssl.rb}: Add deprecation warning Index: ruby_1_9_3/lib/xmlrpc/client.rb =================================================================== --- ruby_1_9_3/lib/xmlrpc/client.rb (revision 32667) +++ ruby_1_9_3/lib/xmlrpc/client.rb (revision 32668) @@ -493,7 +493,7 @@ else a = "#@user" a << ":#@password" if @password != nil - @auth = ("Basic " + [a].pack("m")).chomp + @auth = "Basic " + [a].pack("m0") end end Index: ruby_1_9_3/test/xmlrpc/htpasswd =================================================================== --- ruby_1_9_3/test/xmlrpc/htpasswd (revision 0) +++ ruby_1_9_3/test/xmlrpc/htpasswd (revision 32668) @@ -0,0 +1,2 @@ +admin:Qg266hq/YYKe2 +01234567890123456789012345678901234567890123456789012345678901234567890123456789:Yl.SJmoFETpS2 Index: ruby_1_9_3/test/xmlrpc/test_webrick_server.rb =================================================================== --- ruby_1_9_3/test/xmlrpc/test_webrick_server.rb (revision 32667) +++ ruby_1_9_3/test/xmlrpc/test_webrick_server.rb (revision 32668) @@ -3,13 +3,25 @@ require_relative 'webrick_testing' require "xmlrpc/server" require 'xmlrpc/client' +require 'logger' class Test_Webrick < Test::Unit::TestCase include WEBrick_Testing + @@basic_auth = WEBrick::HTTPAuth::BasicAuth.new( + :Realm => 'auth', + :UserDB => WEBrick::HTTPAuth::Htpasswd.new(File.expand_path('./htpasswd', File.dirname(__FILE__))), + :Logger => Logger.new(File::NULL), + ) + def create_servlet s = XMLRPC::WEBrickServlet.new + def s.service(req, res) + @@basic_auth.authenticate(req, res) + super(req, res) + end + s.add_handler("test.add") do |a,b| a + b end @@ -46,8 +58,6 @@ end start_server(option) {|w| w.mount('/RPC2', create_servlet) } - - @s = XMLRPC::Client.new3(:port => port, :use_ssl => use_ssl) end PORT = 8070 @@ -56,13 +66,33 @@ [false].each do |use_ssl| begin setup_http_server(PORT, use_ssl) - do_test + @s = XMLRPC::Client.new3(:port => PORT, :use_ssl => use_ssl) + @s.user = 'admin' + @s.password = 'admin' + silent do + do_test + end + @s = XMLRPC::Client.new3(:port => PORT, :use_ssl => use_ssl) + @s.user = '01234567890123456789012345678901234567890123456789012345678901234567890123456789' + @s.password = 'guest' + silent do + do_test + end ensure stop_server end end end + def silent + begin + back, $VERBOSE = $VERBOSE, nil + yield + ensure + $VERBOSE = back + end + end + def do_test # simple call assert_equal 9, @s.call('test.add', 4, 5) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/