2006-05-21 14:46:42 +00:00
|
|
|
# Mongrel Web Server - A Mostly Ruby Webserver and Library
|
|
|
|
#
|
|
|
|
# Copyright (C) 2005 Zed A. Shaw zedshaw AT zedshaw dot com
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2006-03-25 21:15:30 +00:00
|
|
|
require 'test/unit'
|
|
|
|
require 'mongrel'
|
2006-05-20 18:06:20 +00:00
|
|
|
require 'net/http'
|
2006-05-24 08:34:17 +00:00
|
|
|
require File.dirname(__FILE__) + "/testhelp.rb"
|
2006-03-25 21:15:30 +00:00
|
|
|
|
|
|
|
$test_plugin_fired = 0
|
|
|
|
|
|
|
|
class TestPlugin < GemPlugin::Plugin "/handlers"
|
|
|
|
include Mongrel::HttpHandlerPlugin
|
|
|
|
|
|
|
|
def process(request, response)
|
|
|
|
$test_plugin_fired += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class Sentinel < GemPlugin::Plugin "/handlers"
|
|
|
|
include Mongrel::HttpHandlerPlugin
|
|
|
|
|
|
|
|
def process(request, response)
|
|
|
|
raise "This Sentinel plugin shouldn't run."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2006-03-26 23:57:11 +00:00
|
|
|
class ConfiguratorTest < Test::Unit::TestCase
|
2006-03-25 21:15:30 +00:00
|
|
|
|
|
|
|
def test_base_handler_config
|
2006-05-24 08:34:17 +00:00
|
|
|
config = nil
|
|
|
|
|
|
|
|
redirect_test_io do
|
|
|
|
config = Mongrel::Configurator.new :host => "localhost" do
|
|
|
|
listener :port => 4501 do
|
|
|
|
# 2 in front should run, but the sentinel shouldn't since dirhandler processes the request
|
|
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
|
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
|
|
|
uri "/", :handler => Mongrel::DirHandler.new(".")
|
|
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
|
|
|
|
|
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
|
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
|
|
|
uri "/test", :handler => Mongrel::DirHandler.new(".")
|
|
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
|
|
|
|
|
|
|
debug "/"
|
|
|
|
setup_signals
|
|
|
|
|
|
|
|
run_config(File.dirname(__FILE__) + "/../test/mongrel.conf")
|
2006-06-16 18:11:08 +00:00
|
|
|
load_mime_map(File.dirname(__FILE__) + "/../test/mime.yaml")
|
2006-05-24 08:34:17 +00:00
|
|
|
|
|
|
|
run
|
|
|
|
end
|
2006-03-25 21:15:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-03-26 23:57:11 +00:00
|
|
|
|
|
|
|
config.listeners.each do |host,listener|
|
2006-05-23 12:46:05 +00:00
|
|
|
assert listener.classifier.uris.length == 3, "Wrong number of registered URIs"
|
2006-03-26 23:57:11 +00:00
|
|
|
assert listener.classifier.uris.include?("/"), "/ not registered"
|
|
|
|
assert listener.classifier.uris.include?("/test"), "/test not registered"
|
|
|
|
end
|
|
|
|
|
2006-05-16 04:28:13 +00:00
|
|
|
res = Net::HTTP.get(URI.parse('http://localhost:4501/test'))
|
2006-03-25 21:15:30 +00:00
|
|
|
assert res != nil, "Didn't get a response"
|
2006-03-26 23:57:11 +00:00
|
|
|
assert $test_plugin_fired == 3, "Test filter plugin didn't run 3 times."
|
2006-03-25 21:15:30 +00:00
|
|
|
|
2006-05-24 08:34:17 +00:00
|
|
|
redirect_test_io do
|
|
|
|
res = Net::HTTP.get(URI.parse('http://localhost:4501/'))
|
2006-03-25 21:15:30 +00:00
|
|
|
|
2006-05-24 08:34:17 +00:00
|
|
|
assert res != nil, "Didn't get a response"
|
|
|
|
assert $test_plugin_fired == 6, "Test filter plugin didn't run 6 times."
|
|
|
|
end
|
2006-03-25 21:15:30 +00:00
|
|
|
|
2006-05-24 08:34:17 +00:00
|
|
|
redirect_test_io do
|
|
|
|
config.stop
|
|
|
|
end
|
2006-05-20 02:56:30 +00:00
|
|
|
|
2006-03-27 07:06:18 +00:00
|
|
|
assert_raise Errno::EBADF, Errno::ECONNREFUSED do
|
2006-05-16 04:28:13 +00:00
|
|
|
res = Net::HTTP.get(URI.parse("http://localhost:4501/"))
|
2006-03-25 21:15:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|