ruby-changes:8490
From: mame <ko1@a...>
Date: Wed, 29 Oct 2008 20:49:02 +0900 (JST)
Subject: [ruby-changes:8490] Ruby:r20023 (trunk, ruby_1_9_1): * test/webrick/utils.rb (start_server): provide a reference to log of
mame 2008-10-29 20:48:35 +0900 (Wed, 29 Oct 2008) New Revision: 20023 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20023 Log: * test/webrick/utils.rb (start_server): provide a reference to log of webrick. * test/webrick/test_httpproxy.rb, test/webrick/test_httpauth.rb, test/webrick/test_cgi.rb, test/webrick/test_httpserver.rb, test/webrick/test_server.rb, test/webrick/test_filehandler.rb: use webrick log as an assertion message. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/test/webrick/test_cgi.rb branches/ruby_1_9_1/test/webrick/test_filehandler.rb branches/ruby_1_9_1/test/webrick/test_httpauth.rb branches/ruby_1_9_1/test/webrick/test_httpproxy.rb branches/ruby_1_9_1/test/webrick/test_httpserver.rb branches/ruby_1_9_1/test/webrick/test_server.rb branches/ruby_1_9_1/test/webrick/utils.rb trunk/ChangeLog trunk/test/webrick/test_cgi.rb trunk/test/webrick/test_filehandler.rb trunk/test/webrick/test_httpauth.rb trunk/test/webrick/test_httpproxy.rb trunk/test/webrick/test_httpserver.rb trunk/test/webrick/test_server.rb trunk/test/webrick/utils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 20022) +++ ChangeLog (revision 20023) @@ -1,3 +1,13 @@ +Wed Oct 29 20:45:08 2008 Yusuke Endoh <mame@t...> + + * test/webrick/utils.rb (start_server): provide a reference to log of + webrick. + + * test/webrick/test_httpproxy.rb, test/webrick/test_httpauth.rb, + test/webrick/test_cgi.rb, test/webrick/test_httpserver.rb, + test/webrick/test_server.rb, test/webrick/test_filehandler.rb: use + webrick log as an assertion message. + Wed Oct 29 16:41:17 2008 Nobuyoshi Nakada <nobu@r...> * pack.c (pack_pack): set encoding from packing string and UTF-8 for Index: test/webrick/test_httpauth.rb =================================================================== --- test/webrick/test_httpauth.rb (revision 20022) +++ test/webrick/test_httpauth.rb (revision 20023) @@ -7,7 +7,7 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase def test_basic_auth - TestWEBrick.start_httpserver{|server, addr, port| + TestWEBrick.start_httpserver{|server, addr, port, log| realm = "WEBrick's realm" path = "/basic_auth" @@ -20,14 +20,14 @@ http = Net::HTTP.new(addr, port) g = Net::HTTP::Get.new(path) g.basic_auth("webrick", "supersecretpassword") - http.request(g){|res| assert_equal("hoge", res.body)} + http.request(g){|res| assert_equal("hoge", res.body, log.call)} g.basic_auth("webrick", "not super") - http.request(g){|res| assert_not_equal("hoge", res.body)} + http.request(g){|res| assert_not_equal("hoge", res.body, log.call)} } end def test_basic_auth2 - TestWEBrick.start_httpserver{|server, addr, port| + TestWEBrick.start_httpserver{|server, addr, port, log| realm = "WEBrick's realm" path = "/basic_auth2" @@ -41,9 +41,9 @@ htpasswd = WEBrick::HTTPAuth::Htpasswd.new(tmpfile.path) users = [] htpasswd.each{|user, pass| users << user } - assert_equal(2, users.size) - assert(users.member?("webrick")) - assert(users.member?("foo")) + assert_equal(2, users.size, log.call) + assert(users.member?("webrick"), log.call) + assert(users.member?("foo"), log.call) server.mount_proc(path){|req, res| auth = WEBrick::HTTPAuth::BasicAuth.new( @@ -56,9 +56,9 @@ http = Net::HTTP.new(addr, port) g = Net::HTTP::Get.new(path) g.basic_auth("webrick", "supersecretpassword") - http.request(g){|res| assert_equal("hoge", res.body)} + http.request(g){|res| assert_equal("hoge", res.body, log.call)} g.basic_auth("webrick", "not super") - http.request(g){|res| assert_not_equal("hoge", res.body)} + http.request(g){|res| assert_not_equal("hoge", res.body, log.call)} } end Index: test/webrick/test_httpproxy.rb =================================================================== --- test/webrick/test_httpproxy.rb (revision 20022) +++ test/webrick/test_httpproxy.rb (revision 20023) @@ -35,7 +35,7 @@ :ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1 }, :RequestHandler => Proc.new{|req, res| request_handler_called += 1 } } - TestWEBrick.start_httpproxy(config){|server, addr, port| + TestWEBrick.start_httpproxy(config){|server, addr, port, log| server.mount_proc("/"){|req, res| res.body = "#{req.request_method} #{req.path} #{req.body}" } @@ -43,28 +43,28 @@ req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("1.1 localhost.localdomain:#{port}", res["via"]) - assert_equal("GET / ", res.body) + assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call) + assert_equal("GET / ", res.body, log.call) } - assert_equal(1, proxy_handler_called) - assert_equal(2, request_handler_called) + assert_equal(1, proxy_handler_called, log.call) + assert_equal(2, request_handler_called, log.call) req = Net::HTTP::Head.new("/") http.request(req){|res| - assert_equal("1.1 localhost.localdomain:#{port}", res["via"]) - assert_nil(res.body) + assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call) + assert_nil(res.body, log.call) } - assert_equal(2, proxy_handler_called) - assert_equal(4, request_handler_called) + assert_equal(2, proxy_handler_called, log.call) + assert_equal(4, request_handler_called, log.call) req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| - assert_equal("1.1 localhost.localdomain:#{port}", res["via"]) - assert_equal("POST / post-data", res.body) + assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call) + assert_equal("POST / post-data", res.body, log.call) } - assert_equal(3, proxy_handler_called) - assert_equal(6, request_handler_called) + assert_equal(3, proxy_handler_called, log.call) + assert_equal(6, request_handler_called, log.call) } end @@ -80,7 +80,7 @@ :ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1 }, :RequestHandler => Proc.new{|req, res| request_handler_called += 1 } } - TestWEBrick.start_httpproxy(config){|server, addr, port| + TestWEBrick.start_httpproxy(config){|server, addr, port, log| server.mount_proc("/"){|req, res| res.body = "#{req.request_method} #{req.path} #{req.body}" } @@ -88,28 +88,28 @@ req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_nil(res["via"]) - assert_equal("GET / ", res.body) + assert_nil(res["via"], log.call) + assert_equal("GET / ", res.body, log.call) } - assert_equal(0, proxy_handler_called) - assert_equal(1, request_handler_called) + assert_equal(0, proxy_handler_called, log.call) + assert_equal(1, request_handler_called, log.call) req = Net::HTTP::Head.new("/") http.request(req){|res| - assert_nil(res["via"]) - assert_nil(res.body) + assert_nil(res["via"], log.call) + assert_nil(res.body, log.call) } - assert_equal(0, proxy_handler_called) - assert_equal(2, request_handler_called) + assert_equal(0, proxy_handler_called, log.call) + assert_equal(2, request_handler_called, log.call) req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| - assert_nil(res["via"]) - assert_equal("POST / post-data", res.body) + assert_nil(res["via"], log.call) + assert_equal("POST / post-data", res.body, log.call) } - assert_equal(0, proxy_handler_called) - assert_equal(3, request_handler_called) + assert_equal(0, proxy_handler_called, log.call) + assert_equal(3, request_handler_called, log.call) } end @@ -147,11 +147,11 @@ assert_equal("CONNECT", req.request_method) }, } - TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port| + TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port, s_log| s_server.mount_proc("/"){|req, res| res.body = "SSL #{req.request_method} #{req.path} #{req.body}" } - TestWEBrick.start_httpproxy(config){|server, addr, port| + TestWEBrick.start_httpproxy(config){|server, addr, port, log| http = Net::HTTP.new("127.0.0.1", s_port, addr, port) http.use_ssl = true http.verify_callback = Proc.new do |preverify_ok, store_ctx| @@ -160,13 +160,13 @@ req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("SSL GET / ", res.body) + assert_equal("SSL GET / ", res.body, s_log.call + log.call) } req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| - assert_equal("SSL POST / post-data", res.body) + assert_equal("SSL POST / post-data", res.body, s_log.call + log.call) } } } @@ -187,7 +187,7 @@ :ProxyContentHandler => Proc.new{|req, res| up_proxy_handler_called += 1}, :RequestHandler => Proc.new{|req, res| up_request_handler_called += 1} } - TestWEBrick.start_httpproxy(up_config){|up_server, up_addr, up_port| + TestWEBrick.start_httpproxy(up_config){|up_server, up_addr, up_port, up_log| up_server.mount_proc("/"){|req, res| res.body = "#{req.request_method} #{req.path} #{req.body}" } @@ -197,45 +197,45 @@ :ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1}, :RequestHandler => Proc.new{|req, res| request_handler_called += 1}, } - TestWEBrick.start_httpproxy(config){|server, addr, port| + TestWEBrick.start_httpproxy(config){|server, addr, port, log| http = Net::HTTP.new(up_addr, up_port, addr, port) req = Net::HTTP::Get.new("/") http.request(req){|res| via = res["via"].split(/,\s+/) - assert(via.include?("1.1 localhost.localdomain:#{up_port}")) - assert(via.include?("1.1 localhost.localdomain:#{port}")) + assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call) + assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call) assert_equal("GET / ", res.body) } - assert_equal(1, up_proxy_handler_called) - assert_equal(2, up_request_handler_called) - assert_equal(1, proxy_handler_called) - assert_equal(1, request_handler_called) + assert_equal(1, up_proxy_handler_called, up_log.call + log.call) + assert_equal(2, up_request_handler_called, up_log.call + log.call) + assert_equal(1, proxy_handler_called, up_log.call + log.call) + assert_equal(1, request_handler_called, up_log.call + log.call) req = Net::HTTP::Head.new("/") http.request(req){|res| via = res["via"].split(/,\s+/) - assert(via.include?("1.1 localhost.localdomain:#{up_port}")) - assert(via.include?("1.1 localhost.localdomain:#{port}")) - assert_nil(res.body) + assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call) + assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call) + assert_nil(res.body, up_log.call + log.call) } - assert_equal(2, up_proxy_handler_called) - assert_equal(4, up_request_handler_called) - assert_equal(2, proxy_handler_called) - assert_equal(2, request_handler_called) + assert_equal(2, up_proxy_handler_called, up_log.call + log.call) + assert_equal(4, up_request_handler_called, up_log.call + log.call) + assert_equal(2, proxy_handler_called, up_log.call + log.call) + assert_equal(2, request_handler_called, up_log.call + log.call) req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| via = res["via"].split(/,\s+/) - assert(via.include?("1.1 localhost.localdomain:#{up_port}")) - assert(via.include?("1.1 localhost.localdomain:#{port}")) - assert_equal("POST / post-data", res.body) + assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call) + assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call) + assert_equal("POST / post-data", res.body, up_log.call + log.call) } - assert_equal(3, up_proxy_handler_called) - assert_equal(6, up_request_handler_called) - assert_equal(3, proxy_handler_called) - assert_equal(3, request_handler_called) + assert_equal(3, up_proxy_handler_called, up_log.call + log.call) + assert_equal(6, up_request_handler_called, up_log.call + log.call) + assert_equal(3, proxy_handler_called, up_log.call + log.call) + assert_equal(3, request_handler_called, up_log.call + log.call) if defined?(OpenSSL) # Testing CONNECT to the upstream proxy server @@ -253,11 +253,11 @@ :SSLCertificate => cert, :SSLPrivateKey => key, } - TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port| + TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port, s_log| s_server.mount_proc("/"){|req, res| res.body = "SSL #{req.request_method} #{req.path} #{req.body}" } - http = Net::HTTP.new("127.0.0.1", s_port, addr, port) + http = Net::HTTP.new("127.0.0.1", s_port, addr, port, up_log.call + log.call + s_log.call) http.use_ssl = true http.verify_callback = Proc.new do |preverify_ok, store_ctx| store_ctx.current_cert.to_der == cert.to_der @@ -265,13 +265,13 @@ req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("SSL GET / ", res.body) + assert_equal("SSL GET / ", res.body, up_log.call + log.call + s_log.call) } req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| - assert_equal("SSL POST / post-data", res.body) + assert_equal("SSL POST / post-data", res.body, up_log.call + log.call + s_log.call) } } end Index: test/webrick/utils.rb =================================================================== --- test/webrick/utils.rb (revision 20022) +++ test/webrick/utils.rb (revision 20023) @@ -27,23 +27,30 @@ module_function def start_server(klass, config={}, &block) + log_string = "" + logger = Object.new + logger.instance_eval do + define_singleton_method(:<<) {|msg| log_string << msg } + end + log = proc { "webrick log start:\n" + log_string.gsub(/^/, " ").chomp + "\nwebrick log end" } server = klass.new({ :BindAddress => "127.0.0.1", :Port => 0, :ShutdownSocketWithoutClose =>true, :ServerType => Thread, - :Logger => WEBrick::Log.new(NullWriter), - :AccessLog => [[NullWriter, ""]] + :Logger => WEBrick::Log.new(logger), + :AccessLog => [[logger, ""]] }.update(config)) begin server.start addr = server.listeners[0].addr - block.yield([server, addr[3], addr[1]]) + block.yield([server, addr[3], addr[1], log]) ensure server.shutdown until server.status == :Stop sleep 0.1 end end + log_string end def start_httpserver(config={}, &block) Index: test/webrick/test_cgi.rb =================================================================== --- test/webrick/test_cgi.rb (revision 20022) +++ test/webrick/test_cgi.rb (revision 20023) @@ -21,41 +21,41 @@ if RUBY_PLATFORM =~ /mswin32|mingw|cygwin|bccwin32/ config[:CGIPathEnv] = ENV['PATH'] # runtime dll may not be in system dir. end - TestWEBrick.start_httpserver(config){|server, addr, port| - block.call(server, addr, port) + TestWEBrick.start_httpserver(config){|server, addr, port, log| + block.call(server, addr, port, log) } end def test_cgi - start_cgi_server{|server, addr, port| + start_cgi_server{|server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/webrick.cgi") - http.request(req){|res| assert_equal("/webrick.cgi", res.body)} + http.request(req){|res| assert_equal("/webrick.cgi", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi/path/info") - http.request(req){|res| assert_equal("/path/info", res.body)} + http.request(req){|res| assert_equal("/path/info", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi/%3F%3F%3F?foo=bar") - http.request(req){|res| assert_equal("/???", res.body)} + http.request(req){|res| assert_equal("/???", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi/%A4%DB%A4%B2/%A4%DB%A4%B2") http.request(req){|res| - assert_equal("/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2", res.body)} + assert_equal("/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi?a=1;a=2;b=x") - http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body)} + http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi?a=1&a=2&b=x") - http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body)} + http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body, log.call)} req = Net::HTTP::Post.new("/webrick.cgi?a=x;a=y;b=1") req["Content-Type"] = "application/x-www-form-urlencoded" http.request(req, "a=1;a=2;b=x"){|res| - assert_equal("a=1, a=2, b=x", res.body)} + assert_equal("a=1, a=2, b=x", res.body, log.call)} req = Net::HTTP::Post.new("/webrick.cgi?a=x&a=y&b=1") req["Content-Type"] = "application/x-www-form-urlencoded" http.request(req, "a=1&a=2&b=x"){|res| - assert_equal("a=1, a=2, b=x", res.body)} + assert_equal("a=1, a=2, b=x", res.body, log.call)} req = Net::HTTP::Get.new("/") http.request(req){|res| ary = res.body.lines.to_a - assert_match(%r{/$}, ary[0]) - assert_match(%r{/webrick.cgi$}, ary[1]) + assert_match(%r{/$}, ary[0], log.call) + assert_match(%r{/webrick.cgi$}, ary[1], log.call) } req = Net::HTTP::Get.new("/webrick.cgi") @@ -63,7 +63,7 @@ http.request(req){|res| assert_equal( "CUSTOMER=WILE_E_COYOTE\nPART_NUMBER=ROCKET_LAUNCHER_0001\n", - res.body) + res.body, log.call) } req = Net::HTTP::Get.new("/webrick.cgi") @@ -74,16 +74,16 @@ req["Cookie"] = cookie http.request(req){|res| assert_equal("Customer=WILE_E_COYOTE, Shipping=FedEx", - res["Set-Cookie"]) + res["Set-Cookie"], log.call) assert_equal("Customer=WILE_E_COYOTE\n" + "Part_Number=Rocket_Launcher_0001\n" + - "Shipping=FedEx\n", res.body) + "Shipping=FedEx\n", res.body, log.call) } } end def test_bad_request - start_cgi_server{|server, addr, port| + start_cgi_server{|server, addr, port, log| sock = TCPSocket.new(addr, port) begin sock << "POST /webrick.cgi HTTP/1.0" << CRLF @@ -92,7 +92,7 @@ sock << CRLF sock << "a=1&a=2&b=x" sock.close_write - assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, sock.read) + assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, sock.read, log.call) ensure sock.close end Index: test/webrick/test_httpserver.rb =================================================================== --- test/webrick/test_httpserver.rb (revision 20022) +++ test/webrick/test_httpserver.rb (revision 20023) @@ -223,7 +223,7 @@ :StopCallback => Proc.new{ stopped += 1 }, :RequestCallback => Proc.new{|req, res| requested0 += 1 }, } - TestWEBrick.start_httpserver(config){|server, addr, port| + TestWEBrick.start_httpserver(config){|server, addr, port, log| vhost_config = { :ServerName => "myhostname", :BindAddress => addr, @@ -236,23 +236,23 @@ server.virtual_host(WEBrick::HTTPServer.new(vhost_config)) true while server.status != :Running - assert_equal(started, 1) - assert_equal(stopped, 0) - assert_equal(accepted, 0) + assert_equal(started, 1, log.call) + assert_equal(stopped, 0, log.call) + assert_equal(accepted, 0, log.call) http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/") req["Host"] = "myhostname:#{port}" - http.request(req){|res| assert_equal("404", res.code)} - http.request(req){|res| assert_equal("404", res.code)} - http.request(req){|res| assert_equal("404", res.code)} + http.request(req){|res| assert_equal("404", res.code, log.call)} + http.request(req){|res| assert_equal("404", res.code, log.call)} + http.request(req){|res| assert_equal("404", res.code, log.call)} req["Host"] = "localhost:#{port}" - http.request(req){|res| assert_equal("404", res.code)} - http.request(req){|res| assert_equal("404", res.code)} - http.request(req){|res| assert_equal("404", res.code)} - assert_equal(6, accepted) - assert_equal(3, requested0) - assert_equal(3, requested1) + http.request(req){|res| assert_equal("404", res.code, log.call)} + http.request(req){|res| assert_equal("404", res.code, log.call)} + http.request(req){|res| assert_equal("404", res.code, log.call)} + assert_equal(6, accepted, log.call) + assert_equal(3, requested0, log.call) + assert_equal(3, requested1, log.call) } assert_equal(started, 1) assert_equal(stopped, 1) Index: test/webrick/test_server.rb =================================================================== --- test/webrick/test_server.rb (revision 20022) +++ test/webrick/test_server.rb (revision 20023) @@ -13,12 +13,12 @@ end def test_server - TestWEBrick.start_server(Echo){|server, addr, port| + TestWEBrick.start_server(Echo){|server, addr, port, log| TCPSocket.open(addr, port){|sock| - sock.puts("foo"); assert_equal("foo\n", sock.gets) - sock.puts("bar"); assert_equal("bar\n", sock.gets) - sock.puts("baz"); assert_equal("baz\n", sock.gets) - sock.puts("qux"); assert_equal("qux\n", sock.gets) + sock.puts("foo"); assert_equal("foo\n", sock.gets, log.call) + sock.puts("bar"); assert_equal("bar\n", sock.gets, log.call) + sock.puts("baz"); assert_equal("baz\n", sock.gets, log.call) + sock.puts("qux"); assert_equal("qux\n", sock.gets, log.call) } } end @@ -30,15 +30,15 @@ :StartCallback => Proc.new{ started += 1 }, :StopCallback => Proc.new{ stopped += 1 }, } - TestWEBrick.start_server(Echo, config){|server, addr, port| + TestWEBrick.start_server(Echo, config){|server, addr, port, log| true while server.status != :Running - assert_equal(started, 1) - assert_equal(stopped, 0) - assert_equal(accepted, 0) + assert_equal(started, 1, log.call) + assert_equal(stopped, 0, log.call) + assert_equal(accepted, 0, log.call) TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } - assert_equal(accepted, 3) + assert_equal(accepted, 3, log.call) } assert_equal(started, 1) assert_equal(stopped, 1) Index: test/webrick/test_filehandler.rb =================================================================== --- test/webrick/test_filehandler.rb (revision 20022) +++ test/webrick/test_filehandler.rb (revision 20023) @@ -75,19 +75,19 @@ def test_filehandler config = { :DocumentRoot => File.dirname(__FILE__), } this_file = File.basename(__FILE__) - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("200", res.code) - assert_equal("text/html", res.content_type) - assert_match(/HREF="#{this_file}"/, res.body) + assert_equal("200", res.code, log.call) + assert_equal("text/html", res.content_type, log.call) + assert_match(/HREF="#{this_file}"/, res.body, log.call) } req = Net::HTTP::Get.new("/#{this_file}") http.request(req){|res| - assert_equal("200", res.code) - assert_equal("text/plain", res.content_type) - assert_equal(File.read(__FILE__), res.body) + assert_equal("200", res.code, log.call) + assert_equal("text/plain", res.content_type, log.call) + assert_equal(File.read(__FILE__), res.body, log.call) } end end @@ -95,23 +95,23 @@ def test_non_disclosure_name config = { :DocumentRoot => File.dirname(__FILE__), } this_file = File.basename(__FILE__) - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) doc_root_opts = server[:DocumentRootOptions] doc_root_opts[:NondisclosureName] = %w(.ht* *~ test_*) req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("200", res.code) - assert_equal("text/html", res.content_type) + assert_equal("200", res.code, log.call) + assert_equal("text/html", res.content_type, log.call) assert_no_match(/HREF="#{File.basename(__FILE__)}"/, res.body) } req = Net::HTTP::Get.new("/#{this_file}") http.request(req){|res| - assert_equal("404", res.code) + assert_equal("404", res.code, log.call) } doc_root_opts[:NondisclosureName] = %w(.ht* *~ TEST_*) http.request(req){|res| - assert_equal("404", res.code) + assert_equal("404", res.code, log.call) } end end @@ -119,14 +119,14 @@ def test_directory_traversal config = { :DocumentRoot => File.dirname(__FILE__), } this_file = File.basename(__FILE__) - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/../../") - http.request(req){|res| assert_equal("400", res.code) } + http.request(req){|res| assert_equal("400", res.code, log.call) } req = Net::HTTP::Get.new("/..%5c../#{File.basename(__FILE__)}") - http.request(req){|res| assert_equal(windows? ? "200" : "404", res.code) } + http.request(req){|res| assert_equal(windows? ? "200" : "404", res.code, log.call) } req = Net::HTTP::Get.new("/..%5c..%5cruby.c") - http.request(req){|res| assert_equal("404", res.code) } + http.request(req){|res| assert_equal("404", res.code, log.call) } end end @@ -134,10 +134,10 @@ if windows? config = { :DocumentRoot => File.dirname(__FILE__), } this_file = File.basename(__FILE__) - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/..%5c..") - http.request(req){|res| assert_equal("301", res.code) } + http.request(req){|res| assert_equal("301", res.code, log.call) } end end end @@ -148,25 +148,25 @@ :DocumentRoot => File.dirname(__FILE__), :CGIPathEnv => ENV['PATH'], } - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/webric~1.cgi/test") http.request(req) do |res| if windows? - assert_equal("200", res.code) - assert_equal("/test", res.body) + assert_equal("200", res.code, log.call) + assert_equal("/test", res.body, log.call) else - assert_equal("404", res.code) + assert_equal("404", res.code, log.call) end end req = Net::HTTP::Get.new("/.htaccess") - http.request(req) {|res| assert_equal("404", res.code) } + http.request(req) {|res| assert_equal("404", res.code, log.call) } req = Net::HTTP::Get.new("/htacce~1") - http.request(req) {|res| assert_equal("404", res.code) } + http.request(req) {|res| assert_equal("404", res.code, log.call) } req = Net::HTTP::Get.new("/HTACCE~1") - http.request(req) {|res| assert_equal("404", res.code) } + http.request(req) {|res| assert_equal("404", res.code, log.call) } end end @@ -176,21 +176,21 @@ :DocumentRoot => File.dirname(__FILE__), :CGIPathEnv => ENV['PATH'], } - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/webrick.cgi/test") http.request(req) do |res| - assert_equal("200", res.code) - assert_equal("/test", res.body) + assert_equal("200", res.code, log.call) + assert_equal("/test", res.body, log.call) end response_assertion = Proc.new do |res| if windows? - assert_equal("200", res.code) - assert_equal("/test", res.body) + assert_equal("200", res.code, log.call) + assert_equal("/test", res.body, log.call) else - assert_equal("404", res.code) + assert_equal("404", res.code, log.call) end end req = Net::HTTP::Get.new("/webrick.cgi%20/test") Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20022) +++ ruby_1_9_1/ChangeLog (revision 20023) @@ -1,3 +1,13 @@ +Wed Oct 29 20:45:08 2008 Yusuke Endoh <mame@t...> + + * test/webrick/utils.rb (start_server): provide a reference to log of + webrick. + + * test/webrick/test_httpproxy.rb, test/webrick/test_httpauth.rb, + test/webrick/test_cgi.rb, test/webrick/test_httpserver.rb, + test/webrick/test_server.rb, test/webrick/test_filehandler.rb: use + webrick log as an assertion message. + Wed Oct 29 11:50:57 2008 Nobuyoshi Nakada <nobu@r...> * configure.in (dln-a-out): cannot make shared library nor work with Index: ruby_1_9_1/test/webrick/test_httpauth.rb =================================================================== --- ruby_1_9_1/test/webrick/test_httpauth.rb (revision 20022) +++ ruby_1_9_1/test/webrick/test_httpauth.rb (revision 20023) @@ -7,7 +7,7 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase def test_basic_auth - TestWEBrick.start_httpserver{|server, addr, port| + TestWEBrick.start_httpserver{|server, addr, port, log| realm = "WEBrick's realm" path = "/basic_auth" @@ -20,14 +20,14 @@ http = Net::HTTP.new(addr, port) g = Net::HTTP::Get.new(path) g.basic_auth("webrick", "supersecretpassword") - http.request(g){|res| assert_equal("hoge", res.body)} + http.request(g){|res| assert_equal("hoge", res.body, log.call)} g.basic_auth("webrick", "not super") - http.request(g){|res| assert_not_equal("hoge", res.body)} + http.request(g){|res| assert_not_equal("hoge", res.body, log.call)} } end def test_basic_auth2 - TestWEBrick.start_httpserver{|server, addr, port| + TestWEBrick.start_httpserver{|server, addr, port, log| realm = "WEBrick's realm" path = "/basic_auth2" @@ -41,9 +41,9 @@ htpasswd = WEBrick::HTTPAuth::Htpasswd.new(tmpfile.path) users = [] htpasswd.each{|user, pass| users << user } - assert_equal(2, users.size) - assert(users.member?("webrick")) - assert(users.member?("foo")) + assert_equal(2, users.size, log.call) + assert(users.member?("webrick"), log.call) + assert(users.member?("foo"), log.call) server.mount_proc(path){|req, res| auth = WEBrick::HTTPAuth::BasicAuth.new( @@ -56,9 +56,9 @@ http = Net::HTTP.new(addr, port) g = Net::HTTP::Get.new(path) g.basic_auth("webrick", "supersecretpassword") - http.request(g){|res| assert_equal("hoge", res.body)} + http.request(g){|res| assert_equal("hoge", res.body, log.call)} g.basic_auth("webrick", "not super") - http.request(g){|res| assert_not_equal("hoge", res.body)} + http.request(g){|res| assert_not_equal("hoge", res.body, log.call)} } end Index: ruby_1_9_1/test/webrick/test_httpproxy.rb =================================================================== --- ruby_1_9_1/test/webrick/test_httpproxy.rb (revision 20022) +++ ruby_1_9_1/test/webrick/test_httpproxy.rb (revision 20023) @@ -35,7 +35,7 @@ :ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1 }, :RequestHandler => Proc.new{|req, res| request_handler_called += 1 } } - TestWEBrick.start_httpproxy(config){|server, addr, port| + TestWEBrick.start_httpproxy(config){|server, addr, port, log| server.mount_proc("/"){|req, res| res.body = "#{req.request_method} #{req.path} #{req.body}" } @@ -43,28 +43,28 @@ req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("1.1 localhost.localdomain:#{port}", res["via"]) - assert_equal("GET / ", res.body) + assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call) + assert_equal("GET / ", res.body, log.call) } - assert_equal(1, proxy_handler_called) - assert_equal(2, request_handler_called) + assert_equal(1, proxy_handler_called, log.call) + assert_equal(2, request_handler_called, log.call) req = Net::HTTP::Head.new("/") http.request(req){|res| - assert_equal("1.1 localhost.localdomain:#{port}", res["via"]) - assert_nil(res.body) + assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call) + assert_nil(res.body, log.call) } - assert_equal(2, proxy_handler_called) - assert_equal(4, request_handler_called) + assert_equal(2, proxy_handler_called, log.call) + assert_equal(4, request_handler_called, log.call) req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| - assert_equal("1.1 localhost.localdomain:#{port}", res["via"]) - assert_equal("POST / post-data", res.body) + assert_equal("1.1 localhost.localdomain:#{port}", res["via"], log.call) + assert_equal("POST / post-data", res.body, log.call) } - assert_equal(3, proxy_handler_called) - assert_equal(6, request_handler_called) + assert_equal(3, proxy_handler_called, log.call) + assert_equal(6, request_handler_called, log.call) } end @@ -80,7 +80,7 @@ :ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1 }, :RequestHandler => Proc.new{|req, res| request_handler_called += 1 } } - TestWEBrick.start_httpproxy(config){|server, addr, port| + TestWEBrick.start_httpproxy(config){|server, addr, port, log| server.mount_proc("/"){|req, res| res.body = "#{req.request_method} #{req.path} #{req.body}" } @@ -88,28 +88,28 @@ req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_nil(res["via"]) - assert_equal("GET / ", res.body) + assert_nil(res["via"], log.call) + assert_equal("GET / ", res.body, log.call) } - assert_equal(0, proxy_handler_called) - assert_equal(1, request_handler_called) + assert_equal(0, proxy_handler_called, log.call) + assert_equal(1, request_handler_called, log.call) req = Net::HTTP::Head.new("/") http.request(req){|res| - assert_nil(res["via"]) - assert_nil(res.body) + assert_nil(res["via"], log.call) + assert_nil(res.body, log.call) } - assert_equal(0, proxy_handler_called) - assert_equal(2, request_handler_called) + assert_equal(0, proxy_handler_called, log.call) + assert_equal(2, request_handler_called, log.call) req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| - assert_nil(res["via"]) - assert_equal("POST / post-data", res.body) + assert_nil(res["via"], log.call) + assert_equal("POST / post-data", res.body, log.call) } - assert_equal(0, proxy_handler_called) - assert_equal(3, request_handler_called) + assert_equal(0, proxy_handler_called, log.call) + assert_equal(3, request_handler_called, log.call) } end @@ -147,11 +147,11 @@ assert_equal("CONNECT", req.request_method) }, } - TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port| + TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port, s_log| s_server.mount_proc("/"){|req, res| res.body = "SSL #{req.request_method} #{req.path} #{req.body}" } - TestWEBrick.start_httpproxy(config){|server, addr, port| + TestWEBrick.start_httpproxy(config){|server, addr, port, log| http = Net::HTTP.new("127.0.0.1", s_port, addr, port) http.use_ssl = true http.verify_callback = Proc.new do |preverify_ok, store_ctx| @@ -160,13 +160,13 @@ req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("SSL GET / ", res.body) + assert_equal("SSL GET / ", res.body, s_log.call + log.call) } req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| - assert_equal("SSL POST / post-data", res.body) + assert_equal("SSL POST / post-data", res.body, s_log.call + log.call) } } } @@ -187,7 +187,7 @@ :ProxyContentHandler => Proc.new{|req, res| up_proxy_handler_called += 1}, :RequestHandler => Proc.new{|req, res| up_request_handler_called += 1} } - TestWEBrick.start_httpproxy(up_config){|up_server, up_addr, up_port| + TestWEBrick.start_httpproxy(up_config){|up_server, up_addr, up_port, up_log| up_server.mount_proc("/"){|req, res| res.body = "#{req.request_method} #{req.path} #{req.body}" } @@ -197,45 +197,45 @@ :ProxyContentHandler => Proc.new{|req, res| proxy_handler_called += 1}, :RequestHandler => Proc.new{|req, res| request_handler_called += 1}, } - TestWEBrick.start_httpproxy(config){|server, addr, port| + TestWEBrick.start_httpproxy(config){|server, addr, port, log| http = Net::HTTP.new(up_addr, up_port, addr, port) req = Net::HTTP::Get.new("/") http.request(req){|res| via = res["via"].split(/,\s+/) - assert(via.include?("1.1 localhost.localdomain:#{up_port}")) - assert(via.include?("1.1 localhost.localdomain:#{port}")) + assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call) + assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call) assert_equal("GET / ", res.body) } - assert_equal(1, up_proxy_handler_called) - assert_equal(2, up_request_handler_called) - assert_equal(1, proxy_handler_called) - assert_equal(1, request_handler_called) + assert_equal(1, up_proxy_handler_called, up_log.call + log.call) + assert_equal(2, up_request_handler_called, up_log.call + log.call) + assert_equal(1, proxy_handler_called, up_log.call + log.call) + assert_equal(1, request_handler_called, up_log.call + log.call) req = Net::HTTP::Head.new("/") http.request(req){|res| via = res["via"].split(/,\s+/) - assert(via.include?("1.1 localhost.localdomain:#{up_port}")) - assert(via.include?("1.1 localhost.localdomain:#{port}")) - assert_nil(res.body) + assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call) + assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call) + assert_nil(res.body, up_log.call + log.call) } - assert_equal(2, up_proxy_handler_called) - assert_equal(4, up_request_handler_called) - assert_equal(2, proxy_handler_called) - assert_equal(2, request_handler_called) + assert_equal(2, up_proxy_handler_called, up_log.call + log.call) + assert_equal(4, up_request_handler_called, up_log.call + log.call) + assert_equal(2, proxy_handler_called, up_log.call + log.call) + assert_equal(2, request_handler_called, up_log.call + log.call) req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| via = res["via"].split(/,\s+/) - assert(via.include?("1.1 localhost.localdomain:#{up_port}")) - assert(via.include?("1.1 localhost.localdomain:#{port}")) - assert_equal("POST / post-data", res.body) + assert(via.include?("1.1 localhost.localdomain:#{up_port}"), up_log.call + log.call) + assert(via.include?("1.1 localhost.localdomain:#{port}"), up_log.call + log.call) + assert_equal("POST / post-data", res.body, up_log.call + log.call) } - assert_equal(3, up_proxy_handler_called) - assert_equal(6, up_request_handler_called) - assert_equal(3, proxy_handler_called) - assert_equal(3, request_handler_called) + assert_equal(3, up_proxy_handler_called, up_log.call + log.call) + assert_equal(6, up_request_handler_called, up_log.call + log.call) + assert_equal(3, proxy_handler_called, up_log.call + log.call) + assert_equal(3, request_handler_called, up_log.call + log.call) if defined?(OpenSSL) # Testing CONNECT to the upstream proxy server @@ -253,11 +253,11 @@ :SSLCertificate => cert, :SSLPrivateKey => key, } - TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port| + TestWEBrick.start_httpserver(s_config){|s_server, s_addr, s_port, s_log| s_server.mount_proc("/"){|req, res| res.body = "SSL #{req.request_method} #{req.path} #{req.body}" } - http = Net::HTTP.new("127.0.0.1", s_port, addr, port) + http = Net::HTTP.new("127.0.0.1", s_port, addr, port, up_log.call + log.call + s_log.call) http.use_ssl = true http.verify_callback = Proc.new do |preverify_ok, store_ctx| store_ctx.current_cert.to_der == cert.to_der @@ -265,13 +265,13 @@ req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("SSL GET / ", res.body) + assert_equal("SSL GET / ", res.body, up_log.call + log.call + s_log.call) } req = Net::HTTP::Post.new("/") req.body = "post-data" http.request(req){|res| - assert_equal("SSL POST / post-data", res.body) + assert_equal("SSL POST / post-data", res.body, up_log.call + log.call + s_log.call) } } end Index: ruby_1_9_1/test/webrick/utils.rb =================================================================== --- ruby_1_9_1/test/webrick/utils.rb (revision 20022) +++ ruby_1_9_1/test/webrick/utils.rb (revision 20023) @@ -27,23 +27,30 @@ module_function def start_server(klass, config={}, &block) + log_string = "" + logger = Object.new + logger.instance_eval do + define_singleton_method(:<<) {|msg| log_string << msg } + end + log = proc { "webrick log start:\n" + log_string.gsub(/^/, " ").chomp + "\nwebrick log end" } server = klass.new({ :BindAddress => "127.0.0.1", :Port => 0, :ShutdownSocketWithoutClose =>true, :ServerType => Thread, - :Logger => WEBrick::Log.new(NullWriter), - :AccessLog => [[NullWriter, ""]] + :Logger => WEBrick::Log.new(logger), + :AccessLog => [[logger, ""]] }.update(config)) begin server.start addr = server.listeners[0].addr - block.yield([server, addr[3], addr[1]]) + block.yield([server, addr[3], addr[1], log]) ensure server.shutdown until server.status == :Stop sleep 0.1 end end + log_string end def start_httpserver(config={}, &block) Index: ruby_1_9_1/test/webrick/test_cgi.rb =================================================================== --- ruby_1_9_1/test/webrick/test_cgi.rb (revision 20022) +++ ruby_1_9_1/test/webrick/test_cgi.rb (revision 20023) @@ -21,41 +21,41 @@ if RUBY_PLATFORM =~ /mswin32|mingw|cygwin|bccwin32/ config[:CGIPathEnv] = ENV['PATH'] # runtime dll may not be in system dir. end - TestWEBrick.start_httpserver(config){|server, addr, port| - block.call(server, addr, port) + TestWEBrick.start_httpserver(config){|server, addr, port, log| + block.call(server, addr, port, log) } end def test_cgi - start_cgi_server{|server, addr, port| + start_cgi_server{|server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/webrick.cgi") - http.request(req){|res| assert_equal("/webrick.cgi", res.body)} + http.request(req){|res| assert_equal("/webrick.cgi", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi/path/info") - http.request(req){|res| assert_equal("/path/info", res.body)} + http.request(req){|res| assert_equal("/path/info", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi/%3F%3F%3F?foo=bar") - http.request(req){|res| assert_equal("/???", res.body)} + http.request(req){|res| assert_equal("/???", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi/%A4%DB%A4%B2/%A4%DB%A4%B2") http.request(req){|res| - assert_equal("/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2", res.body)} + assert_equal("/\xA4\xDB\xA4\xB2/\xA4\xDB\xA4\xB2", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi?a=1;a=2;b=x") - http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body)} + http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body, log.call)} req = Net::HTTP::Get.new("/webrick.cgi?a=1&a=2&b=x") - http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body)} + http.request(req){|res| assert_equal("a=1, a=2, b=x", res.body, log.call)} req = Net::HTTP::Post.new("/webrick.cgi?a=x;a=y;b=1") req["Content-Type"] = "application/x-www-form-urlencoded" http.request(req, "a=1;a=2;b=x"){|res| - assert_equal("a=1, a=2, b=x", res.body)} + assert_equal("a=1, a=2, b=x", res.body, log.call)} req = Net::HTTP::Post.new("/webrick.cgi?a=x&a=y&b=1") req["Content-Type"] = "application/x-www-form-urlencoded" http.request(req, "a=1&a=2&b=x"){|res| - assert_equal("a=1, a=2, b=x", res.body)} + assert_equal("a=1, a=2, b=x", res.body, log.call)} req = Net::HTTP::Get.new("/") http.request(req){|res| ary = res.body.lines.to_a - assert_match(%r{/$}, ary[0]) - assert_match(%r{/webrick.cgi$}, ary[1]) + assert_match(%r{/$}, ary[0], log.call) + assert_match(%r{/webrick.cgi$}, ary[1], log.call) } req = Net::HTTP::Get.new("/webrick.cgi") @@ -63,7 +63,7 @@ http.request(req){|res| assert_equal( "CUSTOMER=WILE_E_COYOTE\nPART_NUMBER=ROCKET_LAUNCHER_0001\n", - res.body) + res.body, log.call) } req = Net::HTTP::Get.new("/webrick.cgi") @@ -74,16 +74,16 @@ req["Cookie"] = cookie http.request(req){|res| assert_equal("Customer=WILE_E_COYOTE, Shipping=FedEx", - res["Set-Cookie"]) + res["Set-Cookie"], log.call) assert_equal("Customer=WILE_E_COYOTE\n" + "Part_Number=Rocket_Launcher_0001\n" + - "Shipping=FedEx\n", res.body) + "Shipping=FedEx\n", res.body, log.call) } } end def test_bad_request - start_cgi_server{|server, addr, port| + start_cgi_server{|server, addr, port, log| sock = TCPSocket.new(addr, port) begin sock << "POST /webrick.cgi HTTP/1.0" << CRLF @@ -92,7 +92,7 @@ sock << CRLF sock << "a=1&a=2&b=x" sock.close_write - assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, sock.read) + assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, sock.read, log.call) ensure sock.close end Index: ruby_1_9_1/test/webrick/test_httpserver.rb =================================================================== --- ruby_1_9_1/test/webrick/test_httpserver.rb (revision 20022) +++ ruby_1_9_1/test/webrick/test_httpserver.rb (revision 20023) @@ -223,7 +223,7 @@ :StopCallback => Proc.new{ stopped += 1 }, :RequestCallback => Proc.new{|req, res| requested0 += 1 }, } - TestWEBrick.start_httpserver(config){|server, addr, port| + TestWEBrick.start_httpserver(config){|server, addr, port, log| vhost_config = { :ServerName => "myhostname", :BindAddress => addr, @@ -236,23 +236,23 @@ server.virtual_host(WEBrick::HTTPServer.new(vhost_config)) true while server.status != :Running - assert_equal(started, 1) - assert_equal(stopped, 0) - assert_equal(accepted, 0) + assert_equal(started, 1, log.call) + assert_equal(stopped, 0, log.call) + assert_equal(accepted, 0, log.call) http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/") req["Host"] = "myhostname:#{port}" - http.request(req){|res| assert_equal("404", res.code)} - http.request(req){|res| assert_equal("404", res.code)} - http.request(req){|res| assert_equal("404", res.code)} + http.request(req){|res| assert_equal("404", res.code, log.call)} + http.request(req){|res| assert_equal("404", res.code, log.call)} + http.request(req){|res| assert_equal("404", res.code, log.call)} req["Host"] = "localhost:#{port}" - http.request(req){|res| assert_equal("404", res.code)} - http.request(req){|res| assert_equal("404", res.code)} - http.request(req){|res| assert_equal("404", res.code)} - assert_equal(6, accepted) - assert_equal(3, requested0) - assert_equal(3, requested1) + http.request(req){|res| assert_equal("404", res.code, log.call)} + http.request(req){|res| assert_equal("404", res.code, log.call)} + http.request(req){|res| assert_equal("404", res.code, log.call)} + assert_equal(6, accepted, log.call) + assert_equal(3, requested0, log.call) + assert_equal(3, requested1, log.call) } assert_equal(started, 1) assert_equal(stopped, 1) Index: ruby_1_9_1/test/webrick/test_server.rb =================================================================== --- ruby_1_9_1/test/webrick/test_server.rb (revision 20022) +++ ruby_1_9_1/test/webrick/test_server.rb (revision 20023) @@ -13,12 +13,12 @@ end def test_server - TestWEBrick.start_server(Echo){|server, addr, port| + TestWEBrick.start_server(Echo){|server, addr, port, log| TCPSocket.open(addr, port){|sock| - sock.puts("foo"); assert_equal("foo\n", sock.gets) - sock.puts("bar"); assert_equal("bar\n", sock.gets) - sock.puts("baz"); assert_equal("baz\n", sock.gets) - sock.puts("qux"); assert_equal("qux\n", sock.gets) + sock.puts("foo"); assert_equal("foo\n", sock.gets, log.call) + sock.puts("bar"); assert_equal("bar\n", sock.gets, log.call) + sock.puts("baz"); assert_equal("baz\n", sock.gets, log.call) + sock.puts("qux"); assert_equal("qux\n", sock.gets, log.call) } } end @@ -30,15 +30,15 @@ :StartCallback => Proc.new{ started += 1 }, :StopCallback => Proc.new{ stopped += 1 }, } - TestWEBrick.start_server(Echo, config){|server, addr, port| + TestWEBrick.start_server(Echo, config){|server, addr, port, log| true while server.status != :Running - assert_equal(started, 1) - assert_equal(stopped, 0) - assert_equal(accepted, 0) + assert_equal(started, 1, log.call) + assert_equal(stopped, 0, log.call) + assert_equal(accepted, 0, log.call) TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } - assert_equal(accepted, 3) + assert_equal(accepted, 3, log.call) } assert_equal(started, 1) assert_equal(stopped, 1) Index: ruby_1_9_1/test/webrick/test_filehandler.rb =================================================================== --- ruby_1_9_1/test/webrick/test_filehandler.rb (revision 20022) +++ ruby_1_9_1/test/webrick/test_filehandler.rb (revision 20023) @@ -75,19 +75,19 @@ def test_filehandler config = { :DocumentRoot => File.dirname(__FILE__), } this_file = File.basename(__FILE__) - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("200", res.code) - assert_equal("text/html", res.content_type) - assert_match(/HREF="#{this_file}"/, res.body) + assert_equal("200", res.code, log.call) + assert_equal("text/html", res.content_type, log.call) + assert_match(/HREF="#{this_file}"/, res.body, log.call) } req = Net::HTTP::Get.new("/#{this_file}") http.request(req){|res| - assert_equal("200", res.code) - assert_equal("text/plain", res.content_type) - assert_equal(File.read(__FILE__), res.body) + assert_equal("200", res.code, log.call) + assert_equal("text/plain", res.content_type, log.call) + assert_equal(File.read(__FILE__), res.body, log.call) } end end @@ -95,23 +95,23 @@ def test_non_disclosure_name config = { :DocumentRoot => File.dirname(__FILE__), } this_file = File.basename(__FILE__) - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) doc_root_opts = server[:DocumentRootOptions] doc_root_opts[:NondisclosureName] = %w(.ht* *~ test_*) req = Net::HTTP::Get.new("/") http.request(req){|res| - assert_equal("200", res.code) - assert_equal("text/html", res.content_type) + assert_equal("200", res.code, log.call) + assert_equal("text/html", res.content_type, log.call) assert_no_match(/HREF="#{File.basename(__FILE__)}"/, res.body) } req = Net::HTTP::Get.new("/#{this_file}") http.request(req){|res| - assert_equal("404", res.code) + assert_equal("404", res.code, log.call) } doc_root_opts[:NondisclosureName] = %w(.ht* *~ TEST_*) http.request(req){|res| - assert_equal("404", res.code) + assert_equal("404", res.code, log.call) } end end @@ -119,14 +119,14 @@ def test_directory_traversal config = { :DocumentRoot => File.dirname(__FILE__), } this_file = File.basename(__FILE__) - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/../../") - http.request(req){|res| assert_equal("400", res.code) } + http.request(req){|res| assert_equal("400", res.code, log.call) } req = Net::HTTP::Get.new("/..%5c../#{File.basename(__FILE__)}") - http.request(req){|res| assert_equal(windows? ? "200" : "404", res.code) } + http.request(req){|res| assert_equal(windows? ? "200" : "404", res.code, log.call) } req = Net::HTTP::Get.new("/..%5c..%5cruby.c") - http.request(req){|res| assert_equal("404", res.code) } + http.request(req){|res| assert_equal("404", res.code, log.call) } end end @@ -134,10 +134,10 @@ if windows? config = { :DocumentRoot => File.dirname(__FILE__), } this_file = File.basename(__FILE__) - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/..%5c..") - http.request(req){|res| assert_equal("301", res.code) } + http.request(req){|res| assert_equal("301", res.code, log.call) } end end end @@ -148,25 +148,25 @@ :DocumentRoot => File.dirname(__FILE__), :CGIPathEnv => ENV['PATH'], } - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/webric~1.cgi/test") http.request(req) do |res| if windows? - assert_equal("200", res.code) - assert_equal("/test", res.body) + assert_equal("200", res.code, log.call) + assert_equal("/test", res.body, log.call) else - assert_equal("404", res.code) + assert_equal("404", res.code, log.call) end end req = Net::HTTP::Get.new("/.htaccess") - http.request(req) {|res| assert_equal("404", res.code) } + http.request(req) {|res| assert_equal("404", res.code, log.call) } req = Net::HTTP::Get.new("/htacce~1") - http.request(req) {|res| assert_equal("404", res.code) } + http.request(req) {|res| assert_equal("404", res.code, log.call) } req = Net::HTTP::Get.new("/HTACCE~1") - http.request(req) {|res| assert_equal("404", res.code) } + http.request(req) {|res| assert_equal("404", res.code, log.call) } end end @@ -176,21 +176,21 @@ :DocumentRoot => File.dirname(__FILE__), :CGIPathEnv => ENV['PATH'], } - TestWEBrick.start_httpserver(config) do |server, addr, port| + TestWEBrick.start_httpserver(config) do |server, addr, port, log| http = Net::HTTP.new(addr, port) req = Net::HTTP::Get.new("/webrick.cgi/test") http.request(req) do |res| - assert_equal("200", res.code) - assert_equal("/test", res.body) + assert_equal("200", res.code, log.call) + assert_equal("/test", res.body, log.call) end response_assertion = Proc.new do |res| if windows? - assert_equal("200", res.code) - assert_equal("/test", res.body) + assert_equal("200", res.code, log.call) + assert_equal("/test", res.body, log.call) else - assert_equal("404", res.code) + assert_equal("404", res.code, log.call) end end req = Net::HTTP::Get.new("/webrick.cgi%20/test") -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/