spec_fastcgi.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. begin
  2. require File.expand_path('../testrequest', __FILE__)
  3. require 'rack/handler/fastcgi'
  4. describe Rack::Handler::FastCGI do
  5. extend TestRequest::Helpers
  6. @host = '127.0.0.1'
  7. @port = 9203
  8. if `which lighttpd` && !$?.success?
  9. raise "lighttpd not found"
  10. end
  11. # Keep this first.
  12. $pid = fork {
  13. ENV['RACK_ENV'] = 'deployment'
  14. ENV['RUBYLIB'] = [
  15. File.expand_path('../../lib', __FILE__),
  16. ENV['RUBYLIB'],
  17. ].compact.join(':')
  18. Dir.chdir(File.expand_path("../cgi", __FILE__)) do
  19. exec "lighttpd -D -f lighttpd.conf"
  20. end
  21. }
  22. should "respond" do
  23. sleep 1
  24. GET("/test")
  25. response.should.not.be.nil
  26. end
  27. should "respond via rackup server" do
  28. GET("/sample_rackup.ru")
  29. status.should.equal 200
  30. end
  31. should "be a lighttpd" do
  32. GET("/test.fcgi")
  33. status.should.equal 200
  34. response["SERVER_SOFTWARE"].should =~ /lighttpd/
  35. response["HTTP_VERSION"].should.equal "HTTP/1.1"
  36. response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
  37. response["SERVER_PORT"].should.equal @port.to_s
  38. response["SERVER_NAME"].should.equal @host
  39. end
  40. should "have rack headers" do
  41. GET("/test.fcgi")
  42. response["rack.version"].should.equal [1,1]
  43. response["rack.multithread"].should.be.false
  44. response["rack.multiprocess"].should.be.true
  45. response["rack.run_once"].should.be.false
  46. end
  47. should "have CGI headers on GET" do
  48. GET("/test.fcgi")
  49. response["REQUEST_METHOD"].should.equal "GET"
  50. response["SCRIPT_NAME"].should.equal "/test.fcgi"
  51. response["REQUEST_PATH"].should.equal "/"
  52. response["PATH_INFO"].should.equal ""
  53. response["QUERY_STRING"].should.equal ""
  54. response["test.postdata"].should.equal ""
  55. GET("/test.fcgi/foo?quux=1")
  56. response["REQUEST_METHOD"].should.equal "GET"
  57. response["SCRIPT_NAME"].should.equal "/test.fcgi"
  58. response["REQUEST_PATH"].should.equal "/"
  59. response["PATH_INFO"].should.equal "/foo"
  60. response["QUERY_STRING"].should.equal "quux=1"
  61. end
  62. should "have CGI headers on POST" do
  63. POST("/test.fcgi", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
  64. status.should.equal 200
  65. response["REQUEST_METHOD"].should.equal "POST"
  66. response["SCRIPT_NAME"].should.equal "/test.fcgi"
  67. response["REQUEST_PATH"].should.equal "/"
  68. response["QUERY_STRING"].should.equal ""
  69. response["HTTP_X_TEST_HEADER"].should.equal "42"
  70. response["test.postdata"].should.equal "rack-form-data=23"
  71. end
  72. should "support HTTP auth" do
  73. GET("/test.fcgi", {:user => "ruth", :passwd => "secret"})
  74. response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
  75. end
  76. should "set status" do
  77. GET("/test.fcgi?secret")
  78. status.should.equal 403
  79. response["rack.url_scheme"].should.equal "http"
  80. end
  81. # Keep this last.
  82. should "shutdown" do
  83. Process.kill 15, $pid
  84. Process.wait($pid).should.equal $pid
  85. end
  86. end
  87. rescue RuntimeError
  88. $stderr.puts "Skipping Rack::Handler::FastCGI tests (lighttpd is required). Install lighttpd and try again."
  89. rescue LoadError
  90. $stderr.puts "Skipping Rack::Handler::FastCGI tests (FCGI is required). `gem install fcgi` and try again."
  91. end