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/cgi'
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::Handler::CGI do
|
|
|
|
extend TestRequest::Helpers
|
2009-12-26 21:00:18 +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 "be a lighttpd" do
|
2009-12-19 03:16:58 +01:00
|
|
|
GET("/test")
|
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")
|
2010-06-14 06:09:24 +02:00
|
|
|
response["rack.version"].should.equal([1,1])
|
|
|
|
response["rack.multithread"].should.be.false
|
|
|
|
response["rack.multiprocess"].should.be.true
|
|
|
|
response["rack.run_once"].should.be.true
|
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")
|
|
|
|
response["REQUEST_METHOD"].should.equal "GET"
|
|
|
|
response["SCRIPT_NAME"].should.equal "/test"
|
|
|
|
response["REQUEST_PATH"].should.equal "/"
|
2010-06-14 06:09:24 +02:00
|
|
|
response["PATH_INFO"].should.be.nil
|
2009-12-19 03:16:58 +01:00
|
|
|
response["QUERY_STRING"].should.equal ""
|
|
|
|
response["test.postdata"].should.equal ""
|
|
|
|
|
|
|
|
GET("/test/foo?quux=1")
|
|
|
|
response["REQUEST_METHOD"].should.equal "GET"
|
|
|
|
response["SCRIPT_NAME"].should.equal "/test"
|
|
|
|
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", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
|
|
|
|
status.should.equal 200
|
|
|
|
response["REQUEST_METHOD"].should.equal "POST"
|
|
|
|
response["SCRIPT_NAME"].should.equal "/test"
|
|
|
|
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", {: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?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
|
2010-06-14 06:09:24 +02:00
|
|
|
Process.wait($pid).should == $pid
|
2009-12-19 03:16:58 +01:00
|
|
|
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."
|
|
|
|
end
|