2010-06-18 02:27:39 +02:00
|
|
|
begin
|
2010-06-14 06:09:24 +02:00
|
|
|
require File.expand_path('../testrequest', __FILE__)
|
|
|
|
require 'rack/handler/fastcgi'
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::Handler::FastCGI do
|
|
|
|
extend TestRequest::Helpers
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
@host = '0.0.0.0'
|
|
|
|
@port = 9203
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-18 02:27:39 +02:00
|
|
|
if `which lighttpd` && !$?.success?
|
|
|
|
raise "lighttpd not found"
|
|
|
|
end
|
|
|
|
|
2009-12-19 03:16:58 +01:00
|
|
|
# Keep this first.
|
2010-06-14 06:09:24 +02:00
|
|
|
$pid = fork {
|
|
|
|
ENV['RACK_ENV'] = 'deployment'
|
|
|
|
ENV['RUBYLIB'] = [
|
|
|
|
File.expand_path('../../lib', __FILE__),
|
|
|
|
ENV['RUBYLIB'],
|
|
|
|
].compact.join(':')
|
|
|
|
|
|
|
|
Dir.chdir(File.expand_path("../cgi", __FILE__)) do
|
2009-12-19 03:16:58 +01:00
|
|
|
exec "lighttpd -D -f lighttpd.conf"
|
2010-06-14 06:09:24 +02:00
|
|
|
end
|
|
|
|
}
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "respond" do
|
2009-12-19 03:16:58 +01:00
|
|
|
sleep 1
|
2010-06-14 06:09:24 +02:00
|
|
|
GET("/test")
|
|
|
|
response.should.not.be.nil
|
2009-12-19 03:16:58 +01:00
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "respond via rackup server" do
|
|
|
|
GET("/sample_rackup.ru")
|
|
|
|
status.should.equal 200
|
|
|
|
end
|
|
|
|
|
|
|
|
should "be a lighttpd" do
|
2009-12-19 03:16:58 +01:00
|
|
|
GET("/test.fcgi")
|
2010-06-14 06:09:24 +02:00
|
|
|
status.should.equal 200
|
2009-12-19 03:16:58 +01:00
|
|
|
response["SERVER_SOFTWARE"].should =~ /lighttpd/
|
|
|
|
response["HTTP_VERSION"].should.equal "HTTP/1.1"
|
|
|
|
response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
|
|
|
|
response["SERVER_PORT"].should.equal @port.to_s
|
2010-06-14 06:09:24 +02:00
|
|
|
response["SERVER_NAME"].should.equal @host
|
2009-12-19 03:16:58 +01:00
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "have rack headers" do
|
2009-12-19 03:16:58 +01:00
|
|
|
GET("/test.fcgi")
|
2009-12-26 21:00:18 +01:00
|
|
|
response["rack.version"].should.equal [1,1]
|
2010-06-14 06:09:24 +02:00
|
|
|
response["rack.multithread"].should.be.false
|
|
|
|
response["rack.multiprocess"].should.be.true
|
|
|
|
response["rack.run_once"].should.be.false
|
2009-12-19 03:16:58 +01:00
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "have CGI headers on GET" do
|
2009-12-19 03:16:58 +01:00
|
|
|
GET("/test.fcgi")
|
|
|
|
response["REQUEST_METHOD"].should.equal "GET"
|
|
|
|
response["SCRIPT_NAME"].should.equal "/test.fcgi"
|
|
|
|
response["REQUEST_PATH"].should.equal "/"
|
2009-12-26 21:00:18 +01:00
|
|
|
response["PATH_INFO"].should.equal ""
|
2009-12-19 03:16:58 +01:00
|
|
|
response["QUERY_STRING"].should.equal ""
|
|
|
|
response["test.postdata"].should.equal ""
|
|
|
|
|
|
|
|
GET("/test.fcgi/foo?quux=1")
|
|
|
|
response["REQUEST_METHOD"].should.equal "GET"
|
|
|
|
response["SCRIPT_NAME"].should.equal "/test.fcgi"
|
|
|
|
response["REQUEST_PATH"].should.equal "/"
|
|
|
|
response["PATH_INFO"].should.equal "/foo"
|
|
|
|
response["QUERY_STRING"].should.equal "quux=1"
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "have CGI headers on POST" do
|
2009-12-19 03:16:58 +01:00
|
|
|
POST("/test.fcgi", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
|
|
|
|
status.should.equal 200
|
|
|
|
response["REQUEST_METHOD"].should.equal "POST"
|
|
|
|
response["SCRIPT_NAME"].should.equal "/test.fcgi"
|
|
|
|
response["REQUEST_PATH"].should.equal "/"
|
|
|
|
response["QUERY_STRING"].should.equal ""
|
|
|
|
response["HTTP_X_TEST_HEADER"].should.equal "42"
|
|
|
|
response["test.postdata"].should.equal "rack-form-data=23"
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "support HTTP auth" do
|
2009-12-19 03:16:58 +01:00
|
|
|
GET("/test.fcgi", {:user => "ruth", :passwd => "secret"})
|
|
|
|
response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "set status" do
|
2009-12-19 03:16:58 +01:00
|
|
|
GET("/test.fcgi?secret")
|
|
|
|
status.should.equal 403
|
|
|
|
response["rack.url_scheme"].should.equal "http"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Keep this last.
|
2010-06-14 06:09:24 +02:00
|
|
|
should "shutdown" do
|
2009-12-19 03:16:58 +01:00
|
|
|
Process.kill 15, $pid
|
|
|
|
Process.wait($pid).should.equal $pid
|
|
|
|
end
|
|
|
|
end
|
2010-06-18 02:27:39 +02:00
|
|
|
|
|
|
|
rescue RuntimeError
|
|
|
|
$stderr.puts "Skipping Rack::Session::FastCGI tests (lighttpd is required). Install lighttpd and try again."
|
|
|
|
rescue LoadError
|
|
|
|
$stderr.puts "Skipping Rack::Handler::FastCGI tests (FCGI is required). `gem install fcgi` and try again."
|
|
|
|
end
|