Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WEBrick::TestFileHandler#test_short_filename test not working on mswin #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions test/webrick/test_cgi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,8 @@ def teardown
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)}
Expand Down Expand Up @@ -98,7 +76,7 @@ def test_bad_request
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
Expand All @@ -115,7 +93,7 @@ def test_bad_request
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/'
Expand All @@ -137,7 +115,7 @@ def test_bad_uri
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
Expand All @@ -155,7 +133,7 @@ def test_bad_header
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
Expand Down
9 changes: 2 additions & 7 deletions test/webrick/test_filehandler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,15 @@ def test_unwise_in_path
def test_short_filename
return if File.executable?(__FILE__) # skip on strange file system

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
Expand Down
20 changes: 20 additions & 0 deletions test/webrick/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,24 @@ def start_httpserver(config={}, log_tester=DefaultLogTester, &block)
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