From dcad2ce485a55d82b13cd46806dca297e2ad518a Mon Sep 17 00:00:00 2001 From: gotoyuzo Date: Sun, 17 Aug 2008 17:33:13 +0000 Subject: * lib/webrick/cgi.rb (WEBrick::CGI::Socket#eof?): added lacked method. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/webrick/test_cgi.rb | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'test/webrick') diff --git a/test/webrick/test_cgi.rb b/test/webrick/test_cgi.rb index c5dbc0bf9..b50038d84 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 -- cgit