Project

General

Profile

Bug #4110 » fix_webrick_test.diff

kyanagi (Kouhei Yanagita), 12/02/2010 10:22 PM

View differences:

test/webrick/test_httprequest.rb (working copy)
require "test/unit"
class TestWEBrickHTTPRequest < Test::Unit::TestCase
HTTP_CONFIG = WEBrick::Config::HTTP.merge(:ServerName => 'localhost')
def test_parse_09
msg = <<-_end_of_message_
GET /
foobar # HTTP/0.9 request don't have header nor entity body.
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal("GET", req.request_method)
assert_equal("/", req.unparsed_uri)
assert_equal(WEBrick::HTTPVersion.new("0.9"), req.http_version)
assert_equal(WEBrick::Config::HTTP[:ServerName], req.host)
assert_equal(HTTP_CONFIG[:ServerName], req.host)
assert_equal(80, req.port)
assert_equal(false, req.keep_alive?)
assert_equal(nil, req.body)
......
GET / HTTP/1.0
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal("GET", req.request_method)
assert_equal("/", req.unparsed_uri)
assert_equal(WEBrick::HTTPVersion.new("1.0"), req.http_version)
assert_equal(WEBrick::Config::HTTP[:ServerName], req.host)
assert_equal(HTTP_CONFIG[:ServerName], req.host)
assert_equal(80, req.port)
assert_equal(false, req.keep_alive?)
assert_equal(nil, req.body)
......
GET /path HTTP/1.1
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal("GET", req.request_method)
assert_equal("/path", req.unparsed_uri)
assert_equal("", req.script_name)
assert_equal("/path", req.path_info)
assert_equal(WEBrick::HTTPVersion.new("1.1"), req.http_version)
assert_equal(WEBrick::Config::HTTP[:ServerName], req.host)
assert_equal(HTTP_CONFIG[:ServerName], req.host)
assert_equal(80, req.port)
assert_equal(true, req.keep_alive?)
assert_equal(nil, req.body)
......
msg = <<-_end_of_message_
GET /#{"a"*2084} HTTP/1.1
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
assert_raise(WEBrick::HTTPStatus::RequestURITooLarge){
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
}
......
foobar
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal(
URI.parse("http://test.ruby-lang.org:8080/path"), req.request_uri)
......
hogehoge
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal("POST", req.request_method)
assert_equal("/foo/baz", req.path)
......
Host: test.ruby-lang.org
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal(URI.parse("http://test.ruby-lang.org/path"), req.request_uri)
assert_equal("test.ruby-lang.org", req.host)
......
Host: 192.168.1.1
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal(URI.parse("http://192.168.1.1/path"), req.request_uri)
assert_equal("192.168.1.1", req.host)
......
Host: [fe80::208:dff:feef:98c7]
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal(URI.parse("http://[fe80::208:dff:feef:98c7]/path"),
req.request_uri)
......
Host: 192.168.1.1:8080
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal(URI.parse("http://192.168.1.1:8080/path"), req.request_uri)
assert_equal("192.168.1.1", req.host)
......
Host: [fe80::208:dff:feef:98c7]:8080
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
assert_equal(URI.parse("http://[fe80::208:dff:feef:98c7]:8080/path"),
req.request_uri)
......
Host: test.ruby-lang.org:8080
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
query = req.query
assert_equal("1", query["foo"])
......
#{param}
_end_of_message_
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
query = req.query
assert_equal("1", query["foo"])
......
end
}
msg << "0" << crlf
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg))
assert_equal(File.read(__FILE__), req.body)
end
......
_end_of_message_
msg.gsub!(/^ {6}/, "")
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg))
assert_equal("server.example.com", req.server_name)
assert_equal("http://forward.example.com/foo", req.request_uri.to_s)
......
_end_of_message_
msg.gsub!(/^ {6}/, "")
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg))
assert_equal("server.example.com", req.server_name)
assert_equal("http://forward.example.com:8080/foo", req.request_uri.to_s)
......
_end_of_message_
msg.gsub!(/^ {6}/, "")
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg))
assert_equal("server.example.com", req.server_name)
assert_equal("https://forward.example.com/foo", req.request_uri.to_s)
......
_end_of_message_
msg.gsub!(/^ {6}/, "")
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg))
assert req['expect']
l = msg.size
......
_end_of_message_
msg.gsub!(/^ {6}/, "")
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg))
assert !req['expect']
l = msg.size
......
#{param}
_end_of_message_
assert_raise(WEBrick::HTTPStatus::LengthRequired){
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
req.body
}
......
body is too short.
_end_of_message_
assert_raise(WEBrick::HTTPStatus::BadRequest){
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
req.body
}
......
body is too short.
_end_of_message_
assert_raise(WEBrick::HTTPStatus::NotImplemented){
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
req.body
}
test/webrick/test_filehandler.rb (working copy)
require "stringio"
class WEBrick::TestFileHandler < Test::Unit::TestCase
HTTP_CONFIG = WEBrick::Config::HTTP.merge(:ServerName => 'localhost')
def default_file_handler(filename)
klass = WEBrick::HTTPServlet::DefaultFileHandler
klass.new(WEBrick::Config::HTTP, filename)
klass.new(HTTP_CONFIG, filename)
end
def windows?
......
end
def make_range_response(file, range_spec)
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req = WEBrick::HTTPRequest.new(HTTP_CONFIG)
req.parse(make_range_request(range_spec))
res = WEBrick::HTTPResponse.new(WEBrick::Config::HTTP)
res = WEBrick::HTTPResponse.new(HTTP_CONFIG)
size = File.size(file)
handler = default_file_handler(file)
handler.make_partial_content(req, res, file, size)
    (1-1/1)