summaryrefslogtreecommitdiff
path: root/tool/test/webrick
diff options
context:
space:
mode:
Diffstat (limited to 'tool/test/webrick')
-rw-r--r--tool/test/webrick/test_cgi.rb32
-rw-r--r--tool/test/webrick/test_filehandler.rb14
-rw-r--r--tool/test/webrick/test_httprequest.rb2
-rw-r--r--tool/test/webrick/test_httpserver.rb2
-rw-r--r--tool/test/webrick/test_server.rb2
-rw-r--r--tool/test/webrick/utils.rb20
-rwxr-xr-x[-rw-r--r--]tool/test/webrick/webrick.cgi4
7 files changed, 34 insertions, 42 deletions
diff --git a/tool/test/webrick/test_cgi.rb b/tool/test/webrick/test_cgi.rb
index 7a75cf565e..a9be8f353d 100644
--- a/tool/test/webrick/test_cgi.rb
+++ b/tool/test/webrick/test_cgi.rb
@@ -12,30 +12,8 @@ class TestWEBrickCGI < Test::Unit::TestCase
super
end
- def start_cgi_server(log_tester=TestWEBrick::DefaultLogTester, &block)
- config = {
- :CGIInterpreter => TestWEBrick::RubyBin,
- :DocumentRoot => File.dirname(__FILE__),
- :DirectoryIndex => ["webrick.cgi"],
- :RequestCallback => Proc.new{|req, res|
- def req.meta_vars
- meta = super
- meta["RUBYLIB"] = $:.join(File::PATH_SEPARATOR)
- meta[RbConfig::CONFIG['LIBPATHENV']] = ENV[RbConfig::CONFIG['LIBPATHENV']] if RbConfig::CONFIG['LIBPATHENV']
- return meta
- end
- },
- }
- if RUBY_PLATFORM =~ /mswin|mingw|cygwin|bccwin32/
- config[:CGIPathEnv] = ENV['PATH'] # runtime dll may not be in system dir.
- end
- TestWEBrick.start_httpserver(config, log_tester){|server, addr, port, log|
- block.call(server, addr, port, log)
- }
- end
-
def test_cgi
- start_cgi_server{|server, addr, port, log|
+ TestWEBrick.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, log.call)}
@@ -98,7 +76,7 @@ class TestWEBrickCGI < Test::Unit::TestCase
log_tester = lambda {|log, access_log|
assert_match(/BadRequest/, log.join)
}
- start_cgi_server(log_tester) {|server, addr, port, log|
+ TestWEBrick.start_cgi_server({}, log_tester) {|server, addr, port, log|
sock = TCPSocket.new(addr, port)
begin
sock << "POST /webrick.cgi HTTP/1.0" << CRLF
@@ -115,7 +93,7 @@ class TestWEBrickCGI < Test::Unit::TestCase
end
def test_cgi_env
- start_cgi_server do |server, addr, port, log|
+ TestWEBrick.start_cgi_server do |server, addr, port, log|
http = Net::HTTP.new(addr, port)
req = Net::HTTP::Get.new("/webrick.cgi/dumpenv")
req['proxy'] = 'http://example.com/'
@@ -137,7 +115,7 @@ class TestWEBrickCGI < Test::Unit::TestCase
assert_equal(1, log.length)
assert_match(/ERROR bad URI/, log[0])
}
- start_cgi_server(log_tester) {|server, addr, port, log|
+ TestWEBrick.start_cgi_server({}, log_tester) {|server, addr, port, log|
res = TCPSocket.open(addr, port) {|sock|
sock << "GET /#{CtrlSeq}#{CRLF}#{CRLF}"
sock.close_write
@@ -155,7 +133,7 @@ class TestWEBrickCGI < Test::Unit::TestCase
assert_equal(1, log.length)
assert_match(/ERROR bad header/, log[0])
}
- start_cgi_server(log_tester) {|server, addr, port, log|
+ TestWEBrick.start_cgi_server({}, log_tester) {|server, addr, port, log|
res = TCPSocket.open(addr, port) {|sock|
sock << "GET / HTTP/1.0#{CRLF}#{CtrlSeq}#{CRLF}#{CRLF}"
sock.close_write
diff --git a/tool/test/webrick/test_filehandler.rb b/tool/test/webrick/test_filehandler.rb
index 146d8ce792..452667d4f4 100644
--- a/tool/test/webrick/test_filehandler.rb
+++ b/tool/test/webrick/test_filehandler.rb
@@ -85,12 +85,12 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
"Content-Type: text/plain\r\n" \
"Content-Range: bytes 0-0/#{filesize}\r\n" \
"\r\n" \
- "#{IO.read(__FILE__, 1)}\r\n" \
+ "#{File.read(__FILE__, 1)}\r\n" \
"--#{boundary}\r\n" \
"Content-Type: text/plain\r\n" \
"Content-Range: bytes #{off}-#{last}/#{filesize}\r\n" \
"\r\n" \
- "#{IO.read(__FILE__, 2, off)}\r\n" \
+ "#{File.read(__FILE__, 2, off)}\r\n" \
"--#{boundary}--\r\n"
assert_equal exp, body
end
@@ -247,22 +247,16 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
def test_short_filename
return if File.executable?(__FILE__) # skip on strange file system
- return if /mswin/ =~ RUBY_PLATFORM && ENV.key?('GITHUB_ACTIONS') # not working from the beginning
- config = {
- :CGIInterpreter => TestWEBrick::RubyBin,
- :DocumentRoot => File.dirname(__FILE__),
- :CGIPathEnv => ENV['PATH'],
- }
log_tester = lambda {|log, access_log|
log = log.reject {|s| /ERROR `.*\' not found\./ =~ s }
log = log.reject {|s| /WARN the request refers nondisclosure name/ =~ s }
assert_equal([], log)
}
- TestWEBrick.start_httpserver(config, log_tester) do |server, addr, port, log|
+ TestWEBrick.start_cgi_server({}, log_tester) do |server, addr, port, log|
http = Net::HTTP.new(addr, port)
if windows?
- root = config[:DocumentRoot].tr("/", "\\")
+ root = File.dirname(__FILE__).tr("/", "\\")
fname = IO.popen(%W[dir /x #{root}\\webrick_long_filename.cgi], encoding: "binary", &:read)
fname.sub!(/\A.*$^$.*$^$/m, '')
if fname
diff --git a/tool/test/webrick/test_httprequest.rb b/tool/test/webrick/test_httprequest.rb
index 759ccbdada..3c0ea937d9 100644
--- a/tool/test/webrick/test_httprequest.rb
+++ b/tool/test/webrick/test_httprequest.rb
@@ -245,7 +245,7 @@ GET /
_end_of_message_
msg.gsub!(/^ {6}/, "")
- open(__FILE__){|io|
+ File.open(__FILE__){|io|
while chunk = io.read(100)
msg << chunk.size.to_s(16) << crlf
msg << chunk << crlf
diff --git a/tool/test/webrick/test_httpserver.rb b/tool/test/webrick/test_httpserver.rb
index 4133be85ad..f6b53e142b 100644
--- a/tool/test/webrick/test_httpserver.rb
+++ b/tool/test/webrick/test_httpserver.rb
@@ -253,7 +253,7 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
server.virtual_host(WEBrick::HTTPServer.new(vhost_config))
Thread.pass while server.status != :Running
- sleep 1 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # server.status behaves unexpectedly with --jit-wait
+ sleep 1 if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? # server.status behaves unexpectedly with --jit-wait
assert_equal(1, started, log.call)
assert_equal(0, stopped, log.call)
assert_equal(0, accepted, log.call)
diff --git a/tool/test/webrick/test_server.rb b/tool/test/webrick/test_server.rb
index 815cc3ce39..3bd8115c61 100644
--- a/tool/test/webrick/test_server.rb
+++ b/tool/test/webrick/test_server.rb
@@ -65,7 +65,7 @@ class TestWEBrickServer < Test::Unit::TestCase
}
TestWEBrick.start_server(Echo, config){|server, addr, port, log|
true while server.status != :Running
- sleep 1 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # server.status behaves unexpectedly with --jit-wait
+ sleep 1 if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? # server.status behaves unexpectedly with --jit-wait
assert_equal(1, started, log.call)
assert_equal(0, stopped, log.call)
assert_equal(0, accepted, log.call)
diff --git a/tool/test/webrick/utils.rb b/tool/test/webrick/utils.rb
index a8568d0a43..c8e84c37f1 100644
--- a/tool/test/webrick/utils.rb
+++ b/tool/test/webrick/utils.rb
@@ -81,4 +81,24 @@ module TestWEBrick
def start_httpproxy(config={}, log_tester=DefaultLogTester, &block)
start_server(WEBrick::HTTPProxyServer, config, log_tester, &block)
end
+
+ def start_cgi_server(config={}, log_tester=TestWEBrick::DefaultLogTester, &block)
+ config = {
+ :CGIInterpreter => TestWEBrick::RubyBin,
+ :DocumentRoot => File.dirname(__FILE__),
+ :DirectoryIndex => ["webrick.cgi"],
+ :RequestCallback => Proc.new{|req, res|
+ def req.meta_vars
+ meta = super
+ meta["RUBYLIB"] = $:.join(File::PATH_SEPARATOR)
+ meta[RbConfig::CONFIG['LIBPATHENV']] = ENV[RbConfig::CONFIG['LIBPATHENV']] if RbConfig::CONFIG['LIBPATHENV']
+ return meta
+ end
+ },
+ }.merge(config)
+ if RUBY_PLATFORM =~ /mswin|mingw|cygwin|bccwin32/
+ config[:CGIPathEnv] = ENV['PATH'] # runtime dll may not be in system dir.
+ end
+ start_server(WEBrick::HTTPServer, config, log_tester, &block)
+ end
end
diff --git a/tool/test/webrick/webrick.cgi b/tool/test/webrick/webrick.cgi
index a294fa72f9..45594b7a7b 100644..100755
--- a/tool/test/webrick/webrick.cgi
+++ b/tool/test/webrick/webrick.cgi
@@ -15,11 +15,11 @@ class TestApp < WEBrick::CGI
}.join(", ")
}.join(", ")
elsif %r{/$} =~ req.request_uri.to_s
- res.body = ""
+ res.body = +""
res.body << req.request_uri.to_s << "\n"
res.body << req.script_name
elsif !req.cookies.empty?
- res.body = req.cookies.inject(""){|result, cookie|
+ res.body = req.cookies.inject(+""){|result, cookie|
result << "%s=%s\n" % [cookie.name, cookie.value]
}
res.cookies << WEBrick::Cookie.new("Customer", "WILE_E_COYOTE")