summaryrefslogtreecommitdiff
path: root/test/webrick
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-17 17:33:13 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-17 17:33:13 +0000
commitd4835a2703fb6f5630cbbcba68180db22d26dfaf (patch)
tree9df9496f791f326811fd5cf4e3ec3267edf7e935 /test/webrick
parent0ff4061ef7e3a8ffa681698fa8490740616d1aac (diff)
* lib/webrick/cgi.rb (WEBrick::CGI::Socket#eof?): added lacked method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/webrick')
-rw-r--r--test/webrick/test_cgi.rb29
1 files changed, 26 insertions, 3 deletions
diff --git a/test/webrick/test_cgi.rb b/test/webrick/test_cgi.rb
index c5dbc0bf96..b50038d84c 100644
--- a/test/webrick/test_cgi.rb
+++ b/test/webrick/test_cgi.rb
@@ -3,9 +3,9 @@ require File.join(File.dirname(__FILE__), "utils.rb")
require "test/unit"
class TestWEBrickCGI < Test::Unit::TestCase
- def test_cgi
- accepted = started = stopped = 0
- requested0 = requested1 = 0
+ CRLF = "\r\n"
+
+ def start_cgi_server(&block)
config = {
:CGIInterpreter => TestWEBrick::RubyBin,
:DocumentRoot => File.dirname(__FILE__),
@@ -22,6 +22,12 @@ class TestWEBrickCGI < Test::Unit::TestCase
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)
+ }
+ end
+
+ def test_cgi
+ start_cgi_server{|server, addr, port|
http = Net::HTTP.new(addr, port)
req = Net::HTTP::Get.new("/webrick.cgi")
http.request(req){|res| assert_equal("/webrick.cgi", res.body)}
@@ -75,4 +81,21 @@ class TestWEBrickCGI < Test::Unit::TestCase
}
}
end
+
+ def test_bad_request
+ start_cgi_server{|server, addr, port|
+ sock = TCPSocket.new(addr, port)
+ begin
+ sock << "POST /webrick.cgi HTTP/1.0" << CRLF
+ sock << "Content-Type: application/x-www-form-urlencoded" << CRLF
+ sock << "Content-Length: 1024" << CRLF
+ sock << CRLF
+ sock << "a=1&a=2&b=x"
+ sock.close_write
+ assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, sock.read)
+ ensure
+ sock.close
+ end
+ }
+ end
end