summaryrefslogtreecommitdiff
path: root/test/webrick
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-29 11:48:35 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-29 11:48:35 +0000
commit224471fd572c1818e99c66f756ce398745885398 (patch)
tree8f02ccee39290f8aa03b81c401d801ba4ac0d601 /test/webrick
parent3056933cc0b7c1d68ddda1a143bfa298a92f4a0c (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/webrick')
-rw-r--r--test/webrick/test_cgi.rb36
-rw-r--r--test/webrick/test_filehandler.rb62
-rw-r--r--test/webrick/test_httpauth.rb18
-rw-r--r--test/webrick/test_httpproxy.rb112
-rw-r--r--test/webrick/test_httpserver.rb26
-rw-r--r--test/webrick/test_server.rb20
-rw-r--r--test/webrick/utils.rb13
7 files changed, 147 insertions, 140 deletions
diff --git a/test/webrick/test_cgi.rb b/test/webrick/test_cgi.rb
index b50038d..ff83919 100644
--- a/test/webrick/test_cgi.rb
+++ b/test/webrick/test_cgi.rb
@@ -21,41 +21,41 @@ class TestWEBrickCGI < Test::Unit::TestCase
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 @@ class TestWEBrickCGI < Test::Unit::TestCase
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 @@ class TestWEBrickCGI < Test::Unit::TestCase
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 @@ class TestWEBrickCGI < Test::Unit::TestCase
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
diff --git a/test/webrick/test_filehandler.rb b/test/webrick/test_filehandler.rb
index 371527e..712ff7b 100644
--- a/test/webrick/test_filehandler.rb
+++ b/test/webrick/test_filehandler.rb
@@ -75,19 +75,19 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
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 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
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 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
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 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
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 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
: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 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
: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")
diff --git a/test/webrick/test_httpauth.rb b/test/webrick/test_httpauth.rb
index 427f839..a6e2947 100644
--- a/test/webrick/test_httpauth.rb
+++ b/test/webrick/test_httpauth.rb
@@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), "utils.rb")
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 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
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 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
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 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
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
diff --git a/test/webrick/test_httpproxy.rb b/test/webrick/test_httpproxy.rb
index 6786254..1f914e3 100644
--- a/test/webrick/test_httpproxy.rb
+++ b/test/webrick/test_httpproxy.rb
@@ -35,7 +35,7 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
: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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
: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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
: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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
: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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
: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 @@ class TestWEBrickHTTPProxy < Test::Unit::TestCase
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
diff --git a/test/webrick/test_httpserver.rb b/test/webrick/test_httpserver.rb
index eb685f9..6b0c419 100644
--- a/test/webrick/test_httpserver.rb
+++ b/test/webrick/test_httpserver.rb
@@ -223,7 +223,7 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
: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 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
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)
diff --git a/test/webrick/test_server.rb b/test/webrick/test_server.rb
index ce5ee85..4c064fd 100644
--- a/test/webrick/test_server.rb
+++ b/test/webrick/test_server.rb
@@ -13,12 +13,12 @@ class TestWEBrickServer < Test::Unit::TestCase
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 @@ class TestWEBrickServer < Test::Unit::TestCase
: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)
diff --git a/test/webrick/utils.rb b/test/webrick/utils.rb
index 39cadcf..82df9cd 100644
--- a/test/webrick/utils.rb
+++ b/test/webrick/utils.rb
@@ -27,23 +27,30 @@ module TestWEBrick
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)