Fix WEBrick::TestFileHandler#test_short_filename test not working
The test is currently skipped and can't possibly work on windows at the moment. It fails because $LOAD_PATH is not set up properly in the forked CGI process, so `require 'uri'` fails. This works properly in the test_cgi.rb tests, because it sets up a :RequestCallback to fix things up. Let's move the setup there into util.rb, so it can be shared with test_filehandler.rb as well.
This commit is contained in:
parent
99f8bb1331
commit
dc532b7c4e
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user