mongrel 1.1.5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +4 -0
- data/CHANGELOG +18 -0
- data/COPYING +55 -0
- data/LICENSE +55 -0
- data/Manifest +69 -0
- data/README +74 -0
- data/TODO +5 -0
- data/bin/mongrel_rails +283 -0
- data/examples/builder.rb +29 -0
- data/examples/camping/README +3 -0
- data/examples/camping/blog.rb +294 -0
- data/examples/camping/tepee.rb +149 -0
- data/examples/httpd.conf +474 -0
- data/examples/mime.yaml +3 -0
- data/examples/mongrel.conf +9 -0
- data/examples/mongrel_simple_ctrl.rb +92 -0
- data/examples/mongrel_simple_service.rb +116 -0
- data/examples/monitrc +57 -0
- data/examples/random_thrash.rb +19 -0
- data/examples/simpletest.rb +52 -0
- data/examples/webrick_compare.rb +20 -0
- data/ext/http11/ext_help.h +14 -0
- data/ext/http11/extconf.rb +6 -0
- data/ext/http11/http11.c +402 -0
- data/ext/http11/http11_parser.c +1221 -0
- data/ext/http11/http11_parser.h +49 -0
- data/ext/http11/http11_parser.java.rl +170 -0
- data/ext/http11/http11_parser.rl +152 -0
- data/ext/http11/http11_parser_common.rl +54 -0
- data/ext/http11_java/Http11Service.java +13 -0
- data/ext/http11_java/org/jruby/mongrel/Http11.java +266 -0
- data/ext/http11_java/org/jruby/mongrel/Http11Parser.java +572 -0
- data/lib/http11.so +0 -0
- data/lib/mongrel.rb +355 -0
- data/lib/mongrel/camping.rb +107 -0
- data/lib/mongrel/cgi.rb +181 -0
- data/lib/mongrel/command.rb +222 -0
- data/lib/mongrel/configurator.rb +388 -0
- data/lib/mongrel/const.rb +110 -0
- data/lib/mongrel/debug.rb +203 -0
- data/lib/mongrel/gems.rb +22 -0
- data/lib/mongrel/handlers.rb +468 -0
- data/lib/mongrel/header_out.rb +28 -0
- data/lib/mongrel/http_request.rb +155 -0
- data/lib/mongrel/http_response.rb +163 -0
- data/lib/mongrel/init.rb +10 -0
- data/lib/mongrel/mime_types.yml +616 -0
- data/lib/mongrel/rails.rb +185 -0
- data/lib/mongrel/stats.rb +89 -0
- data/lib/mongrel/tcphack.rb +18 -0
- data/lib/mongrel/uri_classifier.rb +76 -0
- data/mongrel-public_cert.pem +20 -0
- data/mongrel.gemspec +242 -0
- data/setup.rb +1585 -0
- data/test/mime.yaml +3 -0
- data/test/mongrel.conf +1 -0
- data/test/test_cgi_wrapper.rb +26 -0
- data/test/test_command.rb +86 -0
- data/test/test_conditional.rb +107 -0
- data/test/test_configurator.rb +88 -0
- data/test/test_debug.rb +25 -0
- data/test/test_handlers.rb +126 -0
- data/test/test_http11.rb +156 -0
- data/test/test_redirect_handler.rb +45 -0
- data/test/test_request_progress.rb +100 -0
- data/test/test_response.rb +127 -0
- data/test/test_stats.rb +35 -0
- data/test/test_uriclassifier.rb +261 -0
- data/test/test_ws.rb +115 -0
- data/test/testhelp.rb +79 -0
- data/tools/trickletest.rb +45 -0
- metadata +197 -0
- metadata.gz.sig +1 -0
data/test/mime.yaml
ADDED
data/test/mongrel.conf
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
uri "/fromconf", :handler => Mongrel::Error404Handler.new("test")
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require 'test/testhelp'
|
3
|
+
|
4
|
+
class MockHttpRequest
|
5
|
+
attr_reader :body
|
6
|
+
|
7
|
+
def params
|
8
|
+
return { 'REQUEST_METHOD' => 'GET'}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class CGIWrapperTest < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def test_set_cookies_output_cookies
|
15
|
+
request = MockHttpRequest.new
|
16
|
+
response = nil # not needed for this test
|
17
|
+
output_headers = {}
|
18
|
+
|
19
|
+
cgi = Mongrel::CGIWrapper.new(request, response)
|
20
|
+
session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::MemoryStore)
|
21
|
+
cgi.send_cookies(output_headers)
|
22
|
+
|
23
|
+
assert(output_headers.has_key?("Set-Cookie"))
|
24
|
+
assert_equal("_session_id="+session.session_id+"; path=", output_headers["Set-Cookie"])
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Copyright (c) 2005 Zed A. Shaw
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
|
5
|
+
# for more information.
|
6
|
+
|
7
|
+
require 'test/testhelp'
|
8
|
+
|
9
|
+
class TestCommand < GemPlugin::Plugin "/commands"
|
10
|
+
include Mongrel::Command::Base
|
11
|
+
|
12
|
+
def configure
|
13
|
+
options [
|
14
|
+
["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
|
15
|
+
['', '--user USER', "User to run as", :@user, nil],
|
16
|
+
["-d", "--daemonize", "Whether to run in the background or not", :@daemon, false],
|
17
|
+
["-x", "--test", "Used to let the test run failures", :@test, false],
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate
|
22
|
+
valid_dir? ".", "Can't validate current directory."
|
23
|
+
valid_exists? "Rakefile", "Rakefile not there, test is invalid."
|
24
|
+
if @test
|
25
|
+
valid_exist? "BADFILE", "Yeah, badfile"
|
26
|
+
valid_file? "BADFILE", "Not even a file"
|
27
|
+
valid_dir? "BADDIR", "No dir here"
|
28
|
+
valid? false, "Total failure"
|
29
|
+
end
|
30
|
+
|
31
|
+
return @valid
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def run
|
36
|
+
$test_command_ran = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class CommandTest < Test::Unit::TestCase
|
41
|
+
|
42
|
+
def setup
|
43
|
+
$test_command_ran = false
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_cmd(args)
|
50
|
+
Mongrel::Command::Registry.instance.run args
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_run_command
|
54
|
+
redirect_test_io do
|
55
|
+
run_cmd ["testcommand"]
|
56
|
+
assert $test_command_ran, "command didn't run"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_command_error
|
61
|
+
redirect_test_io do
|
62
|
+
run_cmd ["crapcommand"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_command_listing
|
67
|
+
redirect_test_io do
|
68
|
+
run_cmd ["help"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_options
|
73
|
+
redirect_test_io do
|
74
|
+
run_cmd ["testcommand","-h"]
|
75
|
+
run_cmd ["testcommand","--help"]
|
76
|
+
run_cmd ["testcommand","-e","test","-d","--user"]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_version
|
81
|
+
redirect_test_io do
|
82
|
+
run_cmd ["testcommand", "--version"]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# Copyright (c) 2005 Zed A. Shaw
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
|
5
|
+
# for more information.
|
6
|
+
|
7
|
+
require 'test/testhelp'
|
8
|
+
|
9
|
+
include Mongrel
|
10
|
+
|
11
|
+
class ConditionalResponseTest < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@server = HttpServer.new('127.0.0.1', process_based_port)
|
14
|
+
@server.register('/', Mongrel::DirHandler.new('.'))
|
15
|
+
@server.run
|
16
|
+
|
17
|
+
@http = Net::HTTP.new(@server.host, @server.port)
|
18
|
+
|
19
|
+
# get the ETag and Last-Modified headers
|
20
|
+
@path = '/README'
|
21
|
+
res = @http.start { |http| http.get(@path) }
|
22
|
+
assert_not_nil @etag = res['ETag']
|
23
|
+
assert_not_nil @last_modified = res['Last-Modified']
|
24
|
+
assert_not_nil @content_length = res['Content-Length']
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
@server.stop(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
# status should be 304 Not Modified when If-None-Match is the matching ETag
|
32
|
+
def test_not_modified_via_if_none_match
|
33
|
+
assert_status_for_get_and_head Net::HTTPNotModified, 'If-None-Match' => @etag
|
34
|
+
end
|
35
|
+
|
36
|
+
# status should be 304 Not Modified when If-Modified-Since is the matching Last-Modified date
|
37
|
+
def test_not_modified_via_if_modified_since
|
38
|
+
assert_status_for_get_and_head Net::HTTPNotModified, 'If-Modified-Since' => @last_modified
|
39
|
+
end
|
40
|
+
|
41
|
+
# status should be 304 Not Modified when If-None-Match is the matching ETag
|
42
|
+
# and If-Modified-Since is the matching Last-Modified date
|
43
|
+
def test_not_modified_via_if_none_match_and_if_modified_since
|
44
|
+
assert_status_for_get_and_head Net::HTTPNotModified, 'If-None-Match' => @etag, 'If-Modified-Since' => @last_modified
|
45
|
+
end
|
46
|
+
|
47
|
+
# status should be 200 OK when If-None-Match is invalid
|
48
|
+
def test_invalid_if_none_match
|
49
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => 'invalid'
|
50
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => 'invalid', 'If-Modified-Since' => @last_modified
|
51
|
+
end
|
52
|
+
|
53
|
+
# status should be 200 OK when If-Modified-Since is invalid
|
54
|
+
def test_invalid_if_modified_since
|
55
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-Modified-Since' => 'invalid'
|
56
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => @etag, 'If-Modified-Since' => 'invalid'
|
57
|
+
end
|
58
|
+
|
59
|
+
# status should be 304 Not Modified when If-Modified-Since is greater than the Last-Modified header, but less than the system time
|
60
|
+
def test_if_modified_since_greater_than_last_modified
|
61
|
+
sleep 2
|
62
|
+
last_modified_plus_1 = (Time.httpdate(@last_modified) + 1).httpdate
|
63
|
+
assert_status_for_get_and_head Net::HTTPNotModified, 'If-Modified-Since' => last_modified_plus_1
|
64
|
+
assert_status_for_get_and_head Net::HTTPNotModified, 'If-None-Match' => @etag, 'If-Modified-Since' => last_modified_plus_1
|
65
|
+
end
|
66
|
+
|
67
|
+
# status should be 200 OK when If-Modified-Since is less than the Last-Modified header
|
68
|
+
def test_if_modified_since_less_than_last_modified
|
69
|
+
last_modified_minus_1 = (Time.httpdate(@last_modified) - 1).httpdate
|
70
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-Modified-Since' => last_modified_minus_1
|
71
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => @etag, 'If-Modified-Since' => last_modified_minus_1
|
72
|
+
end
|
73
|
+
|
74
|
+
# status should be 200 OK when If-Modified-Since is a date in the future
|
75
|
+
def test_future_if_modified_since
|
76
|
+
the_future = Time.at(2**31-1).httpdate
|
77
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-Modified-Since' => the_future
|
78
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => @etag, 'If-Modified-Since' => the_future
|
79
|
+
end
|
80
|
+
|
81
|
+
# status should be 200 OK when If-None-Match is a wildcard
|
82
|
+
def test_wildcard_match
|
83
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => '*'
|
84
|
+
assert_status_for_get_and_head Net::HTTPOK, 'If-None-Match' => '*', 'If-Modified-Since' => @last_modified
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
# assert the response status is correct for GET and HEAD
|
90
|
+
def assert_status_for_get_and_head(response_class, headers = {})
|
91
|
+
%w{ get head }.each do |method|
|
92
|
+
res = @http.send(method, @path, headers)
|
93
|
+
assert_kind_of response_class, res
|
94
|
+
assert_equal @etag, res['ETag']
|
95
|
+
case response_class.to_s
|
96
|
+
when 'Net::HTTPNotModified' then
|
97
|
+
assert_nil res['Last-Modified']
|
98
|
+
assert_nil res['Content-Length']
|
99
|
+
when 'Net::HTTPOK' then
|
100
|
+
assert_equal @last_modified, res['Last-Modified']
|
101
|
+
assert_equal @content_length, res['Content-Length']
|
102
|
+
else
|
103
|
+
fail "Incorrect response class: #{response_class}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# Copyright (c) 2005 Zed A. Shaw
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
|
5
|
+
# for more information.
|
6
|
+
|
7
|
+
require 'test/testhelp'
|
8
|
+
|
9
|
+
$test_plugin_fired = 0
|
10
|
+
|
11
|
+
class TestPlugin < GemPlugin::Plugin "/handlers"
|
12
|
+
include Mongrel::HttpHandlerPlugin
|
13
|
+
|
14
|
+
def process(request, response)
|
15
|
+
$test_plugin_fired += 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
class Sentinel < GemPlugin::Plugin "/handlers"
|
21
|
+
include Mongrel::HttpHandlerPlugin
|
22
|
+
|
23
|
+
def process(request, response)
|
24
|
+
raise "This Sentinel plugin shouldn't run."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
class ConfiguratorTest < Test::Unit::TestCase
|
30
|
+
|
31
|
+
def test_base_handler_config
|
32
|
+
@config = nil
|
33
|
+
@port = process_based_port
|
34
|
+
|
35
|
+
redirect_test_io do
|
36
|
+
@config = Mongrel::Configurator.new :host => "localhost" do
|
37
|
+
listener :port => process_based_port do
|
38
|
+
# 2 in front should run, but the sentinel shouldn't since dirhandler processes the request
|
39
|
+
uri "/", :handler => plugin("/handlers/testplugin")
|
40
|
+
uri "/", :handler => plugin("/handlers/testplugin")
|
41
|
+
uri "/", :handler => Mongrel::DirHandler.new(".")
|
42
|
+
uri "/", :handler => plugin("/handlers/testplugin")
|
43
|
+
|
44
|
+
uri "/test", :handler => plugin("/handlers/testplugin")
|
45
|
+
uri "/test", :handler => plugin("/handlers/testplugin")
|
46
|
+
uri "/test", :handler => Mongrel::DirHandler.new(".")
|
47
|
+
uri "/test", :handler => plugin("/handlers/testplugin")
|
48
|
+
|
49
|
+
debug "/"
|
50
|
+
setup_signals
|
51
|
+
|
52
|
+
run_config(File.dirname(__FILE__) + "/../test/mongrel.conf")
|
53
|
+
load_mime_map(File.dirname(__FILE__) + "/../test/mime.yaml")
|
54
|
+
|
55
|
+
run
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# pp @config.listeners.values.first.classifier.routes
|
61
|
+
|
62
|
+
@config.listeners.each do |host,listener|
|
63
|
+
assert listener.classifier.uris.length == 3, "Wrong number of registered URIs"
|
64
|
+
assert listener.classifier.uris.include?("/"), "/ not registered"
|
65
|
+
assert listener.classifier.uris.include?("/test"), "/test not registered"
|
66
|
+
end
|
67
|
+
|
68
|
+
res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/test"))
|
69
|
+
assert res != nil, "Didn't get a response"
|
70
|
+
assert $test_plugin_fired == 3, "Test filter plugin didn't run 3 times."
|
71
|
+
|
72
|
+
redirect_test_io do
|
73
|
+
res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/"))
|
74
|
+
|
75
|
+
assert res != nil, "Didn't get a response"
|
76
|
+
assert $test_plugin_fired == 6, "Test filter plugin didn't run 6 times."
|
77
|
+
end
|
78
|
+
|
79
|
+
redirect_test_io do
|
80
|
+
@config.stop(false, true)
|
81
|
+
end
|
82
|
+
|
83
|
+
assert_raise Errno::EBADF, Errno::ECONNREFUSED do
|
84
|
+
res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/"))
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/test/test_debug.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright (c) 2005 Zed A. Shaw
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
|
5
|
+
# for more information.
|
6
|
+
|
7
|
+
require 'test/testhelp'
|
8
|
+
require 'mongrel/debug'
|
9
|
+
|
10
|
+
class MongrelDbgTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def test_tracing_to_log
|
13
|
+
FileUtils.rm_rf "log/mongrel_debug"
|
14
|
+
|
15
|
+
MongrelDbg::configure
|
16
|
+
out = StringIO.new
|
17
|
+
|
18
|
+
MongrelDbg::begin_trace(:rails)
|
19
|
+
MongrelDbg::trace(:rails, "Good stuff")
|
20
|
+
MongrelDbg::end_trace(:rails)
|
21
|
+
|
22
|
+
assert File.exist?("log/mongrel_debug"), "Didn't make logging directory"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# Copyright (c) 2005 Zed A. Shaw
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
|
5
|
+
# for more information.
|
6
|
+
|
7
|
+
require 'test/testhelp'
|
8
|
+
|
9
|
+
class SimpleHandler < Mongrel::HttpHandler
|
10
|
+
def process(request, response)
|
11
|
+
response.start do |head,out|
|
12
|
+
head["Content-Type"] = "text/html"
|
13
|
+
results = "<html><body>Your request:<br /><pre>#{request.params.to_yaml}</pre><a href=\"/files\">View the files.</a></body></html>"
|
14
|
+
out << results
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class DumbHandler < Mongrel::HttpHandler
|
20
|
+
def process(request, response)
|
21
|
+
response.start do |head,out|
|
22
|
+
head["Content-Type"] = "text/html"
|
23
|
+
out.write("test")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_status(results, expecting)
|
29
|
+
results.each do |res|
|
30
|
+
assert(res.kind_of?(expecting), "Didn't get #{expecting}, got: #{res.class}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class HandlersTest < Test::Unit::TestCase
|
35
|
+
|
36
|
+
def setup
|
37
|
+
@port = process_based_port
|
38
|
+
stats = Mongrel::StatisticsFilter.new(:sample_rate => 1)
|
39
|
+
|
40
|
+
@config = Mongrel::Configurator.new :host => '127.0.0.1' do
|
41
|
+
listener :port => process_based_port do
|
42
|
+
uri "/", :handler => SimpleHandler.new
|
43
|
+
uri "/", :handler => stats
|
44
|
+
uri "/404", :handler => Mongrel::Error404Handler.new("Not found")
|
45
|
+
uri "/dumb", :handler => Mongrel::DeflateFilter.new
|
46
|
+
uri "/dumb", :handler => DumbHandler.new, :in_front => true
|
47
|
+
uri "/files", :handler => Mongrel::DirHandler.new("doc")
|
48
|
+
uri "/files_nodir", :handler => Mongrel::DirHandler.new("doc", listing_allowed=false, index_html="none")
|
49
|
+
uri "/status", :handler => Mongrel::StatusHandler.new(:stats_filter => stats)
|
50
|
+
uri "/relative", :handler => Mongrel::DirHandler.new(nil, listing_allowed=false, index_html="none")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
@test_file = windows? ? "testfile" : "tmp/testfile"
|
55
|
+
|
56
|
+
File.open("/#{@test_file}", 'w') do
|
57
|
+
# Do nothing
|
58
|
+
end
|
59
|
+
|
60
|
+
@config.run
|
61
|
+
end
|
62
|
+
|
63
|
+
def teardown
|
64
|
+
@config.stop(false, true)
|
65
|
+
File.delete "/#{@test_file}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_more_web_server
|
69
|
+
res = hit([ "http://localhost:#{@port}/test",
|
70
|
+
"http://localhost:#{@port}/dumb",
|
71
|
+
"http://localhost:#{@port}/404",
|
72
|
+
"http://localhost:#{@port}/files/rdoc/index.html",
|
73
|
+
"http://localhost:#{@port}/files/rdoc/nothere.html",
|
74
|
+
"http://localhost:#{@port}/files/rdoc/",
|
75
|
+
"http://localhost:#{@port}/files_nodir/rdoc/",
|
76
|
+
"http://localhost:#{@port}/status",
|
77
|
+
])
|
78
|
+
check_status res, String
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_nil_dirhandler
|
82
|
+
# Camping uses this internally
|
83
|
+
handler = Mongrel::DirHandler.new(nil, false)
|
84
|
+
assert handler.can_serve("/#{@test_file}")
|
85
|
+
# Not a bug! A nil @file parameter is the only circumstance under which
|
86
|
+
# we are allowed to serve any existing file
|
87
|
+
assert handler.can_serve("../../../../../../../../../../#{@test_file}")
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_non_nil_dirhandler_is_not_vulnerable_to_path_traversal
|
91
|
+
# The famous security bug of Mongrel 1.1.2
|
92
|
+
handler = Mongrel::DirHandler.new("/doc", false)
|
93
|
+
assert_nil handler.can_serve("/#{@test_file}")
|
94
|
+
assert_nil handler.can_serve("../../../../../../../../../../#{@test_file}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_deflate
|
98
|
+
Net::HTTP.start("localhost", @port) do |h|
|
99
|
+
# Test that no accept-encoding returns a non-deflated response
|
100
|
+
req = h.get("/dumb")
|
101
|
+
assert(
|
102
|
+
!req['Content-Encoding'] ||
|
103
|
+
!req['Content-Encoding'].include?('deflate'))
|
104
|
+
assert_equal "test", req.body
|
105
|
+
|
106
|
+
req = h.get("/dumb", {"Accept-Encoding" => "deflate"})
|
107
|
+
# -MAX_WBITS stops zlib from looking for a zlib header
|
108
|
+
inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS)
|
109
|
+
assert req['Content-Encoding'].include?('deflate')
|
110
|
+
assert_equal "test", inflater.inflate(req.body)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# TODO: find out why this fails on win32 but nowhere else
|
115
|
+
#def test_posting_fails_dirhandler
|
116
|
+
# req = Net::HTTP::Post.new("http://localhost:#{@port}/files/rdoc/")
|
117
|
+
# req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
|
118
|
+
# res = hit [["http://localhost:#{@port}/files/rdoc/",req]]
|
119
|
+
# check_status res, Net::HTTPNotFound
|
120
|
+
#end
|
121
|
+
|
122
|
+
def test_unregister
|
123
|
+
@config.listeners["127.0.0.1:#{@port}"].unregister("/")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|