diff options
author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-01-10 06:29:58 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-01-10 06:29:58 +0000 |
commit | a9a02401a849958b5d654cf60d4cda927c7e33b4 (patch) | |
tree | 77b4df3270c46d4eca271d09181e303b3da464d5 /test | |
parent | c744d6f62dcb536e58ded4a79eec1987880bc23c (diff) | |
download | ruby-a9a02401a849958b5d654cf60d4cda927c7e33b4.tar.gz |
* lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line): should
escape SCRIPT_NAME and PATH_INFO before being parsed as a URI.
* lib/webrick/httputils.rb (WEBrick::HTTPUtils#escape_path): add
new method to escape URI path component.
* lib/webrick/ssl.rb (WEBrick::Config::SSL): the default value
of :SSLEnable is false.
* test/webrick/{test_cgi.rb,webrick.cgi}: new file.
* test/webrick/utils.rb: require "webrick/https.h".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/webrick/test_cgi.rb | 46 | ||||
-rw-r--r-- | test/webrick/utils.rb | 1 | ||||
-rw-r--r-- | test/webrick/webrick.cgi | 26 |
3 files changed, 73 insertions, 0 deletions
diff --git a/test/webrick/test_cgi.rb b/test/webrick/test_cgi.rb new file mode 100644 index 0000000000..60d5da6a72 --- /dev/null +++ b/test/webrick/test_cgi.rb @@ -0,0 +1,46 @@ +require "webrick" +require File.join(File.dirname(__FILE__), "utils.rb") +require "test/unit" +begin + loadpath = $:.dup + $:.replace($: | [File.expand_path("../ruby", File.dirname(__FILE__))]) + require 'envutil' +ensure + $:.replace(loadpath) +end + +class TestWEBrickCGI < Test::Unit::TestCase + def test_cgi + accepted = started = stopped = 0 + requested0 = requested1 = 0 + config = { + :CGIInterpreter => EnvUtil.rubybin, + :DocumentRoot => File.dirname(__FILE__), + } + TestWEBrick.start_httpserver(config){|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)} + req = Net::HTTP::Get.new("/webrick.cgi/path/info") + http.request(req){|res| assert_equal("/path/info", res.body)} + req = Net::HTTP::Get.new("/webrick.cgi/%3F%3F%3F?foo=bar") + http.request(req){|res| assert_equal("/???", res.body)} + 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)} + 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)} + 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)} + + 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)} + 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)} + } + end +end diff --git a/test/webrick/utils.rb b/test/webrick/utils.rb index 50ffd759aa..adb0d106e7 100644 --- a/test/webrick/utils.rb +++ b/test/webrick/utils.rb @@ -1,4 +1,5 @@ require "webrick" +require "webrick/https" require "webrick/httpproxy" module TestWEBrick diff --git a/test/webrick/webrick.cgi b/test/webrick/webrick.cgi new file mode 100644 index 0000000000..97e1377454 --- /dev/null +++ b/test/webrick/webrick.cgi @@ -0,0 +1,26 @@ +#!ruby -d +require "webrick/cgi" + +class TestApp < WEBrick::CGI + def do_GET(req, res) + res["content-type"] = "text/plain" + if p = req.path_info + res.body = p + elsif (q = req.query).size > 0 + res.body = q.keys.sort.collect{|key| + q[key].list.sort.collect{|v| + "#{key}=#{v}" + }.join(", ") + }.join(", ") + else + res.body = req.script_name + end + end + + def do_POST(req, res) + do_GET(req, res) + end +end + +cgi = TestApp.new +cgi.start |